From d30f669439edad1383756adbe27ab4480a1802dc Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 27 Oct 2021 18:17:48 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20`SophonModelTestCase`=20fa?= =?UTF-8?q?ilure=20assertions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/core/tests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/sophon/core/tests.py b/backend/sophon/core/tests.py index 5561222..4236e6d 100644 --- a/backend/sophon/core/tests.py +++ b/backend/sophon/core/tests.py @@ -31,6 +31,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta): self.assertTrue(isinstance(response.data, dict)) return response.data + def list_fail(self) -> None: + response = self.list() + self.assertTrue(response.status_code >= 400) + def retrieve(self, pk) -> Response: url = self.get_url("detail", pk=pk) return self.client.get(url, {}, format="json") @@ -41,6 +45,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta): self.assertTrue(isinstance(response.data, dict)) return response.data + def retrieve_fail(self, pk) -> None: + response = self.retrieve(pk=pk) + self.assertTrue(response.status_code >= 400) + def create(self, data) -> Response: url = self.get_url("list") return self.client.post(url, data, format="json") @@ -51,6 +59,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta): self.assertTrue(isinstance(response.data, dict)) return response.data + def create_fail(self, data) -> None: + response = self.create(data) + self.assertTrue(response.status_code >= 400) + def update(self, pk, data) -> Response: url = self.get_url("detail", pk=pk) return self.client.put(url, data, format="json") @@ -61,6 +73,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta): self.assertTrue(isinstance(response.data, dict)) return response.data + def update_fail(self, pk, data) -> None: + response = self.update(pk, data) + self.assertTrue(response.status_code >= 400) + def destroy(self, pk) -> Response: url = self.get_url("detail", pk=pk) return self.client.delete(url, format="json") @@ -69,6 +85,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta): response = self.destroy(pk=pk) self.assertEqual(response.status_code, 204) + def destroy_fail(self, pk) -> None: + response = self.destroy(pk) + self.assertTrue(response.status_code >= 400) + class ResearchGroupTests(SophonModelTestCase): @classmethod