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:
parent
ffbc4c5f0c
commit
d30f669439
1 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue