diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
index 0ac552c..4c40d6d 100644
a
|
b
|
class GenericRelationsTests(TestCase):
|
231 | 231 | tag = TaggedItem.objects.create(content_object=tailless, tag="lizard") |
232 | 232 | self.assertEqual(tag.content_object, tailless) |
233 | 233 | |
234 | | class CustomWidget(forms.CharField): |
| 234 | class CustomWidget(forms.TextInput): |
235 | 235 | pass |
236 | 236 | |
237 | 237 | class TaggedItemForm(forms.ModelForm): |
diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
index 4694147..b8711fc 100644
a
|
b
|
class ModelFormsetTest(TestCase):
|
383 | 383 | self.assertEqual(len(formset.forms), 1) |
384 | 384 | self.assertHTMLEqual(formset.forms[0].as_p(), |
385 | 385 | '<p><label for="id_form-0-name">Name:</label> <input id="id_form-0-name" type="text" name="form-0-name" maxlength="100" /></p>\n' |
386 | | '<p><label for="id_form-0-write_speed">Write speed:</label> <input type="text" name="form-0-write_speed" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr" id="id_form-0-author_ptr" /></p>') |
| 386 | '<p><label for="id_form-0-write_speed">Write speed:</label> <input type="number" name="form-0-write_speed" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr" id="id_form-0-author_ptr" /></p>') |
387 | 387 | |
388 | 388 | data = { |
389 | 389 | 'form-TOTAL_FORMS': '1', # the number of forms rendered |
… |
… |
class ModelFormsetTest(TestCase):
|
406 | 406 | self.assertEqual(len(formset.forms), 2) |
407 | 407 | self.assertHTMLEqual(formset.forms[0].as_p(), |
408 | 408 | '<p><label for="id_form-0-name">Name:</label> <input id="id_form-0-name" type="text" name="form-0-name" value="Ernest Hemingway" maxlength="100" /></p>\n' |
409 | | '<p><label for="id_form-0-write_speed">Write speed:</label> <input type="text" name="form-0-write_speed" value="10" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr" value="%d" id="id_form-0-author_ptr" /></p>' % hemingway_id) |
| 409 | '<p><label for="id_form-0-write_speed">Write speed:</label> <input type="number" name="form-0-write_speed" value="10" id="id_form-0-write_speed" /><input type="hidden" name="form-0-author_ptr" value="%d" id="id_form-0-author_ptr" /></p>' % hemingway_id) |
410 | 410 | self.assertHTMLEqual(formset.forms[1].as_p(), |
411 | 411 | '<p><label for="id_form-1-name">Name:</label> <input id="id_form-1-name" type="text" name="form-1-name" maxlength="100" /></p>\n' |
412 | | '<p><label for="id_form-1-write_speed">Write speed:</label> <input type="text" name="form-1-write_speed" id="id_form-1-write_speed" /><input type="hidden" name="form-1-author_ptr" id="id_form-1-author_ptr" /></p>') |
| 412 | '<p><label for="id_form-1-write_speed">Write speed:</label> <input type="number" name="form-1-write_speed" id="id_form-1-write_speed" /><input type="hidden" name="form-1-author_ptr" id="id_form-1-author_ptr" /></p>') |
413 | 413 | |
414 | 414 | data = { |
415 | 415 | 'form-TOTAL_FORMS': '2', # the number of forms rendered |
… |
… |
class ModelFormsetTest(TestCase):
|
549 | 549 | formset = AuthorBooksFormSet2(instance=author) |
550 | 550 | self.assertEqual(len(formset.forms), 1) |
551 | 551 | self.assertHTMLEqual(formset.forms[0].as_p(), |
552 | | '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input type="text" name="bookwithcustompk_set-0-my_pk" id="id_bookwithcustompk_set-0-my_pk" /></p>\n' |
| 552 | '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input id="id_bookwithcustompk_set-0-my_pk" type="number" name="bookwithcustompk_set-0-my_pk" maxlength="6" /></p>\n' |
553 | 553 | '<p><label for="id_bookwithcustompk_set-0-title">Title:</label> <input id="id_bookwithcustompk_set-0-title" type="text" name="bookwithcustompk_set-0-title" maxlength="100" /><input type="hidden" name="bookwithcustompk_set-0-author" value="1" id="id_bookwithcustompk_set-0-author" /></p>') |
554 | 554 | |
555 | 555 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
797 | 797 | '<option value="%d">Joe Perry at Giordanos</option>\n' |
798 | 798 | '<option value="%d">Jack Berry at Giordanos</option>\n' |
799 | 799 | '</select></p>\n' |
800 | | '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>' |
| 800 | '<p><label for="id_form-0-age">Age:</label> <input type="number" name="form-0-age" id="id_form-0-age" /></p>' |
801 | 801 | % (owner1.auto_id, owner2.auto_id)) |
802 | 802 | |
803 | 803 | owner1 = Owner.objects.get(name=u'Joe Perry') |
… |
… |
class ModelFormsetTest(TestCase):
|
807 | 807 | formset = FormSet(instance=owner1) |
808 | 808 | self.assertEqual(len(formset.forms), 1) |
809 | 809 | self.assertHTMLEqual(formset.forms[0].as_p(), |
810 | | '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>' |
| 810 | '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>' |
811 | 811 | % owner1.auto_id) |
812 | 812 | |
813 | 813 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
828 | 828 | formset = FormSet(instance=owner1) |
829 | 829 | self.assertEqual(len(formset.forms), 1) |
830 | 830 | self.assertHTMLEqual(formset.forms[0].as_p(), |
831 | | '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>' |
| 831 | '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>' |
832 | 832 | % owner1.auto_id) |
833 | 833 | |
834 | 834 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
984 | 984 | result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result) |
985 | 985 | self.assertHTMLEqual(result, |
986 | 986 | '<p><label for="id_membership_set-0-date_joined">Date joined:</label> <input type="text" name="membership_set-0-date_joined" value="__DATETIME__" id="id_membership_set-0-date_joined" /><input type="hidden" name="initial-membership_set-0-date_joined" value="__DATETIME__" id="initial-membership_set-0-id_membership_set-0-date_joined" /></p>\n' |
987 | | '<p><label for="id_membership_set-0-karma">Karma:</label> <input type="text" name="membership_set-0-karma" id="id_membership_set-0-karma" /><input type="hidden" name="membership_set-0-person" value="%d" id="id_membership_set-0-person" /><input type="hidden" name="membership_set-0-id" id="id_membership_set-0-id" /></p>' |
| 987 | '<p><label for="id_membership_set-0-karma">Karma:</label> <input type="number" name="membership_set-0-karma" id="id_membership_set-0-karma" /><input type="hidden" name="membership_set-0-person" value="%d" id="id_membership_set-0-person" /><input type="hidden" name="membership_set-0-id" id="id_membership_set-0-id" /></p>' |
988 | 988 | % person.id) |
989 | 989 | |
990 | 990 | # test for validation with callable defaults. Validations rely on hidden fields |
diff --git a/tests/regressiontests/forms/tests/extra.py b/tests/regressiontests/forms/tests/extra.py
index c873af7..a79ffdf 100644
a
|
b
|
class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
|
603 | 603 | f = CommentForm(data, auto_id=False, error_class=DivErrorList) |
604 | 604 | self.assertHTMLEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p> |
605 | 605 | <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> |
606 | | <p>Email: <input type="text" name="email" value="invalid" /></p> |
| 606 | <p>Email: <input type="email" name="email" value="invalid" /></p> |
607 | 607 | <div class="errorlist"><div class="error">This field is required.</div></div> |
608 | 608 | <p>Comment: <input type="text" name="comment" /></p>""") |
609 | 609 | |
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 6e4a544..6e9dc08 100644
a
|
b
|
def fix_os_paths(x):
|
47 | 47 | |
48 | 48 | |
49 | 49 | class FieldsTests(SimpleTestCase): |
50 | | |
51 | 50 | def setUp(self): |
52 | 51 | self.save_warnings_state() |
53 | 52 | warnings.filterwarnings('ignore', category=DeprecationWarning, |
… |
… |
class FieldsTests(SimpleTestCase):
|
56 | 55 | def tearDown(self): |
57 | 56 | self.restore_warnings_state() |
58 | 57 | |
| 58 | def assertWidgetRendersTo(self, field, to): |
| 59 | class _Form(Form): |
| 60 | f = field |
| 61 | self.assertEqual(str(_Form()['f']), to) |
| 62 | |
59 | 63 | def test_field_sets_widget_is_required(self): |
60 | 64 | self.assertTrue(Field(required=True).widget.is_required) |
61 | 65 | self.assertFalse(Field(required=False).widget.is_required) |
… |
… |
class FieldsTests(SimpleTestCase):
|
129 | 133 | |
130 | 134 | def test_integerfield_1(self): |
131 | 135 | f = IntegerField() |
| 136 | self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />') |
132 | 137 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
133 | 138 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
134 | 139 | self.assertEqual(1, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
163 | 168 | |
164 | 169 | def test_integerfield_3(self): |
165 | 170 | f = IntegerField(max_value=10) |
| 171 | self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />') |
166 | 172 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
167 | 173 | self.assertEqual(1, f.clean(1)) |
168 | 174 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
174 | 180 | |
175 | 181 | def test_integerfield_4(self): |
176 | 182 | f = IntegerField(min_value=10) |
| 183 | self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />') |
177 | 184 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
178 | 185 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
179 | 186 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
185 | 192 | |
186 | 193 | def test_integerfield_5(self): |
187 | 194 | f = IntegerField(min_value=10, max_value=20) |
| 195 | self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />') |
188 | 196 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
189 | 197 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
190 | 198 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
200 | 208 | |
201 | 209 | def test_floatfield_1(self): |
202 | 210 | f = FloatField() |
| 211 | self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />') |
203 | 212 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
204 | 213 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
205 | 214 | self.assertEqual(1.0, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
226 | 235 | |
227 | 236 | def test_floatfield_3(self): |
228 | 237 | f = FloatField(max_value=1.5, min_value=0.5) |
| 238 | self.assertWidgetRendersTo(f, '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" />') |
229 | 239 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
230 | 240 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
231 | 241 | self.assertEqual(1.5, f.clean('1.5')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
237 | 247 | |
238 | 248 | def test_decimalfield_1(self): |
239 | 249 | f = DecimalField(max_digits=4, decimal_places=2) |
| 250 | self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" maxlength="5" />') |
240 | 251 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
241 | 252 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
242 | 253 | self.assertEqual(f.clean('1'), Decimal("1")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
282 | 293 | |
283 | 294 | def test_decimalfield_3(self): |
284 | 295 | f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) |
| 296 | self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.5" max="1.5" maxlength="5" type="number" id="id_f" />') |
285 | 297 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
286 | 298 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
287 | 299 | self.assertEqual(f.clean('1.5'), Decimal("1.5")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
496 | 508 | |
497 | 509 | def test_emailfield_1(self): |
498 | 510 | f = EmailField() |
| 511 | self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />') |
499 | 512 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
500 | 513 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
501 | 514 | self.assertEqual(u'person@example.com', f.clean('person@example.com')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
534 | 547 | |
535 | 548 | def test_emailfield_3(self): |
536 | 549 | f = EmailField(min_length=10, max_length=15) |
| 550 | self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />') |
537 | 551 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com') |
538 | 552 | self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com')) |
539 | 553 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com') |
… |
… |
class FieldsTests(SimpleTestCase):
|
574 | 588 | |
575 | 589 | def test_urlfield_1(self): |
576 | 590 | f = URLField() |
| 591 | self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />') |
577 | 592 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
578 | 593 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
579 | 594 | self.assertEqual(u'http://localhost/', f.clean('http://localhost')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
625 | 640 | |
626 | 641 | def test_urlfield_5(self): |
627 | 642 | f = URLField(min_length=15, max_length=20) |
| 643 | self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />') |
628 | 644 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com') |
629 | 645 | self.assertEqual(u'http://example.com/', f.clean('http://example.com')) |
630 | 646 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com') |
diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py
index 3f529f2..f1edc6d 100644
a
|
b
|
class FormsTestCase(TestCase):
|
253 | 253 | get_spam = BooleanField() |
254 | 254 | |
255 | 255 | f = SignupForm(auto_id=False) |
256 | | self.assertHTMLEqual(str(f['email']), '<input type="text" name="email" />') |
| 256 | self.assertHTMLEqual(str(f['email']), '<input type="email" name="email" />') |
257 | 257 | self.assertHTMLEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />') |
258 | 258 | |
259 | 259 | f = SignupForm({'email': 'test@example.com', 'get_spam': True}, auto_id=False) |
260 | | self.assertHTMLEqual(str(f['email']), '<input type="text" name="email" value="test@example.com" />') |
| 260 | self.assertHTMLEqual(str(f['email']), '<input type="email" name="email" value="test@example.com" />') |
261 | 261 | self.assertHTMLEqual(str(f['get_spam']), '<input checked="checked" type="checkbox" name="get_spam" />') |
262 | 262 | |
263 | 263 | # 'True' or 'true' should be rendered without a value attribute |
… |
… |
class FormsTestCase(TestCase):
|
1749 | 1749 | <option value="2">Yes</option> |
1750 | 1750 | <option value="3">No</option> |
1751 | 1751 | </select></li> |
1752 | | <li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li> |
1753 | | <li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></li>""") |
| 1752 | <li><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></li> |
| 1753 | <li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></li>""") |
1754 | 1754 | |
1755 | 1755 | self.assertHTMLEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul> |
1756 | 1756 | <p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p> |
… |
… |
class FormsTestCase(TestCase):
|
1759 | 1759 | <option value="2">Yes</option> |
1760 | 1760 | <option value="3">No</option> |
1761 | 1761 | </select></p> |
1762 | | <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p> |
| 1762 | <p><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></p> |
1763 | 1763 | <ul class="errorlist"><li>This field is required.</li></ul> |
1764 | | <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""") |
| 1764 | <p class="required error"><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>""") |
1765 | 1765 | |
1766 | 1766 | self.assertHTMLEqual(p.as_table(), """<tr class="required error"><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="name" id="id_name" /></td></tr> |
1767 | 1767 | <tr class="required"><th><label for="id_is_cool">Is cool:</label></th><td><select name="is_cool" id="id_is_cool"> |
… |
… |
class FormsTestCase(TestCase):
|
1769 | 1769 | <option value="2">Yes</option> |
1770 | 1770 | <option value="3">No</option> |
1771 | 1771 | </select></td></tr> |
1772 | | <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr> |
1773 | | <tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="age" id="id_age" /></td></tr>""") |
| 1772 | <tr><th><label for="id_email">Email:</label></th><td><input type="email" name="email" id="id_email" /></td></tr> |
| 1773 | <tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="number" name="age" id="id_age" /></td></tr>""") |
1774 | 1774 | |
1775 | 1775 | def test_label_split_datetime_not_displayed(self): |
1776 | 1776 | class EventForm(Form): |
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
index 05ef978..afa4d33 100644
a
|
b
|
class FormsFormsetTestCase(TestCase):
|
49 | 49 | formset = ChoiceFormSet(auto_id=False, prefix='choices') |
50 | 50 | self.assertHTMLEqual(str(formset), """<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" /> |
51 | 51 | <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> |
52 | | <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" /></td></tr>""") |
| 52 | <tr><th>Votes:</th><td><input type="number" name="choices-0-votes" /></td></tr>""") |
53 | 53 | |
54 | 54 | # On thing to note is that there needs to be a special value in the data. This |
55 | 55 | # value tells the FormSet how many forms were displayed so it can tell how |
… |
… |
class FormsFormsetTestCase(TestCase):
|
133 | 133 | form_output.append(form.as_ul()) |
134 | 134 | |
135 | 135 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
136 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 136 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
137 | 137 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
138 | | <li>Votes: <input type="text" name="choices-1-votes" /></li>""") |
| 138 | <li>Votes: <input type="number" name="choices-1-votes" /></li>""") |
139 | 139 | |
140 | 140 | # Let's simulate what would happen if we submitted this form. |
141 | 141 | |
… |
… |
class FormsFormsetTestCase(TestCase):
|
206 | 206 | form_output.append(form.as_ul()) |
207 | 207 | |
208 | 208 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" /></li> |
209 | | <li>Votes: <input type="text" name="choices-0-votes" /></li> |
| 209 | <li>Votes: <input type="number" name="choices-0-votes" /></li> |
210 | 210 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
211 | | <li>Votes: <input type="text" name="choices-1-votes" /></li> |
| 211 | <li>Votes: <input type="number" name="choices-1-votes" /></li> |
212 | 212 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
213 | | <li>Votes: <input type="text" name="choices-2-votes" /></li>""") |
| 213 | <li>Votes: <input type="number" name="choices-2-votes" /></li>""") |
214 | 214 | |
215 | 215 | # Since we displayed every form as blank, we will also accept them back as blank. |
216 | 216 | # This may seem a little strange, but later we will show how to require a minimum |
… |
… |
class FormsFormsetTestCase(TestCase):
|
297 | 297 | form_output.append(form.as_ul()) |
298 | 298 | |
299 | 299 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
300 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 300 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
301 | 301 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
302 | | <li>Votes: <input type="text" name="choices-1-votes" /></li> |
| 302 | <li>Votes: <input type="number" name="choices-1-votes" /></li> |
303 | 303 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
304 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
| 304 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
305 | 305 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
306 | | <li>Votes: <input type="text" name="choices-3-votes" /></li>""") |
| 306 | <li>Votes: <input type="number" name="choices-3-votes" /></li>""") |
307 | 307 | |
308 | 308 | # Make sure retrieving an empty form works, and it shows up in the form list |
309 | 309 | |
310 | 310 | self.assertTrue(formset.empty_form.empty_permitted) |
311 | 311 | self.assertHTMLEqual(formset.empty_form.as_ul(), """<li>Choice: <input type="text" name="choices-__prefix__-choice" /></li> |
312 | | <li>Votes: <input type="text" name="choices-__prefix__-votes" /></li>""") |
| 312 | <li>Votes: <input type="number" name="choices-__prefix__-votes" /></li>""") |
313 | 313 | |
314 | 314 | def test_formset_with_deletion(self): |
315 | 315 | # FormSets with deletion ###################################################### |
… |
… |
class FormsFormsetTestCase(TestCase):
|
327 | 327 | form_output.append(form.as_ul()) |
328 | 328 | |
329 | 329 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
330 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 330 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
331 | 331 | <li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> |
332 | 332 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
333 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
| 333 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
334 | 334 | <li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> |
335 | 335 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
336 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
| 336 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
337 | 337 | <li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>""") |
338 | 338 | |
339 | 339 | # To delete something, we just need to set that form's special delete field to |
… |
… |
class FormsFormsetTestCase(TestCase):
|
424 | 424 | form_output.append(form.as_ul()) |
425 | 425 | |
426 | 426 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
427 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
428 | | <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 427 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
| 428 | <li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> |
429 | 429 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
430 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
431 | | <li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 430 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
| 431 | <li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> |
432 | 432 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
433 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
434 | | <li>Order: <input type="text" name="choices-2-ORDER" /></li>""") |
| 433 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
| 434 | <li>Order: <input type="number" name="choices-2-ORDER" /></li>""") |
435 | 435 | |
436 | 436 | data = { |
437 | 437 | 'choices-TOTAL_FORMS': '3', # the number of forms rendered |
… |
… |
class FormsFormsetTestCase(TestCase):
|
535 | 535 | form_output.append(form.as_ul()) |
536 | 536 | |
537 | 537 | self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
538 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
539 | | <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 538 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
| 539 | <li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> |
540 | 540 | <li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> |
541 | 541 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
542 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
543 | | <li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 542 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
| 543 | <li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> |
544 | 544 | <li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> |
545 | 545 | <li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li> |
546 | | <li>Votes: <input type="text" name="choices-2-votes" value="500" /></li> |
547 | | <li>Order: <input type="text" name="choices-2-ORDER" value="3" /></li> |
| 546 | <li>Votes: <input type="number" name="choices-2-votes" value="500" /></li> |
| 547 | <li>Order: <input type="number" name="choices-2-ORDER" value="3" /></li> |
548 | 548 | <li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li> |
549 | 549 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
550 | | <li>Votes: <input type="text" name="choices-3-votes" /></li> |
551 | | <li>Order: <input type="text" name="choices-3-ORDER" /></li> |
| 550 | <li>Votes: <input type="number" name="choices-3-votes" /></li> |
| 551 | <li>Order: <input type="number" name="choices-3-ORDER" /></li> |
552 | 552 | <li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>""") |
553 | 553 | |
554 | 554 | # Let's delete Fergie, and put The Decemberists ahead of Calexico. |
… |
… |
class FormsetAsFooTests(TestCase):
|
864 | 864 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
865 | 865 | self.assertHTMLEqual(formset.as_table(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> |
866 | 866 | <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" value="Calexico" /></td></tr> |
867 | | <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" value="100" /></td></tr>""") |
| 867 | <tr><th>Votes:</th><td><input type="number" name="choices-0-votes" value="100" /></td></tr>""") |
868 | 868 | |
869 | 869 | def test_as_p(self): |
870 | 870 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
871 | 871 | self.assertHTMLEqual(formset.as_p(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> |
872 | 872 | <p>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></p> |
873 | | <p>Votes: <input type="text" name="choices-0-votes" value="100" /></p>""") |
| 873 | <p>Votes: <input type="number" name="choices-0-votes" value="100" /></p>""") |
874 | 874 | |
875 | 875 | def test_as_ul(self): |
876 | 876 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
877 | 877 | self.assertHTMLEqual(formset.as_ul(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" /> |
878 | 878 | <li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
879 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>""") |
| 879 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>""") |
880 | 880 | |
881 | 881 | |
882 | 882 | # Regression test for #11418 ################################################# |
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 2499b7a..395b2fc 100644
a
|
b
|
class FormsWidgetTestCase(TestCase):
|
17 | 17 | # Each Widget class corresponds to an HTML form widget. A Widget knows how to |
18 | 18 | # render itself, given a field name and some data. Widgets don't perform |
19 | 19 | # validation. |
| 20 | def test_generic_input(self): |
| 21 | w = TextInput(input_type='hello') |
| 22 | self.assertHTMLEqual(w.render('generic', ''), u'<input type="hello" name="generic" />') |
| 23 | |
20 | 24 | def test_textinput(self): |
21 | 25 | w = TextInput() |
22 | 26 | self.assertHTMLEqual(w.render('email', ''), u'<input type="text" name="email" />') |
diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
index db81eec..3c2d18e 100644
a
|
b
|
class GenericAdminViewTest(TestCase):
|
101 | 101 | # Works with no queryset |
102 | 102 | formset = EpisodeMediaFormSet(instance=e) |
103 | 103 | self.assertEqual(len(formset.forms), 5) |
104 | | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk) |
105 | | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk) |
106 | | self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>') |
| 104 | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk) |
| 105 | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk) |
| 106 | self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>') |
107 | 107 | |
108 | 108 | # A queryset can be used to alter display ordering |
109 | 109 | formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.order_by('url')) |
110 | 110 | self.assertEqual(len(formset.forms), 5) |
111 | | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk) |
112 | | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk) |
113 | | self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>') |
| 111 | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk) |
| 112 | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk) |
| 113 | self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>') |
114 | 114 | |
115 | 115 | # Works with a queryset that omits items |
116 | 116 | formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.filter(url__endswith=".png")) |
117 | 117 | self.assertEqual(len(formset.forms), 4) |
118 | | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk) |
119 | | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>') |
| 118 | self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk) |
| 119 | self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>') |
120 | 120 | |
121 | 121 | def testGenericInlineFormsetFactory(self): |
122 | 122 | # Regression test for #10522. |
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index faed4e5..7e3e703 100644
a
|
b
|
class FormattingTests(TestCase):
|
618 | 618 | self.assertEqual(True, form6.is_valid()) |
619 | 619 | self.assertHTMLEqual( |
620 | 620 | form6.as_ul(), |
621 | | u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input type="text" name="cents_paid" value="59,47" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="text" name="products_delivered" value="12000" id="id_products_delivered" /></li>' |
| 621 | u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input name="cents_paid" value="59,47" step="0.01" maxlength="5" type="number" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="number" name="products_delivered" value="12000" id="id_products_delivered" /></li>' |
622 | 622 | ) |
623 | 623 | self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00') |
624 | 624 | self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added']) |
625 | 625 | with self.settings(USE_THOUSAND_SEPARATOR=True): |
626 | 626 | # Checking for the localized "products_delivered" field |
627 | | self.assertTrue(u'<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
| 627 | self.assertTrue(u'<input type="number" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
628 | 628 | |
629 | 629 | def test_iter_format_modules(self): |
630 | 630 | """ |