diff options
| author | Jannis Leidel <jannis@leidel.info> | 2010-02-01 14:14:56 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2010-02-01 14:14:56 +0000 |
| commit | 9555f2be9dc7c5cc1aeb3f4a047550ccd9b0cb2c (patch) | |
| tree | 52de3832306a6f3689be00c9f2f8fa0b7b22b2b1 /tests/regressiontests | |
| parent | f70a0882a3d916cfd59c31d6a6f4316dce104466 (diff) | |
Fixed #12692 - Properly handle the extra clause of admin inline formsets. Also fixes #12703, second error.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12369 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/admin_views/tests.py | 32 | ||||
| -rw-r--r-- | tests/regressiontests/forms/formsets.py | 18 | ||||
| -rw-r--r-- | tests/regressiontests/generic_inline_admin/tests.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/inline_formsets/tests.py | 4 | ||||
| -rw-r--r-- | tests/regressiontests/model_formsets_regress/tests.py | 6 |
5 files changed, 56 insertions, 7 deletions
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 7fc52b3460..d52a57f9ee 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -87,6 +87,7 @@ class AdminViewBasicTest(TestCase): # inline data "article_set-TOTAL_FORMS": u"3", "article_set-INITIAL_FORMS": u"0", + "article_set-MAX_NUM_FORMS": u"0", } response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data) self.failUnlessEqual(response.status_code, 302) # redirect somewhere @@ -97,6 +98,7 @@ class AdminViewBasicTest(TestCase): # inline data "article_set-TOTAL_FORMS": u"6", "article_set-INITIAL_FORMS": u"3", + "article_set-MAX_NUM_FORMS": u"0", "article_set-0-id": u"1", # there is no title in database, give one here or formset will fail. "article_set-0-title": u"Norske bostaver æøå skaper problemer", @@ -864,6 +866,7 @@ class AdminViewUnicodeTest(TestCase): # inline data "chapter_set-TOTAL_FORMS": u"6", "chapter_set-INITIAL_FORMS": u"3", + "chapter_set-MAX_NUM_FORMS": u"0", "chapter_set-0-id": u"1", "chapter_set-0-title": u"Norske bostaver æøå skaper problemer", "chapter_set-0-content": u"<p>Svært frustrerende med UnicodeDecodeError</p>", @@ -926,14 +929,14 @@ class AdminViewListEditable(TestCase): def test_changelist_input_html(self): response = self.client.get('/test_admin/admin/admin_views/person/') # 2 inputs per object(the field and the hidden id field) = 6 - # 2 management hidden fields = 2 + # 3 management hidden fields = 3 # 4 action inputs (3 regular checkboxes, 1 checkbox to select all) # main form submit button = 1 # search field and search submit button = 2 # CSRF field = 1 # field to track 'select all' across paginated views = 1 - # 6 + 2 + 4 + 1 + 2 + 1 + 1 = 17 inputs - self.failUnlessEqual(response.content.count("<input"), 17) + # 6 + 3 + 4 + 1 + 2 + 1 + 1 = 18 inputs + self.failUnlessEqual(response.content.count("<input"), 18) # 1 select per object = 3 selects self.failUnlessEqual(response.content.count("<select"), 4) @@ -941,6 +944,7 @@ class AdminViewListEditable(TestCase): data = { "form-TOTAL_FORMS": "3", "form-INITIAL_FORMS": "3", + "form-MAX_NUM_FORMS": "0", "form-0-gender": "1", "form-0-id": "1", @@ -961,6 +965,7 @@ class AdminViewListEditable(TestCase): data = { "form-TOTAL_FORMS": "2", "form-INITIAL_FORMS": "2", + "form-MAX_NUM_FORMS": "0", "form-0-id": "1", "form-0-gender": "1", @@ -978,6 +983,7 @@ class AdminViewListEditable(TestCase): data = { "form-TOTAL_FORMS": "1", "form-INITIAL_FORMS": "1", + "form-MAX_NUM_FORMS": "0", "form-0-id": "1", "form-0-gender": "1" @@ -998,6 +1004,7 @@ class AdminViewListEditable(TestCase): data = { "form-TOTAL_FORMS": "4", "form-INITIAL_FORMS": "4", + "form-MAX_NUM_FORMS": "0", "form-0-order": "14", "form-0-id": "1", @@ -1069,9 +1076,11 @@ class AdminInheritedInlinesTest(TestCase): # inline data "accounts-TOTAL_FORMS": u"1", "accounts-INITIAL_FORMS": u"0", + "accounts-MAX_NUM_FORMS": u"0", "accounts-0-username": foo_user, "accounts-2-TOTAL_FORMS": u"1", "accounts-2-INITIAL_FORMS": u"0", + "accounts-2-MAX_NUM_FORMS": u"0", "accounts-2-0-username": bar_user, } @@ -1096,6 +1105,7 @@ class AdminInheritedInlinesTest(TestCase): "accounts-TOTAL_FORMS": "2", "accounts-INITIAL_FORMS": u"1", + "accounts-MAX_NUM_FORMS": u"0", "accounts-0-username": "%s-1" % foo_user, "accounts-0-account_ptr": "1", @@ -1103,6 +1113,7 @@ class AdminInheritedInlinesTest(TestCase): "accounts-2-TOTAL_FORMS": u"2", "accounts-2-INITIAL_FORMS": u"1", + "accounts-2-MAX_NUM_FORMS": u"0", "accounts-2-0-username": "%s-1" % bar_user, "accounts-2-0-account_ptr": "2", @@ -1348,6 +1359,7 @@ class AdminInlineFileUploadTest(TestCase): "name": u"Test Gallery", "pictures-TOTAL_FORMS": u"2", "pictures-INITIAL_FORMS": u"1", + "pictures-MAX_NUM_FORMS": u"0", "pictures-0-id": u"1", "pictures-0-gallery": u"1", "pictures-0-name": "Test Picture", @@ -1370,6 +1382,7 @@ class AdminInlineTests(TestCase): "widget_set-TOTAL_FORMS": "3", "widget_set-INITIAL_FORMS": u"0", + "widget_set-MAX_NUM_FORMS": u"0", "widget_set-0-id": "", "widget_set-0-owner": "1", "widget_set-0-name": "", @@ -1382,6 +1395,7 @@ class AdminInlineTests(TestCase): "doohickey_set-TOTAL_FORMS": "3", "doohickey_set-INITIAL_FORMS": u"0", + "doohickey_set-MAX_NUM_FORMS": u"0", "doohickey_set-0-owner": "1", "doohickey_set-0-code": "", "doohickey_set-0-name": "", @@ -1394,6 +1408,7 @@ class AdminInlineTests(TestCase): "grommet_set-TOTAL_FORMS": "3", "grommet_set-INITIAL_FORMS": u"0", + "grommet_set-MAX_NUM_FORMS": u"0", "grommet_set-0-code": "", "grommet_set-0-owner": "1", "grommet_set-0-name": "", @@ -1406,6 +1421,7 @@ class AdminInlineTests(TestCase): "whatsit_set-TOTAL_FORMS": "3", "whatsit_set-INITIAL_FORMS": u"0", + "whatsit_set-MAX_NUM_FORMS": u"0", "whatsit_set-0-owner": "1", "whatsit_set-0-index": "", "whatsit_set-0-name": "", @@ -1418,6 +1434,7 @@ class AdminInlineTests(TestCase): "fancydoodad_set-TOTAL_FORMS": "3", "fancydoodad_set-INITIAL_FORMS": u"0", + "fancydoodad_set-MAX_NUM_FORMS": u"0", "fancydoodad_set-0-doodad_ptr": "", "fancydoodad_set-0-owner": "1", "fancydoodad_set-0-name": "", @@ -1433,6 +1450,7 @@ class AdminInlineTests(TestCase): "category_set-TOTAL_FORMS": "3", "category_set-INITIAL_FORMS": "0", + "category_set-MAX_NUM_FORMS": "0", "category_set-0-order": "", "category_set-0-id": "", "category_set-0-collector": "1", @@ -1624,6 +1642,7 @@ class AdminInlineTests(TestCase): "category_set-TOTAL_FORMS": "7", "category_set-INITIAL_FORMS": "4", + "category_set-MAX_NUM_FORMS": "0", "category_set-0-order": "14", "category_set-0-id": "1", @@ -1750,9 +1769,9 @@ class ReadonlyTest(TestCase): response = self.client.get('/test_admin/admin/admin_views/post/add/') self.assertEqual(response.status_code, 200) self.assertNotContains(response, 'name="posted"') - # 3 fields + 2 submit buttons + 2 inline management form fields, + 2 - # hidden fields for inlines + 1 field for the inline - self.assertEqual(response.content.count("input"), 10) + # 3 fields + 2 submit buttons + 4 inline management form fields, + 2 + # hidden fields for inlines + 1 field for the inline + 2 empty form + self.assertEqual(response.content.count("input"), 14) self.assertContains(response, formats.localize(datetime.date.today())) self.assertContains(response, "<label>Awesomeness level:</label>") @@ -1773,6 +1792,7 @@ class ReadonlyTest(TestCase): "content": "This is an incredible development.", "link_set-TOTAL_FORMS": "1", "link_set-INITIAL_FORMS": "0", + "link_set-MAX_NUM_FORMS": "0", } response = self.client.post('/test_admin/admin/admin_views/post/add/', data) self.assertEqual(response.status_code, 302) diff --git a/tests/regressiontests/forms/formsets.py b/tests/regressiontests/forms/formsets.py index 7999710ec1..700ab7c358 100644 --- a/tests/regressiontests/forms/formsets.py +++ b/tests/regressiontests/forms/formsets.py @@ -20,7 +20,7 @@ but we'll look at how to do so later. >>> formset = ChoiceFormSet(auto_id=False, prefix='choices') >>> print formset -<input type="hidden" name="choices-TOTAL_FORMS" value="1" /><input type="hidden" name="choices-INITIAL_FORMS" value="0" /> +<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" /> <tr><th>Choice:</th><td><input type="text" name="choices-0-choice" /></td></tr> <tr><th>Votes:</th><td><input type="text" name="choices-0-votes" /></td></tr> @@ -34,6 +34,7 @@ the TOTAL_FORMS field appropriately. >>> data = { ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... } @@ -60,6 +61,7 @@ any of the forms. >>> data = { ... 'choices-TOTAL_FORMS': '1', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '', ... } @@ -90,6 +92,7 @@ Let's simulate what would happen if we submitted this form. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': '', @@ -111,6 +114,7 @@ handle that later. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': 'The Decemberists', @@ -130,6 +134,7 @@ handle that case later. >>> data = { ... 'choices-TOTAL_FORMS': '2', # the number of forms rendered ... 'choices-INITIAL_FORMS': '1', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': '', # deleted value ... 'choices-0-votes': '', # deleted value ... 'choices-1-choice': '', @@ -167,6 +172,7 @@ number of forms to be completed. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': '', ... 'choices-0-votes': '', ... 'choices-1-choice': '', @@ -187,6 +193,7 @@ We can just fill out one of the forms. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': '', @@ -207,6 +214,7 @@ And once again, if we try to partially complete a form, validation will fail. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-1-choice': 'The Decemberists', @@ -274,6 +282,7 @@ To delete something, we just need to set that form's special delete field to >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-DELETE': '', @@ -303,6 +312,7 @@ it's going to be deleted. >>> data = { ... 'check-TOTAL_FORMS': '3', # the number of forms rendered ... 'check-INITIAL_FORMS': '2', # the number of forms with initial data +... 'check-MAX_NUM_FORMS': '0', # max number of forms ... 'check-0-field': '200', ... 'check-0-DELETE': '', ... 'check-1-field': '50', @@ -351,6 +361,7 @@ something at the front of the list, you'd need to set it's order to 0. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '2', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -377,6 +388,7 @@ they will be sorted below everything else. >>> data = { ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -406,6 +418,7 @@ Ordering should work with blank fieldsets. >>> data = { ... 'choices-TOTAL_FORMS': '3', # the number of forms rendered ... 'choices-INITIAL_FORMS': '0', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... } >>> formset = ChoiceFormSet(data, auto_id=False, prefix='choices') @@ -450,6 +463,7 @@ Let's delete Fergie, and put The Decemberists ahead of Calexico. >>> data = { ... 'choices-TOTAL_FORMS': '4', # the number of forms rendered ... 'choices-INITIAL_FORMS': '3', # the number of forms with initial data +... 'choices-MAX_NUM_FORMS': '0', # max number of forms ... 'choices-0-choice': 'Calexico', ... 'choices-0-votes': '100', ... 'choices-0-ORDER': '1', @@ -508,6 +522,7 @@ We start out with a some duplicate data. >>> data = { ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data +... 'drinks-MAX_NUM_FORMS': '0', # max number of forms ... 'drinks-0-name': 'Gin and Tonic', ... 'drinks-1-name': 'Gin and Tonic', ... } @@ -529,6 +544,7 @@ Make sure we didn't break the valid case. >>> data = { ... 'drinks-TOTAL_FORMS': '2', # the number of forms rendered ... 'drinks-INITIAL_FORMS': '0', # the number of forms with initial data +... 'drinks-MAX_NUM_FORMS': '0', # max number of forms ... 'drinks-0-name': 'Gin and Tonic', ... 'drinks-1-name': 'Bloody Mary', ... } diff --git a/tests/regressiontests/generic_inline_admin/tests.py b/tests/regressiontests/generic_inline_admin/tests.py index 21704cd8de..6853a896a4 100644 --- a/tests/regressiontests/generic_inline_admin/tests.py +++ b/tests/regressiontests/generic_inline_admin/tests.py @@ -58,6 +58,7 @@ class GenericAdminViewTest(TestCase): # inline data "generic_inline_admin-media-content_type-object_id-TOTAL_FORMS": u"1", "generic_inline_admin-media-content_type-object_id-INITIAL_FORMS": u"0", + "generic_inline_admin-media-content_type-object_id-MAX_NUM_FORMS": u"0", } response = self.client.post('/generic_inline_admin/admin/generic_inline_admin/episode/add/', post_data) self.failUnlessEqual(response.status_code, 302) # redirect somewhere @@ -71,6 +72,7 @@ class GenericAdminViewTest(TestCase): # inline data "generic_inline_admin-media-content_type-object_id-TOTAL_FORMS": u"3", "generic_inline_admin-media-content_type-object_id-INITIAL_FORMS": u"2", + "generic_inline_admin-media-content_type-object_id-MAX_NUM_FORMS": u"0", "generic_inline_admin-media-content_type-object_id-0-id": u"%d" % self.mp3_media_pk, "generic_inline_admin-media-content_type-object_id-0-url": u"http://example.com/podcast.mp3", "generic_inline_admin-media-content_type-object_id-1-id": u"%d" % self.png_media_pk, @@ -192,6 +194,7 @@ class GenericInlineAdminWithUniqueTogetherTest(TestCase): # inline data "generic_inline_admin-phonenumber-content_type-object_id-TOTAL_FORMS": u"1", "generic_inline_admin-phonenumber-content_type-object_id-INITIAL_FORMS": u"0", + "generic_inline_admin-phonenumber-content_type-object_id-MAX_NUM_FORMS": u"0", "generic_inline_admin-phonenumber-content_type-object_id-0-id": "", "generic_inline_admin-phonenumber-content_type-object_id-0-phone_number": "555-555-5555", } diff --git a/tests/regressiontests/inline_formsets/tests.py b/tests/regressiontests/inline_formsets/tests.py index aef6b3f10a..83d2fba193 100644 --- a/tests/regressiontests/inline_formsets/tests.py +++ b/tests/regressiontests/inline_formsets/tests.py @@ -10,6 +10,7 @@ class DeletionTests(TestCase): data = { 'poem_set-TOTAL_FORMS': u'1', 'poem_set-INITIAL_FORMS': u'1', + 'poem_set-MAX_NUM_FORMS': u'0', 'poem_set-0-id': str(poem.pk), 'poem_set-0-poet': str(poet.pk), 'poem_set-0-name': u'test', @@ -30,6 +31,7 @@ class DeletionTests(TestCase): data = { 'poem_set-TOTAL_FORMS': u'1', 'poem_set-INITIAL_FORMS': u'0', + 'poem_set-MAX_NUM_FORMS': u'0', 'poem_set-0-id': u'', 'poem_set-0-poem': u'1', 'poem_set-0-name': u'x' * 1000, @@ -58,6 +60,7 @@ class DeletionTests(TestCase): data = { 'poem_set-TOTAL_FORMS': u'1', 'poem_set-INITIAL_FORMS': u'1', + 'poem_set-MAX_NUM_FORMS': u'0', 'poem_set-0-id': u'1', 'poem_set-0-poem': u'1', 'poem_set-0-name': u'x' * 1000, @@ -88,6 +91,7 @@ class DeletionTests(TestCase): data = { 'child_set-TOTAL_FORMS': u'1', 'child_set-INITIAL_FORMS': u'0', + 'child_set-MAX_NUM_FORMS': u'0', 'child_set-0-name': u'child', } formset = ChildFormSet(data, instance=school) diff --git a/tests/regressiontests/model_formsets_regress/tests.py b/tests/regressiontests/model_formsets_regress/tests.py index 4dba9fc19f..61bc514324 100644 --- a/tests/regressiontests/model_formsets_regress/tests.py +++ b/tests/regressiontests/model_formsets_regress/tests.py @@ -20,6 +20,7 @@ class InlineFormsetTests(TestCase): 'username': u'apollo13', 'usersite_set-TOTAL_FORMS': u'1', 'usersite_set-INITIAL_FORMS': u'0', + 'usersite_set-MAX_NUM_FORMS': u'0', 'usersite_set-0-data': u'10', 'usersite_set-0-user': u'apollo13' } @@ -43,6 +44,7 @@ class InlineFormsetTests(TestCase): data = { 'usersite_set-TOTAL_FORMS': u'1', 'usersite_set-INITIAL_FORMS': u'1', + 'usersite_set-MAX_NUM_FORMS': u'0', 'usersite_set-0-id': unicode(usersite[0]['id']), 'usersite_set-0-data': u'11', 'usersite_set-0-user': u'apollo13' @@ -60,6 +62,7 @@ class InlineFormsetTests(TestCase): data = { 'usersite_set-TOTAL_FORMS': u'2', 'usersite_set-INITIAL_FORMS': u'1', + 'usersite_set-MAX_NUM_FORMS': u'0', 'usersite_set-0-id': unicode(usersite[0]['id']), 'usersite_set-0-data': u'11', 'usersite_set-0-user': u'apollo13', @@ -92,6 +95,7 @@ class InlineFormsetTests(TestCase): 'name': u"Guido's House of Pasta", 'manager_set-TOTAL_FORMS': u'1', 'manager_set-INITIAL_FORMS': u'0', + 'manager_set-MAX_NUM_FORMS': u'0', 'manager_set-0-name': u'Guido Van Rossum' } restaurant = User() @@ -113,6 +117,7 @@ class InlineFormsetTests(TestCase): data = { 'manager_set-TOTAL_FORMS': u'1', 'manager_set-INITIAL_FORMS': u'1', + 'manager_set-MAX_NUM_FORMS': u'0', 'manager_set-0-id': unicode(manager[0]['id']), 'manager_set-0-name': u'Terry Gilliam' } @@ -128,6 +133,7 @@ class InlineFormsetTests(TestCase): data = { 'manager_set-TOTAL_FORMS': u'2', 'manager_set-INITIAL_FORMS': u'1', + 'manager_set-MAX_NUM_FORMS': u'0', 'manager_set-0-id': unicode(manager[0]['id']), 'manager_set-0-name': u'Terry Gilliam', 'manager_set-1-name': u'John Cleese' |
