Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, middleware_classes=None, **defaults):
super(RequestFactory, self).__init__(**defaults)
self.middleware_classes = middleware_classes or []
self._override_shortcuts()
import django
from rest_framework import test
from djet import testcases
class APIRequestFactory(testcases.RequestFactory, test.APIRequestFactory):
def _request(self, method, **kwargs):
request = super(APIRequestFactory, self)._request(method, **kwargs)
user = kwargs.get('user')
token = kwargs.get('token')
test.force_authenticate(request, user, token)
return request
class APIViewTransactionTestCase(testcases.ViewTransactionTestCase):
factory_class = APIRequestFactory
class APIViewTestCase(testcases.ViewTestCase):
factory_class = APIRequestFactory
viewset = None