diff --git a/drf_kit/tests.py b/drf_kit/tests.py index 02f836c..e116716 100644 --- a/drf_kit/tests.py +++ b/drf_kit/tests.py @@ -121,6 +121,14 @@ def assertResponseDeleted(self, response: Response): logger.info("Please use assertResponseDelete instead") self.assertResponseDelete(response=response) + def assertResponseBadRequest(self, response: Response, expected: dict = ANY): + self.assertResponse( + expected_status=status.HTTP_400_BAD_REQUEST, + expected_body=expected, + response=response, + response_key=None, + ) + def assertResponseNotAllowed(self, response: Response): method = response.request["REQUEST_METHOD"] expected = {"detail": f'Method "{method}" not allowed.'} diff --git a/test_app/tests/tests_views/tests_crud_views.py b/test_app/tests/tests_views/tests_crud_views.py index 68c361e..522fb98 100644 --- a/test_app/tests/tests_views/tests_crud_views.py +++ b/test_app/tests/tests_views/tests_crud_views.py @@ -149,7 +149,7 @@ def test_post_endpoint_with_constraint_error(self): expected = { "errors": "This Beast violates the check `minimum-beast-age` which states `(AND: ('age__gte', 0))`", } - self.assertResponse(expected_status=status.HTTP_400_BAD_REQUEST, expected_body=expected, response=response) + self.assertResponseBadRequest(response=response, expected=expected) beasts = models.Beast.objects.all() self.assertEqual(0, beasts.count())