Coverage for pages/tests/test_forms.py: 88.24%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-22 12:02 -0700

1from django.core.mail import BadHeaderError 1a

2from django.test import TestCase 1a

3 

4 

5class ContactFormTests(TestCase): 1a

6 def test_contact_page_form_is_valid(self): 1a

7 response = self.client.post( 1a

8 "/contact/", 

9 data={ 

10 "from_email": "joe@example.com", 

11 "subject": "Test Email", 

12 "message": "This is a test email", 

13 }, 

14 ) 

15 self.assertEqual(response.status_code, 302) 1a

16 

17 def test_contact_form_is_invalid(self): 1a

18 response = self.client.post( 1a

19 "/contact/", 

20 data={ 

21 "from_email": "john@example.com", 

22 "subject": "Test Email", 

23 "not_a_form_field": "This is a test", 

24 }, 

25 ) 

26 self.assertEqual(response.status_code, 200) 1a

27 

28 def test_header_injection(self): 1a

29 error_occured = True 1a

30 try: 1a

31 self.client.post( 1a

32 "/contact/", 

33 data={ 

34 "from_email": "joe@example.com", 

35 "subject": "Subject\nInjectionTest", 

36 "message": "This is a test of a BadHeaderError", 

37 }, 

38 ) 

39 error_occured = False 1a

40 except BadHeaderError: 

41 error_occured = True 

42 self.assertFalse(error_occured) 1a