diff options
Diffstat (limited to 'tests/modeltests/model_formsets')
| -rw-r--r-- | tests/modeltests/model_formsets/models.py | 43 | ||||
| -rw-r--r-- | tests/modeltests/model_formsets/tests.py | 3 |
2 files changed, 44 insertions, 2 deletions
diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py index 702523eb7c..e8c3e98ac7 100644 --- a/tests/modeltests/model_formsets/models.py +++ b/tests/modeltests/model_formsets/models.py @@ -200,6 +200,7 @@ __test__ = {'API_TESTS': """ >>> data = { ... 'form-TOTAL_FORMS': '3', # the number of forms rendered ... 'form-INITIAL_FORMS': '0', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-name': 'Charles Baudelaire', ... 'form-1-name': 'Arthur Rimbaud', ... 'form-2-name': '', @@ -237,6 +238,7 @@ them in alphabetical order by name. >>> data = { ... 'form-TOTAL_FORMS': '3', # the number of forms rendered ... 'form-INITIAL_FORMS': '2', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-id': '2', ... 'form-0-name': 'Arthur Rimbaud', ... 'form-1-id': '1', @@ -280,6 +282,7 @@ deltetion, make sure we don't save that form. >>> data = { ... 'form-TOTAL_FORMS': '4', # the number of forms rendered ... 'form-INITIAL_FORMS': '3', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-id': '2', ... 'form-0-name': 'Arthur Rimbaud', ... 'form-1-id': '1', @@ -309,6 +312,7 @@ Let's edit a record to ensure save only returns that one record. >>> data = { ... 'form-TOTAL_FORMS': '4', # the number of forms rendered ... 'form-INITIAL_FORMS': '3', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-id': '2', ... 'form-0-name': 'Walt Whitman', ... 'form-1-id': '1', @@ -339,6 +343,7 @@ Test the behavior of commit=False and save_m2m >>> data = { ... 'form-TOTAL_FORMS': '2', # the number of forms rendered ... 'form-INITIAL_FORMS': '1', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-id': '1', ... 'form-0-name': '2nd Tuesday of the Week Meeting', ... 'form-0-authors': [2, 1, 3, 4], @@ -393,6 +398,7 @@ used. >>> data = { ... 'form-TOTAL_FORMS': '3', # the number of forms rendered ... 'form-INITIAL_FORMS': '0', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-name': 'Walt Whitman', ... 'form-1-name': 'Charles Baudelaire', ... 'form-2-name': '', @@ -419,6 +425,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': '1', # the number of forms rendered ... 'form-INITIAL_FORMS': '0', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-author_ptr': '', ... 'form-0-name': 'Ernest Hemingway', ... 'form-0-write_speed': '10', @@ -442,6 +449,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': '2', # the number of forms rendered ... 'form-INITIAL_FORMS': '1', # the number of forms with initial data +... 'form-MAX_NUM_FORMS': '0', # the max number of forms ... 'form-0-author_ptr': hemingway_id, ... 'form-0-name': 'Ernest Hemingway', ... 'form-0-write_speed': '10', @@ -476,6 +484,7 @@ admin system's edit inline functionality works. >>> data = { ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered ... 'book_set-INITIAL_FORMS': '0', # the number of forms with initial data +... 'book_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'book_set-0-title': 'Les Fleurs du Mal', ... 'book_set-1-title': '', ... 'book_set-2-title': '', @@ -510,6 +519,7 @@ book. >>> data = { ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered ... 'book_set-INITIAL_FORMS': '1', # the number of forms with initial data +... 'book_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'book_set-0-id': '1', ... 'book_set-0-title': 'Les Fleurs du Mal', ... 'book_set-1-title': 'Les Paradis Artificiels', @@ -536,6 +546,7 @@ This is used in the admin for save_as functionality. >>> data = { ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered ... 'book_set-INITIAL_FORMS': '2', # the number of forms with initial data +... 'book_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'book_set-0-id': '1', ... 'book_set-0-title': 'Les Fleurs du Mal', ... 'book_set-1-id': '2', @@ -573,6 +584,7 @@ Test inline formsets where the inline-edited object has a custom primary key tha >>> data = { ... 'bookwithcustompk_set-TOTAL_FORMS': '1', # the number of forms rendered ... 'bookwithcustompk_set-INITIAL_FORMS': '0', # the number of forms with initial data +... 'bookwithcustompk_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'bookwithcustompk_set-0-my_pk': '77777', ... 'bookwithcustompk_set-0-title': 'Les Fleurs du Mal', ... } @@ -603,6 +615,7 @@ has a non AutoField yet auto-created primary key. >>> data = { ... 'alternatebook_set-TOTAL_FORMS': '1', # the number of forms rendered ... 'alternatebook_set-INITIAL_FORMS': '0', # the number of forms with initial data +... 'alternatebook_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'alternatebook_set-0-title': 'Flowers of Evil', ... 'alternatebook_set-0-notes': 'English translation of Les Fleurs du Mal' ... } @@ -631,6 +644,7 @@ True >>> data = { ... 'poem_set-TOTAL_FORMS': '3', # the number of forms rendered ... 'poem_set-INITIAL_FORMS': '0', # the number of forms with initial data +... 'poem_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'poem_set-0-name': 'The Cloud in Trousers', ... 'poem_set-1-name': 'I', ... 'poem_set-2-name': '', @@ -659,6 +673,7 @@ We can provide a custom queryset to our InlineFormSet: >>> data = { ... 'book_set-TOTAL_FORMS': '5', # the number of forms rendered ... 'book_set-INITIAL_FORMS': '3', # the number of forms with initial data +... 'book_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'book_set-0-id': '1', ... 'book_set-0-title': 'Les Fleurs du Mal', ... 'book_set-1-id': '2', @@ -682,6 +697,7 @@ True >>> data = { ... 'book_set-TOTAL_FORMS': '3', # the number of forms rendered ... 'book_set-INITIAL_FORMS': '1', # the number of forms with initial data +... 'book_set-MAX_NUM_FORMS': '0', # the max number of forms ... 'book_set-0-id': '5', ... 'book_set-0-title': 'Flowers of Evil', ... 'book_set-1-title': 'Revue des deux mondes', @@ -718,6 +734,7 @@ We need to ensure that it is displayed >>> data = { ... 'owner_set-TOTAL_FORMS': '2', ... 'owner_set-INITIAL_FORMS': '0', +... 'owner_set-MAX_NUM_FORMS': '0', ... 'owner_set-0-auto_id': '', ... 'owner_set-0-name': u'Joe Perry', ... 'owner_set-1-auto_id': '', @@ -739,6 +756,7 @@ True >>> data = { ... 'owner_set-TOTAL_FORMS': '3', ... 'owner_set-INITIAL_FORMS': '1', +... 'owner_set-MAX_NUM_FORMS': '0', ... 'owner_set-0-auto_id': u'1', ... 'owner_set-0-name': u'Joe Perry', ... 'owner_set-1-auto_id': '', @@ -767,7 +785,8 @@ True >>> owner = Owner.objects.get(name=u'Joe Perry') >>> FormSet = inlineformset_factory(Owner, OwnerProfile, max_num=1, can_delete=False) - +>>> FormSet.max_num +1 >>> formset = FormSet(instance=owner) >>> for form in formset.forms: ... print form.as_p() @@ -776,6 +795,7 @@ True >>> data = { ... 'ownerprofile-TOTAL_FORMS': '1', ... 'ownerprofile-INITIAL_FORMS': '0', +... 'ownerprofile-MAX_NUM_FORMS': '1', ... 'ownerprofile-0-owner': '', ... 'ownerprofile-0-age': u'54', ... } @@ -784,7 +804,6 @@ True True >>> formset.save() [<OwnerProfile: Joe Perry is 54>] - >>> formset = FormSet(instance=owner) >>> for form in formset.forms: ... print form.as_p() @@ -793,6 +812,7 @@ True >>> data = { ... 'ownerprofile-TOTAL_FORMS': '1', ... 'ownerprofile-INITIAL_FORMS': '1', +... 'ownerprofile-MAX_NUM_FORMS': '1', ... 'ownerprofile-0-owner': u'1', ... 'ownerprofile-0-age': u'55', ... } @@ -805,6 +825,8 @@ True # ForeignKey with unique=True should enforce max_num=1 >>> FormSet = inlineformset_factory(Place, Location, can_delete=False) +>>> FormSet.max_num +1 >>> formset = FormSet(instance=place) >>> for form in formset.forms: ... print form.as_p() @@ -826,6 +848,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': '1', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-slug': 'car-red', ... } >>> formset = FormSet(data) @@ -837,6 +860,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': '1', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-slug': 'car-red', ... } >>> formset = FormSet(data) @@ -851,6 +875,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': '1', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-price': u'12.00', ... 'form-0-quantity': '1', ... } @@ -863,6 +888,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': '1', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-price': u'12.00', ... 'form-0-quantity': '1', ... } @@ -880,6 +906,7 @@ False >>> data = { ... 'revision_set-TOTAL_FORMS': '1', ... 'revision_set-INITIAL_FORMS': '0', +... 'revision_set-MAX_NUM_FORMS': '0', ... 'revision_set-0-repository': repository.pk, ... 'revision_set-0-revision': '146239817507f148d448db38840db7c3cbf47c76', ... 'revision_set-0-DELETE': '', @@ -894,6 +921,7 @@ True >>> data = { ... 'revision_set-TOTAL_FORMS': '1', ... 'revision_set-INITIAL_FORMS': '0', +... 'revision_set-MAX_NUM_FORMS': '0', ... 'revision_set-0-repository': repository.pk, ... 'revision_set-0-revision': '146239817507f148d448db38840db7c3cbf47c76', ... 'revision_set-0-DELETE': '', @@ -911,6 +939,7 @@ False >>> data = { ... 'revision_set-TOTAL_FORMS': '1', ... 'revision_set-INITIAL_FORMS': '0', +... 'revision_set-MAX_NUM_FORMS': '0', ... 'revision_set-0-repository': repository.pk, ... 'revision_set-0-revision': '146239817507f148d448db38840db7c3cbf47c76', ... 'revision_set-0-DELETE': '', @@ -940,6 +969,7 @@ False >>> data = { ... 'membership_set-TOTAL_FORMS': '1', ... 'membership_set-INITIAL_FORMS': '0', +... 'membership_set-MAX_NUM_FORMS': '0', ... 'membership_set-0-date_joined': unicode(now.strftime('%Y-%m-%d %H:%M:%S')), ... 'initial-membership_set-0-date_joined': unicode(now.strftime('%Y-%m-%d %H:%M:%S')), ... 'membership_set-0-karma': '', @@ -954,6 +984,7 @@ True >>> filled_data = { ... 'membership_set-TOTAL_FORMS': '1', ... 'membership_set-INITIAL_FORMS': '0', +... 'membership_set-MAX_NUM_FORMS': '0', ... 'membership_set-0-date_joined': unicode(one_day_later.strftime('%Y-%m-%d %H:%M:%S')), ... 'initial-membership_set-0-date_joined': unicode(now.strftime('%Y-%m-%d %H:%M:%S')), ... 'membership_set-0-karma': '', @@ -976,6 +1007,7 @@ False >>> data = { ... 'membership_set-TOTAL_FORMS': '1', ... 'membership_set-INITIAL_FORMS': '0', +... 'membership_set-MAX_NUM_FORMS': '0', ... 'membership_set-0-date_joined_0': unicode(now.strftime('%Y-%m-%d')), ... 'membership_set-0-date_joined_1': unicode(now.strftime('%H:%M:%S')), ... 'initial-membership_set-0-date_joined': unicode(now.strftime('%Y-%m-%d %H:%M:%S')), @@ -1011,6 +1043,7 @@ True >>> data = { ... 'form-TOTAL_FORMS': 2, ... 'form-INITIAL_FORMS': 0, +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-slug': 'red_car', ... 'form-1-slug': 'red_car', ... } @@ -1024,6 +1057,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': 2, ... 'form-INITIAL_FORMS': 0, +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-price': '25', ... 'form-0-quantity': '7', ... 'form-1-price': '25', @@ -1041,6 +1075,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': '2', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... 'form-0-price': '24', ... 'form-1-price': '24', ... } @@ -1054,6 +1089,7 @@ True >>> data = { ... 'book_set-TOTAL_FORMS': '2', ... 'book_set-INITIAL_FORMS': '2', +... 'book_set-MAX_NUM_FORMS': '0', ... ... 'book_set-0-title': 'The 2008 Election', ... 'book_set-0-author': str(author.id), @@ -1075,6 +1111,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': '2', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... ... 'form-0-title': 'blah', ... 'form-0-slug': 'Morning', @@ -1096,6 +1133,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': '2', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... ... 'form-0-title': 'foo', ... 'form-0-slug': 'Morning in Prague', @@ -1115,6 +1153,7 @@ False >>> data = { ... 'form-TOTAL_FORMS': '2', ... 'form-INITIAL_FORMS': '0', +... 'form-MAX_NUM_FORMS': '0', ... ... 'form-0-title': 'foo', ... 'form-0-slug': 'Morning in Prague', diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py index d343fc7296..62489bad37 100644 --- a/tests/modeltests/model_formsets/tests.py +++ b/tests/modeltests/model_formsets/tests.py @@ -9,6 +9,7 @@ class DeletionTests(TestCase): data = { 'form-TOTAL_FORMS': u'1', 'form-INITIAL_FORMS': u'1', + 'form-MAX_NUM_FORMS': u'0', 'form-0-id': str(poet.pk), 'form-0-name': u'test', 'form-0-DELETE': u'on', @@ -27,6 +28,7 @@ class DeletionTests(TestCase): data = { 'form-TOTAL_FORMS': u'1', 'form-INITIAL_FORMS': u'0', + 'form-MAX_NUM_FORMS': u'0', 'form-0-id': u'', 'form-0-name': u'x' * 1000, } @@ -53,6 +55,7 @@ class DeletionTests(TestCase): data = { 'form-TOTAL_FORMS': u'1', 'form-INITIAL_FORMS': u'1', + 'form-MAX_NUM_FORMS': u'0', 'form-0-id': u'1', 'form-0-name': u'x' * 1000, } |
