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

File html5-input-types-tests-take3.patch, 40.8 KB (added by Jonas H., 13 years ago)

Against [17904]

  • tests/modeltests/generic_relations/tests.py

    diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
    index 0ac552c..4c40d6d 100644
    a b class GenericRelationsTests(TestCase):  
    231231        tag = TaggedItem.objects.create(content_object=tailless, tag="lizard")
    232232        self.assertEqual(tag.content_object, tailless)
    233233
    234 class CustomWidget(forms.CharField):
     234class CustomWidget(forms.TextInput):
    235235    pass
    236236
    237237class TaggedItemForm(forms.ModelForm):
  • tests/modeltests/model_formsets/tests.py

    diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py
    index 4694147..b8711fc 100644
    a b class ModelFormsetTest(TestCase):  
    383383        self.assertEqual(len(formset.forms), 1)
    384384        self.assertHTMLEqual(formset.forms[0].as_p(),
    385385            '<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>')
    387387
    388388        data = {
    389389            'form-TOTAL_FORMS': '1', # the number of forms rendered
    class ModelFormsetTest(TestCase):  
    406406        self.assertEqual(len(formset.forms), 2)
    407407        self.assertHTMLEqual(formset.forms[0].as_p(),
    408408            '<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)
    410410        self.assertHTMLEqual(formset.forms[1].as_p(),
    411411            '<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>')
    413413
    414414        data = {
    415415            'form-TOTAL_FORMS': '2', # the number of forms rendered
    class ModelFormsetTest(TestCase):  
    549549        formset = AuthorBooksFormSet2(instance=author)
    550550        self.assertEqual(len(formset.forms), 1)
    551551        self.assertHTMLEqual(formset.forms[0].as_p(),
    552             '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input type="text" name="bookwithcustompk_set-0-my_pk" id="id_bookwithcustompk_set-0-my_pk" /></p>\n'
     552            '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input id="id_bookwithcustompk_set-0-my_pk" type="number" name="bookwithcustompk_set-0-my_pk" maxlength="6" /></p>\n'
    553553            '<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>')
    554554
    555555        data = {
    class ModelFormsetTest(TestCase):  
    797797            '<option value="%d">Joe Perry at Giordanos</option>\n'
    798798            '<option value="%d">Jack Berry at Giordanos</option>\n'
    799799            '</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>'
    801801            % (owner1.auto_id, owner2.auto_id))
    802802
    803803        owner1 = Owner.objects.get(name=u'Joe Perry')
    class ModelFormsetTest(TestCase):  
    807807        formset = FormSet(instance=owner1)
    808808        self.assertEqual(len(formset.forms), 1)
    809809        self.assertHTMLEqual(formset.forms[0].as_p(),
    810             '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
     810            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
    811811            % owner1.auto_id)
    812812
    813813        data = {
    class ModelFormsetTest(TestCase):  
    828828        formset = FormSet(instance=owner1)
    829829        self.assertEqual(len(formset.forms), 1)
    830830        self.assertHTMLEqual(formset.forms[0].as_p(),
    831             '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
     831            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
    832832            % owner1.auto_id)
    833833
    834834        data = {
    class ModelFormsetTest(TestCase):  
    984984        result = re.sub(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d+)?', '__DATETIME__', result)
    985985        self.assertHTMLEqual(result,
    986986            '<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>'
    988988            % person.id)
    989989
    990990        # 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 c873af7..a79ffdf 100644
    a b class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):  
    603603        f = CommentForm(data, auto_id=False, error_class=DivErrorList)
    604604        self.assertHTMLEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p>
    605605<div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div>
    606 <p>Email: <input type="text" name="email" value="invalid" /></p>
     606<p>Email: <input type="email" name="email" value="invalid" /></p>
    607607<div class="errorlist"><div class="error">This field is required.</div></div>
    608608<p>Comment: <input type="text" name="comment" /></p>""")
    609609
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 6e4a544..6e9dc08 100644
    a b def fix_os_paths(x):  
    4747
    4848
    4949class FieldsTests(SimpleTestCase):
    50 
    5150    def setUp(self):
    5251        self.save_warnings_state()
    5352        warnings.filterwarnings('ignore', category=DeprecationWarning,
    class FieldsTests(SimpleTestCase):  
    5655    def tearDown(self):
    5756        self.restore_warnings_state()
    5857
     58    def assertWidgetRendersTo(self, field, to):
     59        class _Form(Form):
     60            f = field
     61        self.assertEqual(str(_Form()['f']), to)
     62
    5963    def test_field_sets_widget_is_required(self):
    6064        self.assertTrue(Field(required=True).widget.is_required)
    6165        self.assertFalse(Field(required=False).widget.is_required)
    class FieldsTests(SimpleTestCase):  
    129133
    130134    def test_integerfield_1(self):
    131135        f = IntegerField()
     136        self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />')
    132137        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    133138        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    134139        self.assertEqual(1, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    163168
    164169    def test_integerfield_3(self):
    165170        f = IntegerField(max_value=10)
     171        self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />')
    166172        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    167173        self.assertEqual(1, f.clean(1))
    168174        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    174180
    175181    def test_integerfield_4(self):
    176182        f = IntegerField(min_value=10)
     183        self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />')
    177184        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    178185        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    179186        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    185192
    186193    def test_integerfield_5(self):
    187194        f = IntegerField(min_value=10, max_value=20)
     195        self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />')
    188196        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    189197        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    190198        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    200208
    201209    def test_floatfield_1(self):
    202210        f = FloatField()
     211        self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />')
    203212        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    204213        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    205214        self.assertEqual(1.0, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    226235
    227236    def test_floatfield_3(self):
    228237        f = FloatField(max_value=1.5, min_value=0.5)
     238        self.assertWidgetRendersTo(f, '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" />')
    229239        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    230240        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    231241        self.assertEqual(1.5, f.clean('1.5'))
    class FieldsTests(SimpleTestCase):  
    237247
    238248    def test_decimalfield_1(self):
    239249        f = DecimalField(max_digits=4, decimal_places=2)
     250        self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" maxlength="5" />')
    240251        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    241252        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    242253        self.assertEqual(f.clean('1'), Decimal("1"))
    class FieldsTests(SimpleTestCase):  
    282293
    283294    def test_decimalfield_3(self):
    284295        f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
     296        self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.5" max="1.5" maxlength="5" type="number" id="id_f" />')
    285297        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    286298        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    287299        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    class FieldsTests(SimpleTestCase):  
    496508
    497509    def test_emailfield_1(self):
    498510        f = EmailField()
     511        self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />')
    499512        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    500513        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    501514        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    class FieldsTests(SimpleTestCase):  
    534547
    535548    def test_emailfield_3(self):
    536549        f = EmailField(min_length=10, max_length=15)
     550        self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />')
    537551        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
    538552        self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
    539553        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
    class FieldsTests(SimpleTestCase):  
    574588
    575589    def test_urlfield_1(self):
    576590        f = URLField()
     591        self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
    577592        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    578593        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    579594        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    class FieldsTests(SimpleTestCase):  
    625640
    626641    def test_urlfield_5(self):
    627642        f = URLField(min_length=15, max_length=20)
     643        self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
    628644        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
    629645        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    630646        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 3f529f2..f1edc6d 100644
    a b class FormsTestCase(TestCase):  
    253253            get_spam = BooleanField()
    254254
    255255        f = SignupForm(auto_id=False)
    256         self.assertHTMLEqual(str(f['email']), '<input type="text" name="email" />')
     256        self.assertHTMLEqual(str(f['email']), '<input type="email" name="email" />')
    257257        self.assertHTMLEqual(str(f['get_spam']), '<input type="checkbox" name="get_spam" />')
    258258
    259259        f = SignupForm({'email': 'test@example.com', 'get_spam': True}, auto_id=False)
    260         self.assertHTMLEqual(str(f['email']), '<input type="text" name="email" value="test@example.com" />')
     260        self.assertHTMLEqual(str(f['email']), '<input type="email" name="email" value="test@example.com" />')
    261261        self.assertHTMLEqual(str(f['get_spam']), '<input checked="checked" type="checkbox" name="get_spam" />')
    262262
    263263        # 'True' or 'true' should be rendered without a value attribute
    class FormsTestCase(TestCase):  
    17491749<option value="2">Yes</option>
    17501750<option value="3">No</option>
    17511751</select></li>
    1752 <li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li>
    1753 <li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></li>""")
     1752<li><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></li>
     1753<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></li>""")
    17541754
    17551755        self.assertHTMLEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul>
    17561756<p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    class FormsTestCase(TestCase):  
    17591759<option value="2">Yes</option>
    17601760<option value="3">No</option>
    17611761</select></p>
    1762 <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p>
     1762<p><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></p>
    17631763<ul class="errorlist"><li>This field is required.</li></ul>
    1764 <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""")
     1764<p class="required error"><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>""")
    17651765
    17661766        self.assertHTMLEqual(p.as_table(), """<tr class="required error"><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="name" id="id_name" /></td></tr>
    17671767<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):  
    17691769<option value="2">Yes</option>
    17701770<option value="3">No</option>
    17711771</select></td></tr>
    1772 <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>
    1773 <tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="age" id="id_age" /></td></tr>""")
     1772<tr><th><label for="id_email">Email:</label></th><td><input type="email" name="email" id="id_email" /></td></tr>
     1773<tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="number" name="age" id="id_age" /></td></tr>""")
    17741774
    17751775    def test_label_split_datetime_not_displayed(self):
    17761776        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 05ef978..afa4d33 100644
    a b class FormsFormsetTestCase(TestCase):  
    4949        formset = ChoiceFormSet(auto_id=False, prefix='choices')
    5050        self.assertHTMLEqual(str(formset), """<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" />
    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):  
    133133            form_output.append(form.as_ul())
    134134
    135135        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    136 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     136<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    137137<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>""")
    139139
    140140        # Let's simulate what would happen if we submitted this form.
    141141
    class FormsFormsetTestCase(TestCase):  
    206206            form_output.append(form.as_ul())
    207207
    208208        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" /></li>
    209 <li>Votes: <input type="text" name="choices-0-votes" /></li>
     209<li>Votes: <input type="number" name="choices-0-votes" /></li>
    210210<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>
    212212<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>""")
    214214
    215215        # Since we displayed every form as blank, we will also accept them back as blank.
    216216        # This may seem a little strange, but later we will show how to require a minimum
    class FormsFormsetTestCase(TestCase):  
    297297            form_output.append(form.as_ul())
    298298
    299299        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    300 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     300<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    301301<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>
    303303<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>
    305305<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>""")
    307307
    308308        # Make sure retrieving an empty form works, and it shows up in the form list
    309309
    310310        self.assertTrue(formset.empty_form.empty_permitted)
    311311        self.assertHTMLEqual(formset.empty_form.as_ul(), """<li>Choice: <input type="text" name="choices-__prefix__-choice" /></li>
    312 <li>Votes: <input type="text" name="choices-__prefix__-votes" /></li>""")
     312<li>Votes: <input type="number" name="choices-__prefix__-votes" /></li>""")
    313313
    314314    def test_formset_with_deletion(self):
    315315        # FormSets with deletion ######################################################
    class FormsFormsetTestCase(TestCase):  
    327327            form_output.append(form.as_ul())
    328328
    329329        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    330 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     330<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    331331<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li>
    332332<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>
    334334<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li>
    335335<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>
    337337<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>""")
    338338
    339339        # To delete something, we just need to set that form's special delete field to
    class FormsFormsetTestCase(TestCase):  
    424424            form_output.append(form.as_ul())
    425425
    426426        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    427 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
    428 <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li>
     427<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
     428<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li>
    429429<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>
    432432<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>""")
    435435
    436436        data = {
    437437            'choices-TOTAL_FORMS': '3', # the number of forms rendered
    class FormsFormsetTestCase(TestCase):  
    535535            form_output.append(form.as_ul())
    536536
    537537        self.assertHTMLEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    538 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
    539 <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li>
     538<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
     539<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li>
    540540<li>Delete: <input type="checkbox" name="choices-0-DELETE" /></li>
    541541<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>
    544544<li>Delete: <input type="checkbox" name="choices-1-DELETE" /></li>
    545545<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>
    548548<li>Delete: <input type="checkbox" name="choices-2-DELETE" /></li>
    549549<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>
    552552<li>Delete: <input type="checkbox" name="choices-3-DELETE" /></li>""")
    553553
    554554        # Let's delete Fergie, and put The Decemberists ahead of Calexico.
    class FormsetAsFooTests(TestCase):  
    864864        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    865865        self.assertHTMLEqual(formset.as_table(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" />
    866866<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>""")
    868868
    869869    def test_as_p(self):
    870870        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    871871        self.assertHTMLEqual(formset.as_p(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" />
    872872<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>""")
    874874
    875875    def test_as_ul(self):
    876876        formset = ChoiceFormSet(data, auto_id=False, prefix='choices')
    877877        self.assertHTMLEqual(formset.as_ul(),"""<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /><input type="hidden" name="choices-MAX_NUM_FORMS" value="0" />
    878878<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>""")
    880880
    881881
    882882# Regression test for #11418 #################################################
  • tests/regressiontests/forms/tests/widgets.py

    diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
    index 2499b7a..395b2fc 100644
    a b class FormsWidgetTestCase(TestCase):  
    1717    # Each Widget class corresponds to an HTML form widget. A Widget knows how to
    1818    # render itself, given a field name and some data. Widgets don't perform
    1919    # validation.
     20    def test_generic_input(self):
     21        w = TextInput(input_type='hello')
     22        self.assertHTMLEqual(w.render('generic', ''), u'<input type="hello" name="generic" />')
     23
    2024    def test_textinput(self):
    2125        w = TextInput()
    2226        self.assertHTMLEqual(w.render('email', ''), u'<input type="text" name="email" />')
  • 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 db81eec..3c2d18e 100644
    a b class GenericAdminViewTest(TestCase):  
    101101        # Works with no queryset
    102102        formset = EpisodeMediaFormSet(instance=e)
    103103        self.assertEqual(len(formset.forms), 5)
    104         self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk)
    105         self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk)
    106         self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
     104        self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk)
     105        self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk)
     106        self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
    107107
    108108        # A queryset can be used to alter display ordering
    109109        formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.order_by('url'))
    110110        self.assertEqual(len(formset.forms), 5)
    111         self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
    112         self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk)
    113         self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
     111        self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
     112        self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk)
     113        self.assertHTMLEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
    114114
    115115        # Works with a queryset that omits items
    116116        formset = EpisodeMediaFormSet(instance=e, queryset=Media.objects.filter(url__endswith=".png"))
    117117        self.assertEqual(len(formset.forms), 4)
    118         self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
    119         self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>')
     118        self.assertHTMLEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
     119        self.assertHTMLEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>')
    120120
    121121    def testGenericInlineFormsetFactory(self):
    122122        # Regression test for #10522.
  • tests/regressiontests/i18n/tests.py

    diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
    index faed4e5..7e3e703 100644
    a b class FormattingTests(TestCase):  
    618618            self.assertEqual(True, form6.is_valid())
    619619            self.assertHTMLEqual(
    620620                form6.as_ul(),
    621                 u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input type="text" name="cents_paid" value="59,47" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="text" name="products_delivered" value="12000" id="id_products_delivered" /></li>'
     621                u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input name="cents_paid" value="59,47" step="0.01" maxlength="5" type="number" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="number" name="products_delivered" value="12000" id="id_products_delivered" /></li>'
    622622            )
    623623            self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00')
    624624            self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added'])
    625625            with self.settings(USE_THOUSAND_SEPARATOR=True):
    626626                # Checking for the localized "products_delivered" field
    627                 self.assertTrue(u'<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul())
     627                self.assertTrue(u'<input type="number" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul())
    628628
    629629    def test_iter_format_modules(self):
    630630        """
Back to Top