commit 55387a8e264717300ac8e704c8384a565358b5ae
Author: Jonas Haag <jonas@lophus.org>
Date: Sun Aug 14 20:17:36 2011 +0200
t tests
diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
index adfba82..f3831ee 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 2be3a0d..892e301 100644
a
|
b
|
class ModelFormsetTest(TestCase):
|
383 | 383 | self.assertEqual(len(formset.forms), 1) |
384 | 384 | self.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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 cbec105..27f08a3 100644
a
|
b
|
class FormsExtraTestCase(unittest.TestCase, AssertFormErrorsMixin):
|
597 | 597 | f = CommentForm(data, auto_id=False, error_class=DivErrorList) |
598 | 598 | self.assertEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p> |
599 | 599 | <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> |
600 | | <p>Email: <input type="text" name="email" value="invalid" /></p> |
| 600 | <p>Email: <input type="email" name="email" value="invalid" /></p> |
601 | 601 | <div class="errorlist"><div class="error">This field is required.</div></div> |
602 | 602 | <p>Comment: <input type="text" name="comment" /></p>""") |
603 | 603 | |
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 7dd3a27..68908c6 100644
a
|
b
|
def verify_exists_urls(existing_urls=()):
|
75 | 75 | |
76 | 76 | |
77 | 77 | class FieldsTests(SimpleTestCase): |
78 | | |
79 | 78 | def setUp(self): |
80 | 79 | self.save_warnings_state() |
81 | 80 | warnings.filterwarnings('ignore', category=DeprecationWarning, |
… |
… |
class FieldsTests(SimpleTestCase):
|
84 | 83 | def tearDown(self): |
85 | 84 | self.restore_warnings_state() |
86 | 85 | |
| 86 | def assertWidgetRendersTo(self, field, to): |
| 87 | class _Form(Form): |
| 88 | f = field |
| 89 | self.assertEqual(str(_Form()['f']), to) |
| 90 | |
87 | 91 | def test_field_sets_widget_is_required(self): |
88 | 92 | self.assertTrue(Field(required=True).widget.is_required) |
89 | 93 | self.assertFalse(Field(required=False).widget.is_required) |
… |
… |
class FieldsTests(SimpleTestCase):
|
157 | 161 | |
158 | 162 | def test_integerfield_1(self): |
159 | 163 | f = IntegerField() |
| 164 | self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />') |
160 | 165 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
161 | 166 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
162 | 167 | self.assertEqual(1, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
191 | 196 | |
192 | 197 | def test_integerfield_3(self): |
193 | 198 | f = IntegerField(max_value=10) |
| 199 | self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />') |
194 | 200 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
195 | 201 | self.assertEqual(1, f.clean(1)) |
196 | 202 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
202 | 208 | |
203 | 209 | def test_integerfield_4(self): |
204 | 210 | f = IntegerField(min_value=10) |
| 211 | self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />') |
205 | 212 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
206 | 213 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
207 | 214 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
213 | 220 | |
214 | 221 | def test_integerfield_5(self): |
215 | 222 | f = IntegerField(min_value=10, max_value=20) |
| 223 | self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />') |
216 | 224 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
217 | 225 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
218 | 226 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
228 | 236 | |
229 | 237 | def test_floatfield_1(self): |
230 | 238 | f = FloatField() |
| 239 | self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />') |
231 | 240 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
232 | 241 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
233 | 242 | self.assertEqual(1.0, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
254 | 263 | |
255 | 264 | def test_floatfield_3(self): |
256 | 265 | f = FloatField(max_value=1.5, min_value=0.5) |
| 266 | self.assertWidgetRendersTo(f, '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" />') |
257 | 267 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
258 | 268 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
259 | 269 | self.assertEqual(1.5, f.clean('1.5')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
265 | 275 | |
266 | 276 | def test_decimalfield_1(self): |
267 | 277 | f = DecimalField(max_digits=4, decimal_places=2) |
| 278 | self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" maxlength="5" />') |
268 | 279 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
269 | 280 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
270 | 281 | self.assertEqual(f.clean('1'), Decimal("1")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
310 | 321 | |
311 | 322 | def test_decimalfield_3(self): |
312 | 323 | f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) |
| 324 | self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.5" max="1.5" maxlength="5" type="number" id="id_f" />') |
313 | 325 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
314 | 326 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
315 | 327 | self.assertEqual(f.clean('1.5'), Decimal("1.5")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
524 | 536 | |
525 | 537 | def test_emailfield_1(self): |
526 | 538 | f = EmailField() |
| 539 | self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />') |
527 | 540 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
528 | 541 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
529 | 542 | self.assertEqual(u'person@example.com', f.clean('person@example.com')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
562 | 575 | |
563 | 576 | def test_emailfield_3(self): |
564 | 577 | f = EmailField(min_length=10, max_length=15) |
| 578 | self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />') |
565 | 579 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com') |
566 | 580 | self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com')) |
567 | 581 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com') |
… |
… |
class FieldsTests(SimpleTestCase):
|
602 | 616 | |
603 | 617 | def test_urlfield_1(self): |
604 | 618 | f = URLField() |
| 619 | self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />') |
605 | 620 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
606 | 621 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
607 | 622 | self.assertEqual(u'http://localhost/', f.clean('http://localhost')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
676 | 691 | |
677 | 692 | def test_urlfield_5(self): |
678 | 693 | f = URLField(min_length=15, max_length=20) |
| 694 | self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />') |
679 | 695 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com') |
680 | 696 | self.assertEqual(u'http://example.com/', f.clean('http://example.com')) |
681 | 697 | 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 4e9cc16..f98d50b 100644
a
|
b
|
class FormsTestCase(TestCase):
|
253 | 253 | get_spam = BooleanField() |
254 | 254 | |
255 | 255 | f = SignupForm(auto_id=False) |
256 | | self.assertEqual(str(f['email']), '<input type="text" name="email" />') |
| 256 | self.assertEqual(str(f['email']), '<input type="email" name="email" />') |
257 | 257 | self.assertEqual(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.assertEqual(str(f['email']), '<input type="text" name="email" value="test@example.com" />') |
| 260 | self.assertEqual(str(f['email']), '<input type="email" name="email" value="test@example.com" />') |
261 | 261 | self.assertEqual(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):
|
1746 | 1746 | <option value="2">Yes</option> |
1747 | 1747 | <option value="3">No</option> |
1748 | 1748 | </select></li> |
1749 | | <li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li> |
1750 | | <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>""") |
| 1749 | <li><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></li> |
| 1750 | <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>""") |
1751 | 1751 | |
1752 | 1752 | self.assertEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul> |
1753 | 1753 | <p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p> |
… |
… |
class FormsTestCase(TestCase):
|
1756 | 1756 | <option value="2">Yes</option> |
1757 | 1757 | <option value="3">No</option> |
1758 | 1758 | </select></p> |
1759 | | <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p> |
| 1759 | <p><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></p> |
1760 | 1760 | <ul class="errorlist"><li>This field is required.</li></ul> |
1761 | | <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""") |
| 1761 | <p class="required error"><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>""") |
1762 | 1762 | |
1763 | 1763 | self.assertEqual(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> |
1764 | 1764 | <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):
|
1766 | 1766 | <option value="2">Yes</option> |
1767 | 1767 | <option value="3">No</option> |
1768 | 1768 | </select></td></tr> |
1769 | | <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr> |
1770 | | <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>""") |
| 1769 | <tr><th><label for="id_email">Email:</label></th><td><input type="email" name="email" id="id_email" /></td></tr> |
| 1770 | <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>""") |
1771 | 1771 | |
1772 | 1772 | def test_label_split_datetime_not_displayed(self): |
1773 | 1773 | class EventForm(Form): |
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
index f218053..909b8ae 100644
a
|
b
|
class FormsFormsetTestCase(TestCase):
|
49 | 49 | formset = ChoiceFormSet(auto_id=False, prefix='choices') |
50 | 50 | self.assertEqual(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.assertEqual('\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.assertEqual('\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.assertEqual('\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.assertEqual(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.assertEqual('\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.assertEqual('\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.assertEqual('\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.assertEqual(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.assertEqual(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.assertEqual(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/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
index 2c82acf..a576c4a 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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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 0a2852e..02ad1b0 100644
a
|
b
|
class FormattingTests(TestCase):
|
619 | 619 | self.assertEqual(True, form6.is_valid()) |
620 | 620 | self.assertEqual( |
621 | 621 | form6.as_ul(), |
622 | | 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>' |
| 622 | 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>' |
623 | 623 | ) |
624 | 624 | self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00') |
625 | 625 | self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added']) |
626 | 626 | with self.settings(USE_THOUSAND_SEPARATOR=True): |
627 | 627 | # Checking for the localized "products_delivered" field |
628 | | self.assertTrue(u'<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
| 628 | self.assertTrue(u'<input type="number" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
629 | 629 | |
630 | 630 | def test_iter_format_modules(self): |
631 | 631 | """ |