How do you unit test formsets in Django? -


ok, need unit test view, more precise form in view . create such 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 required.')     self.assertformerror (resp, 'shareholder_formset', 'user', 'this field required.') 

ofcourse error

attributeerror: 'shareholderformformset' object has no attribute 'fields'

because formset has forms in it, not fields..... correct way test formset?

that's functional test (since go through view, request possibly model if save it, etc.).

for forms, django-webtest lot easier use; won't have worry these details it: https://pypi.python.org/pypi/django-webtest


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -