commit 80b7e6e0ad9b338339a6f3d42f57db03c17206cc
Author: Jonas Haag <jonas@lophus.org>
Date: Sun Aug 14 20:17:36 2011 +0200
tests
diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
index 7596f77..1be81ef 100644
a
|
b
|
class GenericRelationsTests(TestCase):
|
229 | 229 | tag = TaggedItem.objects.create(content_object=tailless, tag="lizard") |
230 | 230 | self.assertEqual(tag.content_object, tailless) |
231 | 231 | |
232 | | class CustomWidget(forms.CharField): |
| 232 | class CustomWidget(forms.TextInput): |
233 | 233 | pass |
234 | 234 | |
235 | 235 | class TaggedItemForm(forms.ModelForm): |
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index 0831035..52eb065 100644
a
|
b
|
class OldFormForXTests(TestCase):
|
1087 | 1087 | <option value="4">Joe Better</option> |
1088 | 1088 | <option value="1">Mike Royko</option> |
1089 | 1089 | </select></p> |
1090 | | <p><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>''') |
| 1090 | <p><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>''') |
1091 | 1091 | |
1092 | 1092 | data = { |
1093 | 1093 | 'writer': unicode(w_woodward.pk), |
… |
… |
class OldFormForXTests(TestCase):
|
1105 | 1105 | <option value="4">Joe Better</option> |
1106 | 1106 | <option value="1">Mike Royko</option> |
1107 | 1107 | </select></p> |
1108 | | <p><label for="id_age">Age:</label> <input type="text" name="age" value="65" id="id_age" /></p>''') |
| 1108 | <p><label for="id_age">Age:</label> <input type="number" name="age" value="65" id="id_age" /></p>''') |
1109 | 1109 | |
1110 | 1110 | def test_phone_number_field(self): |
1111 | 1111 | f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'}) |
diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
index 34f8d47..b0575e1 100644
a
|
b
|
class ModelFormsetTest(TestCase):
|
359 | 359 | self.assertEqual(len(formset.forms), 1) |
360 | 360 | self.assertEqual(formset.forms[0].as_p(), |
361 | 361 | '<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' |
362 | | '<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>') |
| 362 | '<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>') |
363 | 363 | |
364 | 364 | data = { |
365 | 365 | 'form-TOTAL_FORMS': '1', # the number of forms rendered |
… |
… |
class ModelFormsetTest(TestCase):
|
382 | 382 | self.assertEqual(len(formset.forms), 2) |
383 | 383 | self.assertEqual(formset.forms[0].as_p(), |
384 | 384 | '<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' |
385 | | '<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) |
| 385 | '<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) |
386 | 386 | self.assertEqual(formset.forms[1].as_p(), |
387 | 387 | '<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' |
388 | | '<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>') |
| 388 | '<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>') |
389 | 389 | |
390 | 390 | data = { |
391 | 391 | 'form-TOTAL_FORMS': '2', # the number of forms rendered |
… |
… |
class ModelFormsetTest(TestCase):
|
525 | 525 | formset = AuthorBooksFormSet2(instance=author) |
526 | 526 | self.assertEqual(len(formset.forms), 1) |
527 | 527 | self.assertEqual(formset.forms[0].as_p(), |
528 | | '<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' |
| 528 | '<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' |
529 | 529 | '<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>') |
530 | 530 | |
531 | 531 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
773 | 773 | '<option value="%d">Joe Perry at Giordanos</option>\n' |
774 | 774 | '<option value="%d">Jack Berry at Giordanos</option>\n' |
775 | 775 | '</select></p>\n' |
776 | | '<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>' |
| 776 | '<p><label for="id_form-0-age">Age:</label> <input type="number" name="form-0-age" id="id_form-0-age" /></p>' |
777 | 777 | % (owner1.auto_id, owner2.auto_id)) |
778 | 778 | |
779 | 779 | owner1 = Owner.objects.get(name=u'Joe Perry') |
… |
… |
class ModelFormsetTest(TestCase):
|
783 | 783 | formset = FormSet(instance=owner1) |
784 | 784 | self.assertEqual(len(formset.forms), 1) |
785 | 785 | self.assertEqual(formset.forms[0].as_p(), |
786 | | '<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>' |
| 786 | '<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>' |
787 | 787 | % owner1.auto_id) |
788 | 788 | |
789 | 789 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
804 | 804 | formset = FormSet(instance=owner1) |
805 | 805 | self.assertEqual(len(formset.forms), 1) |
806 | 806 | self.assertEqual(formset.forms[0].as_p(), |
807 | | '<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>' |
| 807 | '<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>' |
808 | 808 | % owner1.auto_id) |
809 | 809 | |
810 | 810 | data = { |
… |
… |
class ModelFormsetTest(TestCase):
|
960 | 960 | result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result) |
961 | 961 | self.assertEqual(result, |
962 | 962 | '<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' |
963 | | '<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>' |
| 963 | '<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>' |
964 | 964 | % person.id) |
965 | 965 | |
966 | 966 | # 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 67a5ffc..f10a57c 100644
a
|
b
|
class FormsExtraTestCase(unittest.TestCase, AssertFormErrorsMixin):
|
591 | 591 | f = CommentForm(data, auto_id=False, error_class=DivErrorList) |
592 | 592 | self.assertEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p> |
593 | 593 | <div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div> |
594 | | <p>Email: <input type="text" name="email" value="invalid" /></p> |
| 594 | <p>Email: <input type="email" name="email" value="invalid" /></p> |
595 | 595 | <div class="errorlist"><div class="error">This field is required.</div></div> |
596 | 596 | <p>Comment: <input type="text" name="comment" /></p>""") |
597 | 597 | |
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index e1b7fe0..a293556 100644
a
|
b
|
def verify_exists_urls(existing_urls=()):
|
71 | 71 | |
72 | 72 | class FieldsTests(SimpleTestCase): |
73 | 73 | |
| 74 | def assertWidgetRendersTo(self, field, to): |
| 75 | class _Form(Form): |
| 76 | f = field |
| 77 | self.assertEqual(str(_Form()['f']), to) |
| 78 | |
74 | 79 | def test_field_sets_widget_is_required(self): |
75 | 80 | self.assertTrue(Field(required=True).widget.is_required) |
76 | 81 | self.assertFalse(Field(required=False).widget.is_required) |
… |
… |
class FieldsTests(SimpleTestCase):
|
127 | 132 | |
128 | 133 | def test_integerfield_1(self): |
129 | 134 | f = IntegerField() |
| 135 | self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />') |
130 | 136 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
131 | 137 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
132 | 138 | self.assertEqual(1, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
161 | 167 | |
162 | 168 | def test_integerfield_3(self): |
163 | 169 | f = IntegerField(max_value=10) |
| 170 | self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />') |
164 | 171 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
165 | 172 | self.assertEqual(1, f.clean(1)) |
166 | 173 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
172 | 179 | |
173 | 180 | def test_integerfield_4(self): |
174 | 181 | f = IntegerField(min_value=10) |
| 182 | self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />') |
175 | 183 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
176 | 184 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
177 | 185 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
183 | 191 | |
184 | 192 | def test_integerfield_5(self): |
185 | 193 | f = IntegerField(min_value=10, max_value=20) |
| 194 | self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />') |
186 | 195 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
187 | 196 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1) |
188 | 197 | self.assertEqual(10, f.clean(10)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
198 | 207 | |
199 | 208 | def test_floatfield_1(self): |
200 | 209 | f = FloatField() |
| 210 | self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />') |
201 | 211 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
202 | 212 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
203 | 213 | self.assertEqual(1.0, f.clean('1')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
224 | 234 | |
225 | 235 | def test_floatfield_3(self): |
226 | 236 | f = FloatField(max_value=1.5, min_value=0.5) |
| 237 | self.assertWidgetRendersTo(f, '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" />') |
227 | 238 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
228 | 239 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
229 | 240 | self.assertEqual(1.5, f.clean('1.5')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
235 | 246 | |
236 | 247 | def test_decimalfield_1(self): |
237 | 248 | f = DecimalField(max_digits=4, decimal_places=2) |
| 249 | self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" maxlength="5" />') |
238 | 250 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
239 | 251 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
240 | 252 | self.assertEqual(f.clean('1'), Decimal("1")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
280 | 292 | |
281 | 293 | def test_decimalfield_3(self): |
282 | 294 | f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) |
| 295 | self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.5" max="1.5" maxlength="5" type="number" id="id_f" />') |
283 | 296 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6') |
284 | 297 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4') |
285 | 298 | self.assertEqual(f.clean('1.5'), Decimal("1.5")) |
… |
… |
class FieldsTests(SimpleTestCase):
|
484 | 497 | |
485 | 498 | def test_emailfield_1(self): |
486 | 499 | f = EmailField() |
| 500 | self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />') |
487 | 501 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
488 | 502 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
489 | 503 | self.assertEqual(u'person@example.com', f.clean('person@example.com')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
522 | 536 | |
523 | 537 | def test_emailfield_3(self): |
524 | 538 | f = EmailField(min_length=10, max_length=15) |
| 539 | self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />') |
525 | 540 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com') |
526 | 541 | self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com')) |
527 | 542 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com') |
… |
… |
class FieldsTests(SimpleTestCase):
|
562 | 577 | |
563 | 578 | def test_urlfield_1(self): |
564 | 579 | f = URLField() |
| 580 | self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />') |
565 | 581 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '') |
566 | 582 | self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None) |
567 | 583 | self.assertEqual(u'http://localhost/', f.clean('http://localhost')) |
… |
… |
class FieldsTests(SimpleTestCase):
|
634 | 650 | |
635 | 651 | def test_urlfield_5(self): |
636 | 652 | f = URLField(min_length=15, max_length=20) |
| 653 | self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />') |
637 | 654 | self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com') |
638 | 655 | self.assertEqual(u'http://example.com/', f.clean('http://example.com')) |
639 | 656 | 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 ed783af..f0463f4 100644
a
|
b
|
class FormsTestCase(TestCase):
|
252 | 252 | get_spam = BooleanField() |
253 | 253 | |
254 | 254 | f = SignupForm(auto_id=False) |
255 | | self.assertEqual(str(f['email']), '<input type="text" name="email" />') |
| 255 | self.assertEqual(str(f['email']), '<input type="email" name="email" />') |
256 | 256 | self.assertEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />') |
257 | 257 | |
258 | 258 | f = SignupForm({'email': 'test@example.com', 'get_spam': True}, auto_id=False) |
259 | | self.assertEqual(str(f['email']), '<input type="text" name="email" value="test@example.com" />') |
| 259 | self.assertEqual(str(f['email']), '<input type="email" name="email" value="test@example.com" />') |
260 | 260 | self.assertEqual(str(f['get_spam']), '<input checked="checked" type="checkbox" name="get_spam" />') |
261 | 261 | |
262 | 262 | # 'True' or 'true' should be rendered without a value attribute |
… |
… |
class FormsTestCase(TestCase):
|
1710 | 1710 | <option value="2">Yes</option> |
1711 | 1711 | <option value="3">No</option> |
1712 | 1712 | </select></li> |
1713 | | <li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li> |
1714 | | <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>""") |
| 1713 | <li><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></li> |
| 1714 | <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>""") |
1715 | 1715 | |
1716 | 1716 | self.assertEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul> |
1717 | 1717 | <p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p> |
… |
… |
class FormsTestCase(TestCase):
|
1720 | 1720 | <option value="2">Yes</option> |
1721 | 1721 | <option value="3">No</option> |
1722 | 1722 | </select></p> |
1723 | | <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p> |
| 1723 | <p><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></p> |
1724 | 1724 | <ul class="errorlist"><li>This field is required.</li></ul> |
1725 | | <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""") |
| 1725 | <p class="required error"><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>""") |
1726 | 1726 | |
1727 | 1727 | 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> |
1728 | 1728 | <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):
|
1730 | 1730 | <option value="2">Yes</option> |
1731 | 1731 | <option value="3">No</option> |
1732 | 1732 | </select></td></tr> |
1733 | | <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr> |
1734 | | <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>""") |
| 1733 | <tr><th><label for="id_email">Email:</label></th><td><input type="email" name="email" id="id_email" /></td></tr> |
| 1734 | <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>""") |
1735 | 1735 | |
1736 | 1736 | def test_label_split_datetime_not_displayed(self): |
1737 | 1737 | class EventForm(Form): |
diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
index 4451fc7..4920ed8 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):
|
106 | 106 | form_output.append(form.as_ul()) |
107 | 107 | |
108 | 108 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
109 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 109 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
110 | 110 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
111 | | <li>Votes: <input type="text" name="choices-1-votes" /></li>""") |
| 111 | <li>Votes: <input type="number" name="choices-1-votes" /></li>""") |
112 | 112 | |
113 | 113 | # Let's simulate what would happen if we submitted this form. |
114 | 114 | |
… |
… |
class FormsFormsetTestCase(TestCase):
|
179 | 179 | form_output.append(form.as_ul()) |
180 | 180 | |
181 | 181 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" /></li> |
182 | | <li>Votes: <input type="text" name="choices-0-votes" /></li> |
| 182 | <li>Votes: <input type="number" name="choices-0-votes" /></li> |
183 | 183 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
184 | | <li>Votes: <input type="text" name="choices-1-votes" /></li> |
| 184 | <li>Votes: <input type="number" name="choices-1-votes" /></li> |
185 | 185 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
186 | | <li>Votes: <input type="text" name="choices-2-votes" /></li>""") |
| 186 | <li>Votes: <input type="number" name="choices-2-votes" /></li>""") |
187 | 187 | |
188 | 188 | # Since we displayed every form as blank, we will also accept them back as blank. |
189 | 189 | # This may seem a little strange, but later we will show how to require a minimum |
… |
… |
class FormsFormsetTestCase(TestCase):
|
270 | 270 | form_output.append(form.as_ul()) |
271 | 271 | |
272 | 272 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
273 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 273 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
274 | 274 | <li>Choice: <input type="text" name="choices-1-choice" /></li> |
275 | | <li>Votes: <input type="text" name="choices-1-votes" /></li> |
| 275 | <li>Votes: <input type="number" name="choices-1-votes" /></li> |
276 | 276 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
277 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
| 277 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
278 | 278 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
279 | | <li>Votes: <input type="text" name="choices-3-votes" /></li>""") |
| 279 | <li>Votes: <input type="number" name="choices-3-votes" /></li>""") |
280 | 280 | |
281 | 281 | # Make sure retrieving an empty form works, and it shows up in the form list |
282 | 282 | |
283 | 283 | self.assertTrue(formset.empty_form.empty_permitted) |
284 | 284 | self.assertEqual(formset.empty_form.as_ul(), """<li>Choice: <input type="text" name="choices-__prefix__-choice" /></li> |
285 | | <li>Votes: <input type="text" name="choices-__prefix__-votes" /></li>""") |
| 285 | <li>Votes: <input type="number" name="choices-__prefix__-votes" /></li>""") |
286 | 286 | |
287 | 287 | def test_formset_with_deletion(self): |
288 | 288 | # FormSets with deletion ###################################################### |
… |
… |
class FormsFormsetTestCase(TestCase):
|
300 | 300 | form_output.append(form.as_ul()) |
301 | 301 | |
302 | 302 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
303 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
| 303 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
304 | 304 | <li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> |
305 | 305 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
306 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
| 306 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
307 | 307 | <li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> |
308 | 308 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
309 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
| 309 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
310 | 310 | <li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>""") |
311 | 311 | |
312 | 312 | # To delete something, we just need to set that form's special delete field to |
… |
… |
class FormsFormsetTestCase(TestCase):
|
397 | 397 | form_output.append(form.as_ul()) |
398 | 398 | |
399 | 399 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
400 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
401 | | <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 400 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
| 401 | <li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> |
402 | 402 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
403 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
404 | | <li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 403 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
| 404 | <li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> |
405 | 405 | <li>Choice: <input type="text" name="choices-2-choice" /></li> |
406 | | <li>Votes: <input type="text" name="choices-2-votes" /></li> |
407 | | <li>Order: <input type="text" name="choices-2-ORDER" /></li>""") |
| 406 | <li>Votes: <input type="number" name="choices-2-votes" /></li> |
| 407 | <li>Order: <input type="number" name="choices-2-ORDER" /></li>""") |
408 | 408 | |
409 | 409 | data = { |
410 | 410 | 'choices-TOTAL_FORMS': '3', # the number of forms rendered |
… |
… |
class FormsFormsetTestCase(TestCase):
|
508 | 508 | form_output.append(form.as_ul()) |
509 | 509 | |
510 | 510 | self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
511 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li> |
512 | | <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li> |
| 511 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li> |
| 512 | <li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li> |
513 | 513 | <li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li> |
514 | 514 | <li>Choice: <input type="text" name="choices-1-choice" value="Fergie" /></li> |
515 | | <li>Votes: <input type="text" name="choices-1-votes" value="900" /></li> |
516 | | <li>Order: <input type="text" name="choices-1-ORDER" value="2" /></li> |
| 515 | <li>Votes: <input type="number" name="choices-1-votes" value="900" /></li> |
| 516 | <li>Order: <input type="number" name="choices-1-ORDER" value="2" /></li> |
517 | 517 | <li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li> |
518 | 518 | <li>Choice: <input type="text" name="choices-2-choice" value="The Decemberists" /></li> |
519 | | <li>Votes: <input type="text" name="choices-2-votes" value="500" /></li> |
520 | | <li>Order: <input type="text" name="choices-2-ORDER" value="3" /></li> |
| 519 | <li>Votes: <input type="number" name="choices-2-votes" value="500" /></li> |
| 520 | <li>Order: <input type="number" name="choices-2-ORDER" value="3" /></li> |
521 | 521 | <li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li> |
522 | 522 | <li>Choice: <input type="text" name="choices-3-choice" /></li> |
523 | | <li>Votes: <input type="text" name="choices-3-votes" /></li> |
524 | | <li>Order: <input type="text" name="choices-3-ORDER" /></li> |
| 523 | <li>Votes: <input type="number" name="choices-3-votes" /></li> |
| 524 | <li>Order: <input type="number" name="choices-3-ORDER" /></li> |
525 | 525 | <li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>""") |
526 | 526 | |
527 | 527 | # Let's delete Fergie, and put The Decemberists ahead of Calexico. |
… |
… |
class FormsetAsFooTests(TestCase):
|
824 | 824 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
825 | 825 | 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" /> |
826 | 826 | <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" value="Calexico" /></td></tr> |
827 | | <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" value="100" /></td></tr>""") |
| 827 | <tr><th>Votes:</th><td><input type="number" name="choices-0-votes" value="100" /></td></tr>""") |
828 | 828 | |
829 | 829 | def test_as_p(self): |
830 | 830 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
831 | 831 | 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" /> |
832 | 832 | <p>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></p> |
833 | | <p>Votes: <input type="text" name="choices-0-votes" value="100" /></p>""") |
| 833 | <p>Votes: <input type="number" name="choices-0-votes" value="100" /></p>""") |
834 | 834 | |
835 | 835 | def test_as_ul(self): |
836 | 836 | formset = ChoiceFormSet(data, auto_id=False, prefix='choices') |
837 | 837 | 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" /> |
838 | 838 | <li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li> |
839 | | <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>""") |
| 839 | <li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>""") |
840 | 840 | |
841 | 841 | |
842 | 842 | # Regression test for #11418 ################################################# |
diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
index da59922..63d073a 100644
a
|
b
|
class GenericAdminViewTest(TestCase):
|
97 | 97 | # Works with no queryset |
98 | 98 | formset = EpisodeMediaFormSet(instance=e) |
99 | 99 | self.assertEqual(len(formset.forms), 5) |
100 | | 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) |
101 | | 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) |
102 | | 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>') |
| 100 | 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) |
| 101 | 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) |
| 102 | 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>') |
103 | 103 | |
104 | 104 | # A queryset can be used to alter display ordering |
105 | 105 | formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.order_by('url')) |
106 | 106 | self.assertEqual(len(formset.forms), 5) |
107 | | 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) |
108 | | 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) |
109 | | 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>') |
| 107 | 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) |
| 108 | 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) |
| 109 | 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>') |
110 | 110 | |
111 | 111 | # Works with a queryset that omits items |
112 | 112 | formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.filter(url__endswith=".png")) |
113 | 113 | self.assertEqual(len(formset.forms), 4) |
114 | | 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) |
115 | | 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>') |
| 114 | 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) |
| 115 | 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>') |
116 | 116 | |
117 | 117 | def testGenericInlineFormsetFactory(self): |
118 | 118 | # Regression test for #10522. |
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 0b955ad..9700cf7 100644
a
|
b
|
class FormattingTests(TestCase):
|
431 | 431 | self.assertEqual(True, form6.is_valid()) |
432 | 432 | self.assertEqual( |
433 | 433 | form6.as_ul(), |
434 | | 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_payed">Cents payed:</label> <input type="text" name="cents_payed" value="59,47" id="id_cents_payed" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="text" name="products_delivered" value="12000" id="id_products_delivered" /></li>' |
| 434 | 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_payed">Cents payed:</label> <input name="cents_payed" value="59,47" step="0.01" maxlength="5" type="number" id="id_cents_payed" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="number" name="products_delivered" value="12000" id="id_products_delivered" /></li>' |
435 | 435 | ) |
436 | 436 | self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00') |
437 | 437 | self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added']) |
438 | 438 | with self.settings(USE_THOUSAND_SEPARATOR=True): |
439 | 439 | # Checking for the localized "products_delivered" field |
440 | | self.assertTrue(u'<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
| 440 | self.assertTrue(u'<input type="number" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul()) |
441 | 441 | |
442 | 442 | def test_iter_format_modules(self): |
443 | 443 | """ |