Ok, so i need to unit test a view, more precise form in a view . So 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.')
Ofcourse i get back an error
AttributeError: 'ShareholderFormFormSet' object has no attribute 'fields'
Because formset has forms in it, not fields..... So what is the correct way to test a formset?
ShareholderForm
? It looks like that is what you are trying to do with your asserts anyways... – Actinochemistry