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

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

against [17821]

  • tests/modeltests/generic_relations/tests.py

    commit 55387a8e264717300ac8e704c8384a565358b5ae
    Author: Jonas Haag <jonas@lophus.org>
    Date:   Sun Aug 14 20:17:36 2011 +0200
    
        t tests
    
    diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py
    index adfba82..f3831ee 100644
    a b class GenericRelationsTests(TestCase):  
    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 2be3a0d..892e301 100644
    a b class ModelFormsetTest(TestCase):  
    383383        self.assertEqual(len(formset.forms), 1)
    384384        self.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(formset.forms[0].as_p(),
    552             '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input type="text" name="bookwithcustompk_set-0-my_pk" id="id_bookwithcustompk_set-0-my_pk" /></p>\n'
     552            '<p><label for="id_bookwithcustompk_set-0-my_pk">My pk:</label> <input id="id_bookwithcustompk_set-0-my_pk" type="number" name="bookwithcustompk_set-0-my_pk" maxlength="6" /></p>\n'
    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.assertEqual(formset.forms[0].as_p(),
    810             '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
     810            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
    811811            % owner1.auto_id)
    812812
    813813        data = {
    class ModelFormsetTest(TestCase):  
    828828        formset = FormSet(instance=owner1)
    829829        self.assertEqual(len(formset.forms), 1)
    830830        self.assertEqual(formset.forms[0].as_p(),
    831             '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="text" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
     831            '<p><label for="id_ownerprofile-0-age">Age:</label> <input type="number" name="ownerprofile-0-age" value="54" id="id_ownerprofile-0-age" /><input type="hidden" name="ownerprofile-0-owner" value="%d" id="id_ownerprofile-0-owner" /></p>'
    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.assertEqual(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 cbec105..27f08a3 100644
    a b class FormsExtraTestCase(unittest.TestCase, AssertFormErrorsMixin):  
    597597        f = CommentForm(data, auto_id=False, error_class=DivErrorList)
    598598        self.assertEqual(f.as_p(), """<p>Name: <input type="text" name="name" maxlength="50" /></p>
    599599<div class="errorlist"><div class="error">Enter a valid e-mail address.</div></div>
    600 <p>Email: <input type="text" name="email" value="invalid" /></p>
     600<p>Email: <input type="email" name="email" value="invalid" /></p>
    601601<div class="errorlist"><div class="error">This field is required.</div></div>
    602602<p>Comment: <input type="text" name="comment" /></p>""")
    603603
  • tests/regressiontests/forms/tests/fields.py

    diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
    index 7dd3a27..68908c6 100644
    a b def verify_exists_urls(existing_urls=()):  
    7575
    7676
    7777class FieldsTests(SimpleTestCase):
    78 
    7978    def setUp(self):
    8079        self.save_warnings_state()
    8180        warnings.filterwarnings('ignore', category=DeprecationWarning,
    class FieldsTests(SimpleTestCase):  
    8483    def tearDown(self):
    8584        self.restore_warnings_state()
    8685
     86    def assertWidgetRendersTo(self, field, to):
     87        class _Form(Form):
     88            f = field
     89        self.assertEqual(str(_Form()['f']), to)
     90
    8791    def test_field_sets_widget_is_required(self):
    8892        self.assertTrue(Field(required=True).widget.is_required)
    8993        self.assertFalse(Field(required=False).widget.is_required)
    class FieldsTests(SimpleTestCase):  
    157161
    158162    def test_integerfield_1(self):
    159163        f = IntegerField()
     164        self.assertWidgetRendersTo(f, '<input type="number" name="f" id="id_f" />')
    160165        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    161166        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    162167        self.assertEqual(1, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    191196
    192197    def test_integerfield_3(self):
    193198        f = IntegerField(max_value=10)
     199        self.assertWidgetRendersTo(f, '<input max="10" type="number" name="f" id="id_f" />')
    194200        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    195201        self.assertEqual(1, f.clean(1))
    196202        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    202208
    203209    def test_integerfield_4(self):
    204210        f = IntegerField(min_value=10)
     211        self.assertWidgetRendersTo(f, '<input id="id_f" type="number" name="f" min="10" />')
    205212        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    206213        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    207214        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    213220
    214221    def test_integerfield_5(self):
    215222        f = IntegerField(min_value=10, max_value=20)
     223        self.assertWidgetRendersTo(f, '<input id="id_f" max="20" type="number" name="f" min="10" />')
    216224        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    217225        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 10.']", f.clean, 1)
    218226        self.assertEqual(10, f.clean(10))
    class FieldsTests(SimpleTestCase):  
    228236
    229237    def test_floatfield_1(self):
    230238        f = FloatField()
     239        self.assertWidgetRendersTo(f, '<input step="any" type="number" name="f" id="id_f" />')
    231240        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    232241        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    233242        self.assertEqual(1.0, f.clean('1'))
    class FieldsTests(SimpleTestCase):  
    254263
    255264    def test_floatfield_3(self):
    256265        f = FloatField(max_value=1.5, min_value=0.5)
     266        self.assertWidgetRendersTo(f, '<input step="any" name="f" min="0.5" max="1.5" type="number" id="id_f" />')
    257267        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    258268        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    259269        self.assertEqual(1.5, f.clean('1.5'))
    class FieldsTests(SimpleTestCase):  
    265275
    266276    def test_decimalfield_1(self):
    267277        f = DecimalField(max_digits=4, decimal_places=2)
     278        self.assertWidgetRendersTo(f, '<input id="id_f" step="0.01" type="number" name="f" maxlength="5" />')
    268279        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    269280        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    270281        self.assertEqual(f.clean('1'), Decimal("1"))
    class FieldsTests(SimpleTestCase):  
    310321
    311322    def test_decimalfield_3(self):
    312323        f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5'))
     324        self.assertWidgetRendersTo(f, '<input step="0.01" name="f" min="0.5" max="1.5" maxlength="5" type="number" id="id_f" />')
    313325        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is less than or equal to 1.5.']", f.clean, '1.6')
    314326        self.assertRaisesMessage(ValidationError, "[u'Ensure this value is greater than or equal to 0.5.']", f.clean, '0.4')
    315327        self.assertEqual(f.clean('1.5'), Decimal("1.5"))
    class FieldsTests(SimpleTestCase):  
    524536
    525537    def test_emailfield_1(self):
    526538        f = EmailField()
     539        self.assertWidgetRendersTo(f, '<input type="email" name="f" id="id_f" />')
    527540        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    528541        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    529542        self.assertEqual(u'person@example.com', f.clean('person@example.com'))
    class FieldsTests(SimpleTestCase):  
    562575
    563576    def test_emailfield_3(self):
    564577        f = EmailField(min_length=10, max_length=15)
     578        self.assertWidgetRendersTo(f, '<input id="id_f" type="email" name="f" maxlength="15" />')
    565579        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 10 characters (it has 9).']", f.clean, 'a@foo.com')
    566580        self.assertEqual(u'alf@foo.com', f.clean('alf@foo.com'))
    567581        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at most 15 characters (it has 20).']", f.clean, 'alf123456788@foo.com')
    class FieldsTests(SimpleTestCase):  
    602616
    603617    def test_urlfield_1(self):
    604618        f = URLField()
     619        self.assertWidgetRendersTo(f, '<input type="url" name="f" id="id_f" />')
    605620        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, '')
    606621        self.assertRaisesMessage(ValidationError, "[u'This field is required.']", f.clean, None)
    607622        self.assertEqual(u'http://localhost/', f.clean('http://localhost'))
    class FieldsTests(SimpleTestCase):  
    676691
    677692    def test_urlfield_5(self):
    678693        f = URLField(min_length=15, max_length=20)
     694        self.assertWidgetRendersTo(f, '<input id="id_f" type="url" name="f" maxlength="20" />')
    679695        self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com')
    680696        self.assertEqual(u'http://example.com/', f.clean('http://example.com'))
    681697        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 4e9cc16..f98d50b 100644
    a b class FormsTestCase(TestCase):  
    253253            get_spam = BooleanField()
    254254
    255255        f = SignupForm(auto_id=False)
    256         self.assertEqual(str(f['email']), '<input type="text" name="email" />')
     256        self.assertEqual(str(f['email']), '<input type="email" name="email" />')
    257257        self.assertEqual(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.assertEqual(str(f['email']), '<input type="text" name="email" value="test@example.com" />')
     260        self.assertEqual(str(f['email']), '<input type="email" name="email" value="test@example.com" />')
    261261        self.assertEqual(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):  
    17461746<option value="2">Yes</option>
    17471747<option value="3">No</option>
    17481748</select></li>
    1749 <li><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></li>
    1750 <li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></li>""")
     1749<li><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></li>
     1750<li class="required error"><ul class="errorlist"><li>This field is required.</li></ul><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></li>""")
    17511751
    17521752        self.assertEqual(p.as_p(), """<ul class="errorlist"><li>This field is required.</li></ul>
    17531753<p class="required error"><label for="id_name">Name:</label> <input type="text" name="name" id="id_name" /></p>
    class FormsTestCase(TestCase):  
    17561756<option value="2">Yes</option>
    17571757<option value="3">No</option>
    17581758</select></p>
    1759 <p><label for="id_email">Email:</label> <input type="text" name="email" id="id_email" /></p>
     1759<p><label for="id_email">Email:</label> <input type="email" name="email" id="id_email" /></p>
    17601760<ul class="errorlist"><li>This field is required.</li></ul>
    1761 <p class="required error"><label for="id_age">Age:</label> <input type="text" name="age" id="id_age" /></p>""")
     1761<p class="required error"><label for="id_age">Age:</label> <input type="number" name="age" id="id_age" /></p>""")
    17621762
    17631763        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>
    17641764<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):  
    17661766<option value="2">Yes</option>
    17671767<option value="3">No</option>
    17681768</select></td></tr>
    1769 <tr><th><label for="id_email">Email:</label></th><td><input type="text" name="email" id="id_email" /></td></tr>
    1770 <tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="age" id="id_age" /></td></tr>""")
     1769<tr><th><label for="id_email">Email:</label></th><td><input type="email" name="email" id="id_email" /></td></tr>
     1770<tr class="required error"><th><label for="id_age">Age:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="number" name="age" id="id_age" /></td></tr>""")
    17711771
    17721772    def test_label_split_datetime_not_displayed(self):
    17731773        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 f218053..909b8ae 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):  
    133133            form_output.append(form.as_ul())
    134134
    135135        self.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    136 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     136<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    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.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" /></li>
    209 <li>Votes: <input type="text" name="choices-0-votes" /></li>
     209<li>Votes: <input type="number" name="choices-0-votes" /></li>
    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.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    300 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     300<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    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.assertEqual(formset.empty_form.as_ul(), """<li>Choice: <input type="text" name="choices-__prefix__-choice" /></li>
    312 <li>Votes: <input type="text" name="choices-__prefix__-votes" /></li>""")
     312<li>Votes: <input type="number" name="choices-__prefix__-votes" /></li>""")
    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.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    330 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
     330<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
    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.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    427 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
    428 <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li>
     427<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
     428<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li>
    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.assertEqual('\n'.join(form_output), """<li>Choice: <input type="text" name="choices-0-choice" value="Calexico" /></li>
    538 <li>Votes: <input type="text" name="choices-0-votes" value="100" /></li>
    539 <li>Order: <input type="text" name="choices-0-ORDER" value="1" /></li>
     538<li>Votes: <input type="number" name="choices-0-votes" value="100" /></li>
     539<li>Order: <input type="number" name="choices-0-ORDER" value="1" /></li>
    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.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" />
    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.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" />
    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.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" />
    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/generic_inline_admin/tests.py

    diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py
    index 2c82acf..a576c4a 100644
    a b class GenericAdminViewTest(TestCase):  
    101101        # Works with no queryset
    102102        formset = EpisodeMediaFormSet(instance=e)
    103103        self.assertEqual(len(formset.forms), 5)
    104         self.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk)
    105         self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk)
    106         self.assertEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
     104        self.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.mp3_media_pk)
     105        self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.png_media_pk)
     106        self.assertEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
    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.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
    112         self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk)
    113         self.assertEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="text" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
     111        self.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
     112        self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" value="http://example.com/podcast.mp3" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>' % self.mp3_media_pk)
     113        self.assertEqual(formset.forms[2].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-2-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-2-url" type="url" name="generic_inline_admin-media-content_type-object_id-2-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-2-id" id="id_generic_inline_admin-media-content_type-object_id-2-id" /></p>')
    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.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="text" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
    119         self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="text" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>')
     118        self.assertEqual(formset.forms[0].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-0-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-0-url" type="url" name="generic_inline_admin-media-content_type-object_id-0-url" value="http://example.com/logo.png" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-0-id" value="%s" id="id_generic_inline_admin-media-content_type-object_id-0-id" /></p>' % self.png_media_pk)
     119        self.assertEqual(formset.forms[1].as_p(), '<p><label for="id_generic_inline_admin-media-content_type-object_id-1-url">Url:</label> <input id="id_generic_inline_admin-media-content_type-object_id-1-url" type="url" name="generic_inline_admin-media-content_type-object_id-1-url" maxlength="200" /><input type="hidden" name="generic_inline_admin-media-content_type-object_id-1-id" id="id_generic_inline_admin-media-content_type-object_id-1-id" /></p>')
    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 0a2852e..02ad1b0 100644
    a b class FormattingTests(TestCase):  
    619619            self.assertEqual(True, form6.is_valid())
    620620            self.assertEqual(
    621621                form6.as_ul(),
    622                 u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input type="text" name="cents_paid" value="59,47" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="text" name="products_delivered" value="12000" id="id_products_delivered" /></li>'
     622                u'<li><label for="id_name">Name:</label> <input id="id_name" type="text" name="name" value="acme" maxlength="50" /></li>\n<li><label for="id_date_added">Date added:</label> <input type="text" name="date_added" value="31.12.2009 06:00:00" id="id_date_added" /></li>\n<li><label for="id_cents_paid">Cents paid:</label> <input name="cents_paid" value="59,47" step="0.01" maxlength="5" type="number" id="id_cents_paid" /></li>\n<li><label for="id_products_delivered">Products delivered:</label> <input type="number" name="products_delivered" value="12000" id="id_products_delivered" /></li>'
    623623            )
    624624            self.assertEqual(localize_input(datetime.datetime(2009, 12, 31, 6, 0, 0)), '31.12.2009 06:00:00')
    625625            self.assertEqual(datetime.datetime(2009, 12, 31, 6, 0, 0), form6.cleaned_data['date_added'])
    626626            with self.settings(USE_THOUSAND_SEPARATOR=True):
    627627                # Checking for the localized "products_delivered" field
    628                 self.assertTrue(u'<input type="text" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul())
     628                self.assertTrue(u'<input type="number" name="products_delivered" value="12.000" id="id_products_delivered" />' in form6.as_ul())
    629629
    630630    def test_iter_format_modules(self):
    631631        """
Back to Top