Ok, so I need a unit test view, a more accurate form in the view. Therefore, I create such a unit test.
class ViewTest(TestCase): fixtures = ['fixture.json'] def setUp(self): self.client = Client() def test_company_create(self): post_data = { 'form-0-user': '', 'form-0-share': '', 'form-TOTAL_FORMS': 1, 'form-INITIAL_FORMS': 0, 'form-MAX_NUM_FORMS': 10 } resp = self.client.post('/company/create/', post_data) self.assertFormError (resp, 'shareholder_formset', 'share', 'This field is required.') self.assertFormError (resp, 'shareholder_formset', 'user', 'This field is required.')
Of course, I will return to the error
AttributeError: The "ShareholderFormFormSet" object does not have a 'field' attribute
Since formet has forms in it, not fields ..... So, what is the correct way to test a set of forms?
source share