How to use the djet.testcases 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 / 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

    def _get_view(self, request):
        if self.viewset:
            actions = request.META.pop('actions')
            return self.viewset.as_view(actions=actions, **self.get_view_kwargs())
        return super(APIViewTestCase, self)._get_view(request)


if django.VERSION >= (1, 4):
    class APIViewLiveServerTestCase(testcases.ViewLiveServerTestCase):
github sunscrapers / djet / djet / restframework.py View on Github external
factory_class = APIRequestFactory


class APIViewTestCase(testcases.ViewTestCase):
    factory_class = APIRequestFactory
    viewset = None

    def _get_view(self, request):
        if self.viewset:
            actions = request.META.pop('actions')
            return self.viewset.as_view(actions=actions, **self.get_view_kwargs())
        return super(APIViewTestCase, self)._get_view(request)


if django.VERSION >= (1, 4):
    class APIViewLiveServerTestCase(testcases.ViewLiveServerTestCase):
        factory_class = APIRequestFactory

if django.VERSION >= (1, 5):
    class APIViewSimpleTestCase(testcases.ViewSimpleTestCase):
        factory_class = APIRequestFactory
github sunscrapers / djet / djet / restframework.py View on Github external
factory_class = APIRequestFactory
    viewset = None

    def _get_view(self, request):
        if self.viewset:
            actions = request.META.pop('actions')
            return self.viewset.as_view(actions=actions, **self.get_view_kwargs())
        return super(APIViewTestCase, self)._get_view(request)


if django.VERSION >= (1, 4):
    class APIViewLiveServerTestCase(testcases.ViewLiveServerTestCase):
        factory_class = APIRequestFactory

if django.VERSION >= (1, 5):
    class APIViewSimpleTestCase(testcases.ViewSimpleTestCase):
        factory_class = APIRequestFactory