-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comma-separate list values in formatted_data
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ def validate_honeypot(form, data, **kwargs): | |
|
||
|
||
class FormsTest(TestCase): | ||
maxDiff = None | ||
|
||
def test_forms(self): | ||
form = Form.objects.create( | ||
title="Test contact form", | ||
|
@@ -48,13 +50,29 @@ def test_forms(self): | |
type="date", | ||
is_required=False, | ||
) | ||
form.fields.create( | ||
ordering=6, | ||
title="Multiple Choice", | ||
name="multiple-choice", | ||
type="multiple-select", | ||
choices="Choice A,Choice B,Choice C", | ||
is_required=False, | ||
) | ||
|
||
form_class = form.form_class() | ||
form_instance = form_class() | ||
|
||
self.assertListEqual( | ||
[field.name for field in form_instance], | ||
["subject", "email", "body", "please-call-me", "radio", "date"], | ||
[ | ||
"subject", | ||
"email", | ||
"body", | ||
"please-call-me", | ||
"radio", | ||
"date", | ||
"multiple-choice", | ||
], | ||
) | ||
|
||
page = Page.objects.create(override_url="/", title="") | ||
|
@@ -72,7 +90,7 @@ def test_forms(self): | |
self.assertContains( | ||
response, | ||
"<input", | ||
10, # csrf, subject, email, checkbox, _formcontent, submit, radio*3, date | ||
13, # csrf, subject, email, checkbox, _formcontent, submit, radio*3, date, three multiple choice | ||
) | ||
self.assertContains(response, "<textarea", 1) | ||
self.assertContains( | ||
|
@@ -104,8 +122,8 @@ def test_forms(self): | |
|
||
self.assertContains( | ||
response, | ||
"Enter a valid e", | ||
1, # Django 1.4 has e-mail, 1.5 and up email | ||
"Enter a valid email", | ||
1, | ||
) | ||
|
||
response = self.client.post( | ||
|
@@ -117,6 +135,7 @@ def test_forms(self): | |
f"fc{form.id}-body": "Hello World", | ||
f"fc{form.id}-radio": "two-what", | ||
f"fc{form.id}-date": "2022-10-02", | ||
f"fc{form.id}-multiple-choice": ["choice-a", "choice-c"], | ||
}, | ||
) | ||
|
||
|
@@ -160,11 +179,19 @@ def test_forms(self): | |
}, | ||
{"name": "radio", "title": "Radio Select", "value": "two what"}, | ||
{"name": "date", "title": "Date", "value": "2022-10-02"}, | ||
{ | ||
"name": "multiple-choice", | ||
"title": "Multiple Choice", | ||
"value": ["Choice A", "Choice C"], | ||
}, | ||
], | ||
} | ||
], | ||
) | ||
|
||
data = submission.formatted_data() | ||
self.assertIn("Multiple Choice:\nChoice A, Choice C", data) | ||
|
||
# Export the submission | ||
User.objects.create_superuser("admin", "[email protected]", "password") | ||
self.client.login(username="admin", password="password") | ||
|