diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-07-07 16:27:34 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-11 14:28:56 -0400 |
| commit | 988309a1aeb3726cfa94a8e77a3f7cf7680dde97 (patch) | |
| tree | 5887a7d47a09c25f4e9e94753c07b706914a52e0 /tests/model_formsets/tests.py | |
| parent | 2457c1866ef3586c56bd19aeaa554e78c1ed1875 (diff) | |
Added ModelFormSet test for validation of a nonexistent PK.
Diffstat (limited to 'tests/model_formsets/tests.py')
| -rw-r--r-- | tests/model_formsets/tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 3245bb3fd9..a34c60158b 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -1655,6 +1655,21 @@ class ModelFormsetTest(TestCase): # created. self.assertQuerysetEqual(Author.objects.all(), ['<Author: Charles>', '<Author: Walt>']) + def test_validation_with_nonexistent_id(self): + AuthorFormSet = modelformset_factory(Author, fields='__all__') + data = { + 'form-TOTAL_FORMS': '1', + 'form-INITIAL_FORMS': '1', + 'form-MAX_NUM_FORMS': '', + 'form-0-id': '12345', + 'form-0-name': 'Charles', + } + formset = AuthorFormSet(data) + self.assertEqual( + formset.errors, + [{'id': ['Select a valid choice. That choice is not one of the available choices.']}], + ) + class TestModelFormsetOverridesTroughFormMeta(TestCase): def test_modelformset_factory_widgets(self): |
