There are situations when testing POST requests with the TestCase client where I pass (by mistake) the wrong fields in the data dictionary. In these cases, the validation fails and the route does not redirect as expected. Example:
def test_admin_can_create_new_quotation(self):
data = {
"client": "wrong object type"
}
response = self.client.post(reverse("quote-create"), data=data)
self.assertRedirects(response, "/quotes/1/") # Fails, status code 200
In these cases it would be helpful to see why the request failed, and I wrote for myself a tiny function, assertNotFormError, which takes the response, the form, and checks if the form has errors.
Is there something similar already available in Django test cases, and if not, would be of interest for the community to add this method to TestCase?
Thanks.
Valentino.