diff --git a/{{cookiecutter.project_slug}}/src/app/testing/api.py b/{{cookiecutter.project_slug}}/src/app/testing/api.py index f9d66ae2..3f65376a 100644 --- a/{{cookiecutter.project_slug}}/src/app/testing/api.py +++ b/{{cookiecutter.project_slug}}/src/app/testing/api.py @@ -5,6 +5,7 @@ from rest_framework.authtoken.models import Token from rest_framework.test import APIClient as DRFAPIClient +from rest_framework.response import Response from users.models import User @@ -58,7 +59,10 @@ def _request(self, method, expected, *args, **kwargs): assert response.status_code == expected, content return content - def _decode(self, response): + def _decode(self, response: Response): + if response.status_code == 204: + return {} + content = response.content.decode("utf-8", errors="ignore") if self.is_json(response): @@ -67,7 +71,7 @@ def _decode(self, response): return content @staticmethod - def is_json(response) -> bool: + def is_json(response: Response) -> bool: if response.has_header("content-type"): return "json" in response.get("content-type")