Ticket #16630: html5-input-types-tests-take1.patch

File html5-input-types-tests-take1.patch, 40.9 KB (added by Jonas H., 13 years ago)
  • tests/modeltests/generic_relations/tests.py

    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):  
    229229        tag = TaggedItem.objects.create(content_object=tailless, tag="lizard")
    230230        self.assertEqual(tag.content_object, tailless)
    231231
    232 class CustomWidget(forms.CharField):
     232class CustomWidget(forms.TextInput):
    233233    pass
    234234
    235235class TaggedItemForm(forms.ModelForm):
  • tests/modeltests/model_forms/tests.py

    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):  
    10871087<option value="4">Joe Better</option>
    10881088<option value="1">Mike Royko</option>
    10891089</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>''')
    10911091
    10921092        data = {
    10931093            'writer': unicode(w_woodward.pk),
    class OldFormForXTests(TestCase):  
    11051105<option value="4">Joe Better</option>
    11061106<option value="1">Mike Royko</option>
    11071107</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>''')
    11091109
    11101110    def test_phone_number_field(self):
    11111111        f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'})
  • tests/modeltests/model_formsets/tests.py

    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):  
    359359        self.assertEqual(len(formset.forms), 1)
    360360        self.assertEqual(formset.forms[0].as_p(),
    361361            '<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>')
    363363
    364364        data = {
    365365            'form-TOTAL_FORMS': '1', # the number of forms rendered
    class ModelFormsetTest(TestCase):  
    382382        self.assertEqual(len(formset.forms), 2)
    383383        self.assertEqual(formset.forms[0].as_p(),
    384384            '<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)
    386386        self.assertEqual(formset.forms[1].as_p(),
    387387            '<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>')
    389389
    390390        data = {
    391391            'form-TOTAL_FORMS': '2', # the number of forms rendered
    class ModelFormsetTest(TestCase):  
    525525        formset = AuthorBooksFormSet2(instance=author)
    526526        self.assertEqual(len(formset.forms), 1)
    527527        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'
    529529            '<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>')
    530530
    531531        data = {
    class ModelFormsetTest(TestCase):  
    773773            '<option value="%d">Joe Perry at Giordanos</option>\n'
    774774            '<option value="%d">Jack Berry at Giordanos</option>\n'
    775775            '</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>'
    777777            % (owner1.auto_id, owner2.auto_id))
    778778
    779779        owner1 = Owner.objects.get(name=u'Joe Perry')
    class ModelFormsetTest(TestCase):  
    783783        formset = FormSet(instance=owner1)
    784784        self.assertEqual(len(formset.forms), 1)
    785785        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>'
    787787            % owner1.auto_id)
    788788
    789789        data = {
    class ModelFormsetTest(TestCase):  
    804804        formset = FormSet(instance=owner1)
    805805        self.assertEqual(len(formset.forms), 1)
    806806        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>'
    808808            % owner1.auto_id)
    809809
    810810        data = {
    class ModelFormsetTest(TestCase):  
    960960        result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result)
    961961        self.assertEqual(result,
    962962            '<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>'
    964964            % person.id)
    965965
    966966        # test for validation with callable defaults. Validations rely on hidden fields
  • tests/regressiontests/forms/tests/extra.py

    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):  
    591591        f = CommentForm(data, auto_id=False, error_class=DivErrorList)
    592592        self.assertEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p>
    593593<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>
    595595<div class="errorlist"><div class="error">This field is required.</div></div>
    596596<p>Comment: <input type="text" name="comment" /></p>""")
    597597
  • tests/regressiontests/forms/tests/fields.py

    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=()):  
    7171
    7272class FieldsTests(SimpleTestCase):
    7373
     74    def assertWidgetRendersTo(self, field, to):
     75        class _Form(Form):
     76            f = field
     77        self.assertEqual(str(_Form()['f']), to)
     78
    7479    def test_field_sets_widget_is_required(self):
    7580        self.assertTrue(Field(required=True).widget.is_required)
    7681        self.assertFalse(Field(required=False).widget.is_required)
    class FieldsTests(SimpleTestCase):  
    127132
    128133    def test_integerfield_1(self):
    129134        f = IntegerField()
     135        self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />')
    130136        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    131137        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    132138        self.assertEqual(1, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    161167
    162168    def test_integerfield_3(self):
    163169        f = IntegerField(max_value=10)
     170        self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />')
    164171        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    165172        self.assertEqual(1, f.clean(1))
    166173        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    172179
    173180    def test_integerfield_4(self):
    174181        f = IntegerField(min_value=10)
     182        self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />')
    175183        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    176184        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    177185        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    183191
    184192    def test_integerfield_5(self):
    185193        f = IntegerField(min_value=10, max_value=20)
     194        self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />')
    186195        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    187196        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    188197        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    198207
    199208    def test_floatfield_1(self):
    200209        f = FloatField()
     210        self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />')
    201211        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    202212        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    203213        self.assertEqual(1.0, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    224234
    225235    def test_floatfield_3(self):
    226236        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" />')
    227238        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    228239        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    229240        self.assertEqual(1.5, f.clean('1.5'))
    class FieldsTests(SimpleTestCase):  
    235246
    236247    def test_decimalfield_1(self):
    237248        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" />')
    238250        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    239251        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    240252        self.assertEqual(f.clean('1'), Decimal("1"))
    class FieldsTests(SimpleTestCase):  
    280292
    281293    def test_decimalfield_3(self):
    282294        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" />')
    283296        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    284297        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    285298        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    class FieldsTests(SimpleTestCase):  
    484497
    485498    def test_emailfield_1(self):
    486499        f = EmailField()
     500        self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />')
    487501        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    488502        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    489503        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    class FieldsTests(SimpleTestCase):  
    522536
    523537    def test_emailfield_3(self):
    524538        f = EmailField(min_length=10, max_length=15)
     539        self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />')
    525540        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
    526541        self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
    527542        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
    class FieldsTests(SimpleTestCase):  
    562577
    563578    def test_urlfield_1(self):
    564579        f = URLField()
     580        self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
    565581        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    566582        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    567583        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    class FieldsTests(SimpleTestCase):  
    634650
    635651    def test_urlfield_5(self):
    636652        f = URLField(min_length=15, max_length=20)
     653        self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
    637654        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
    638655        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    639656        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 20 characters (it has 38).']", f.clean, 'http://abcdefghijklmnopqrstuvwxyz.com')
  • tests/regressiontests/forms/tests/forms.py

    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):  
    252252            get_spam = BooleanField()
    253253
    254254        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" />')
    256256        self.assertEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />')
    257257
    258258        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" />')
    260260        self.assertEqual(str(f['get_spam']), '<input checked="checked" type="checkbox" name="get_spam" />')
    261261
    262262        # 'True' or 'true' should be rendered without a value attribute
    class FormsTestCase(TestCase):  
    17101710<option value="2">Yes</option>
    17111711<option value="3">No</option>
    17121712</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>""")
    17151715
    17161716        self.assertEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul>
    17171717<p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    class FormsTestCase(TestCase):  
    17201720<option value="2">Yes</option>
    17211721<option value="3">No</option>
    17221722</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>
    17241724<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>""")
    17261726
    17271727        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>
    17281728<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):  
    17301730<option value="2">Yes</option>
    17311731<option value="3">No</option>
    17321732</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>""")
    17351735
    17361736    def test_label_split_datetime_not_displayed(self):
    17371737        class EventForm(Form):
  • tests/regressiontests/forms/tests/formsets.py

    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):  
    4949        formset = ChoiceFormSet(auto_id=False, prefix='choices')
    5050        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" />
    5151<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>""")
    5353
    5454        # On thing to note is that there needs to be a special value in the data. This
    5555        # value tells the FormSet how many forms were displayed so it can tell how
    class FormsFormsetTestCase(TestCase):  
    106106            form_output.append(form.as_ul())
    107107
    108108        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>
    110110<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>""")
    112112
    113113        # Let's simulate what would happen if we submitted this form.
    114114
    class FormsFormsetTestCase(TestCase):  
    179179            form_output.append(form.as_ul())
    180180
    181181        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>
    183183<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>
    185185<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>""")
    187187
    188188        # Since we displayed every form as blank, we will also accept them back as blank.
    189189        # This may seem a little strange, but later we will show how to require a minimum
    class FormsFormsetTestCase(TestCase):  
    270270            form_output.append(form.as_ul())
    271271
    272272        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>
    274274<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>
    276276<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>
    278278<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>""")
    280280
    281281        # Make sure retrieving an empty form works, and it shows up in the form list
    282282
    283283        self.assertTrue(formset.empty_form.empty_permitted)
    284284        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>""")
    286286
    287287    def test_formset_with_deletion(self):
    288288        # FormSets with deletion ######################################################
    class FormsFormsetTestCase(TestCase):  
    300300            form_output.append(form.as_ul())
    301301
    302302        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>
    304304<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li>
    305305<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>
    307307<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li>
    308308<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>
    310310<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>""")
    311311
    312312        # To delete something, we just need to set that form's special delete field to
    class FormsFormsetTestCase(TestCase):  
    397397            form_output.append(form.as_ul())
    398398
    399399        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>
    402402<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>
    405405<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>""")
    408408
    409409        data = {
    410410            'choices-TOTAL_FORMS': '3', # the number of forms rendered
    class FormsFormsetTestCase(TestCase):  
    508508            form_output.append(form.as_ul())
    509509
    510510        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>
    513513<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li>
    514514<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>
    517517<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li>
    518518<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>
    521521<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>
    522522<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>
    525525<li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>""")
    526526
    527527        # Let's delete Fergie, and put The Decemberists ahead of Calexico.
    class FormsetAsFooTests(TestCase):  
    824824        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    825825        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" />
    826826<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>""")
    828828
    829829    def test_as_p(self):
    830830        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    831831        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" />
    832832<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>""")
    834834
    835835    def test_as_ul(self):
    836836        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    837837        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" />
    838838<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>""")
    840840
    841841
    842842# Regression test for #11418 #################################################
  • tests/regressiontests/generic_inline_admin/tests.py

    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):  
    9797        # Works with no queryset
    9898        formset = EpisodeMediaFormSet(instance=e)
    9999        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>')
    103103
    104104        # A queryset can be used to alter display ordering
    105105        formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.order_by('url'))
    106106        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>')
    110110
    111111        # Works with a queryset that omits items
    112112        formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.filter(url__endswith=".png"))
    113113        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>')
    116116
    117117    def testGenericInlineFormsetFactory(self):
    118118        # Regression test for #10522.
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index 0b955ad..9700cf7 100644
    a b class FormattingTests(TestCase):  
    431431            self.assertEqual(True, form6.is_valid())
    432432            self.assertEqual(
    433433                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>'
    435435            )
    436436            self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00')
    437437            self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added'])
    438438            with self.settings(USE_THOUSAND_SEPARATOR=True):
    439439                # 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())
    441441
    442442    def test_iter_format_modules(self):
    443443        """
Back to Top