Frage

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?

War es hilfreich?

Lösung

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top