Question

I'm writing coverage test cases for my app views. I have used Createview and Updateview classes with modelform and also used get_success_url() for response redirect.

When I passed data for the form using self.client.post('/product/add/', data), the response was TemplateResponse and status_code was 200, but get_success_url() statements were not covered by the test case. So how can I fill and submit the form from TemplateResponse?

Was it helpful?

Solution

If the client is not redirecting to the success url, the data is probably invalid. You can access the form through the response's context, and check the errors:

print response.context['form'].errors
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top