@@ -18,6 +18,8 @@ def validate_honeypot(form, data, **kwargs):
18
18
19
19
20
20
class FormsTest (TestCase ):
21
+ maxDiff = None
22
+
21
23
def test_forms (self ):
22
24
form = Form .objects .create (
23
25
title = "Test contact form" ,
@@ -48,13 +50,29 @@ def test_forms(self):
48
50
type = "date" ,
49
51
is_required = False ,
50
52
)
53
+ form .fields .create (
54
+ ordering = 6 ,
55
+ title = "Multiple Choice" ,
56
+ name = "multiple-choice" ,
57
+ type = "multiple-select" ,
58
+ choices = "Choice A,Choice B,Choice C" ,
59
+ is_required = False ,
60
+ )
51
61
52
62
form_class = form .form_class ()
53
63
form_instance = form_class ()
54
64
55
65
self .assertListEqual (
56
66
[field .name for field in form_instance ],
57
- ["subject" , "email" , "body" , "please-call-me" , "radio" , "date" ],
67
+ [
68
+ "subject" ,
69
+ "email" ,
70
+ "body" ,
71
+ "please-call-me" ,
72
+ "radio" ,
73
+ "date" ,
74
+ "multiple-choice" ,
75
+ ],
58
76
)
59
77
60
78
page = Page .objects .create (override_url = "/" , title = "" )
@@ -72,7 +90,7 @@ def test_forms(self):
72
90
self .assertContains (
73
91
response ,
74
92
"<input" ,
75
- 10 , # csrf, subject, email, checkbox, _formcontent, submit, radio*3, date
93
+ 13 , # csrf, subject, email, checkbox, _formcontent, submit, radio*3, date, three multiple choice
76
94
)
77
95
self .assertContains (response , "<textarea" , 1 )
78
96
self .assertContains (
@@ -104,8 +122,8 @@ def test_forms(self):
104
122
105
123
self .assertContains (
106
124
response ,
107
- "Enter a valid e " ,
108
- 1 , # Django 1.4 has e-mail, 1.5 and up email
125
+ "Enter a valid email " ,
126
+ 1 ,
109
127
)
110
128
111
129
response = self .client .post (
@@ -117,6 +135,7 @@ def test_forms(self):
117
135
f"fc{ form .id } -body" : "Hello World" ,
118
136
f"fc{ form .id } -radio" : "two-what" ,
119
137
f"fc{ form .id } -date" : "2022-10-02" ,
138
+ f"fc{ form .id } -multiple-choice" : ["choice-a" , "choice-c" ],
120
139
},
121
140
)
122
141
@@ -160,11 +179,19 @@ def test_forms(self):
160
179
},
161
180
{"name" : "radio" , "title" : "Radio Select" , "value" : "two what" },
162
181
{"name" : "date" , "title" : "Date" , "value" : "2022-10-02" },
182
+ {
183
+ "name" : "multiple-choice" ,
184
+ "title" : "Multiple Choice" ,
185
+ "value" : ["Choice A" , "Choice C" ],
186
+ },
163
187
],
164
188
}
165
189
],
166
190
)
167
191
192
+ data = submission .formatted_data ()
193
+ self .assertIn ("Multiple Choice:\n Choice A, Choice C" , data )
194
+
168
195
# Export the submission
169
196
User .
objects .
create_superuser (
"admin" ,
"[email protected] " ,
"password" )
170
197
self .client .login (username = "admin" , password = "password" )
0 commit comments