How to use the djet.testcases.RequestFactory function in djet

To help you get started, we’ve selected a few djet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sunscrapers / djet / djet / testcases.py View on Github external
def __init__(self, middleware_classes=None, **defaults):
        super(RequestFactory, self).__init__(**defaults)
        self.middleware_classes = middleware_classes or []
        self._override_shortcuts()
github sunscrapers / djet / djet / restframework.py View on Github external
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