Coverage for pages/tests/test_forms.py: 100.00%
15 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-10 15:27 -0700
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-10 15:27 -0700
1from django.test import SimpleTestCase
4class ContactFormTests(SimpleTestCase):
5 def test_contact_page_form_is_valid(self):
6 response = self.client.post( 1c
7 "/contact/",
8 data={
9 "from_email": "joe@example.com",
10 "subject": "Test Email",
11 "message": "This is a test email",
12 },
13 )
14 self.assertEqual(response.status_code, 302) 1c
16 def test_contact_form_is_invalid(self):
17 response = self.client.post( 1d
18 "/contact/",
19 data={
20 "from_email": "john@example.com",
21 "subject": "Test Email",
22 "not_a_form_field": "This is a test",
23 },
24 )
25 self.assertEqual(response.status_code, 200) 1d
27 def test_header_injection(self):
28 error_occured = True 1a
29 try: 1a
30 self.client.post( 1a
31 "/contact/",
32 data={
33 "from_email": "joe@example.com",
34 "subject": "Subject\nInjectionTest",
35 "message": "This is a test of a BadHeaderError",
36 },
37 )
38 error_occured = False 1a
39 # except BadHeaderError:
40 # error_occured = True
41 finally:
42 pass 1a
43 self.assertFalse(error_occured) 1a