mirror of https://github.com/django/django.git
Added ModelFormSet test for validation of a nonexistent PK.
This commit is contained in:
parent
2457c1866e
commit
988309a1ae
|
@ -1655,6 +1655,21 @@ class ModelFormsetTest(TestCase):
|
||||||
# created.
|
# created.
|
||||||
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Charles>', '<Author: Walt>'])
|
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):
|
class TestModelFormsetOverridesTroughFormMeta(TestCase):
|
||||||
def test_modelformset_factory_widgets(self):
|
def test_modelformset_factory_widgets(self):
|
||||||
|
|
Loading…
Reference in New Issue