1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 14:54:22 +00:00

🧪 Add SophonModelTestCase failure assertions

This commit is contained in:
Steffo 2021-10-27 18:17:48 +02:00
parent ffbc4c5f0c
commit d30f669439

View file

@ -31,6 +31,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta):
self.assertTrue(isinstance(response.data, dict)) self.assertTrue(isinstance(response.data, dict))
return response.data return response.data
def list_fail(self) -> None:
response = self.list()
self.assertTrue(response.status_code >= 400)
def retrieve(self, pk) -> Response: def retrieve(self, pk) -> Response:
url = self.get_url("detail", pk=pk) url = self.get_url("detail", pk=pk)
return self.client.get(url, {}, format="json") return self.client.get(url, {}, format="json")
@ -41,6 +45,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta):
self.assertTrue(isinstance(response.data, dict)) self.assertTrue(isinstance(response.data, dict))
return response.data 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: def create(self, data) -> Response:
url = self.get_url("list") url = self.get_url("list")
return self.client.post(url, data, format="json") return self.client.post(url, data, format="json")
@ -51,6 +59,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta):
self.assertTrue(isinstance(response.data, dict)) self.assertTrue(isinstance(response.data, dict))
return response.data 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: def update(self, pk, data) -> Response:
url = self.get_url("detail", pk=pk) url = self.get_url("detail", pk=pk)
return self.client.put(url, data, format="json") return self.client.put(url, data, format="json")
@ -61,6 +73,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta):
self.assertTrue(isinstance(response.data, dict)) self.assertTrue(isinstance(response.data, dict))
return response.data 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: def destroy(self, pk) -> Response:
url = self.get_url("detail", pk=pk) url = self.get_url("detail", pk=pk)
return self.client.delete(url, format="json") return self.client.delete(url, format="json")
@ -69,6 +85,10 @@ class SophonModelTestCase(APITestCase, metaclass=abc.ABCMeta):
response = self.destroy(pk=pk) response = self.destroy(pk=pk)
self.assertEqual(response.status_code, 204) 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): class ResearchGroupTests(SophonModelTestCase):
@classmethod @classmethod