You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
1.2 KiB

from typing import Any, Dict
from rest_framework import status
from rest_framework.test import APITestCase
class CRUDMixin(APITestCase):
url = ""
data: Dict[str, Any] = {}
def assert_fetch(self, user=None, expected=status.HTTP_403_FORBIDDEN):
if user:
self.client.force_login(user)
response = self.client.get(self.url)
self.assertEqual(response.status_code, expected)
return response
def assert_create(self, user=None, expected=status.HTTP_403_FORBIDDEN):
if user:
self.client.force_login(user)
response = self.client.post(self.url, data=self.data, format="json")
self.assertEqual(response.status_code, expected)
return response
def assert_update(self, user=None, expected=status.HTTP_403_FORBIDDEN):
if user:
self.client.force_login(user)
response = self.client.patch(self.url, data=self.data, format="json")
self.assertEqual(response.status_code, expected)
return response
def assert_delete(self, user=None, expected=status.HTTP_403_FORBIDDEN):
if user:
self.client.force_login(user)
response = self.client.delete(self.url)
self.assertEqual(response.status_code, expected)