How to use the djet.testcases.ViewTestCase 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 zsiciarz / django-pgallery / tests / test_views.py View on Github external
user = UserFactory(is_staff=True)
        request = self.factory.get(user=user)
        response = self.view(request)
        self.assertContains(response, gallery.title)


class TaggedPhotoListViewTestCase(ViewTestCase):
    view_class = TaggedPhotoListView

    def test_tag_in_response(self):
        request = self.factory.get()
        response = self.view(request, tag="example_tag")
        self.assertContains(response, "example_tag")


class ExifPhotoListViewTestCase(ViewTestCase):
    view_class = ExifPhotoListView

    def test_photo_found(self):
        photo = PhotoFactory(title="Test photo", exif={"Make": "Canon"})
        request = self.factory.get()
        response = self.view(request, exif_key="Make", exif_value="Canon")
        self.assertContains(response, photo.title)

    def test_photo_not_found(self):
        photo = PhotoFactory(title="Test photo", exif={"Make": "Nikon"})
        request = self.factory.get()
        response = self.view(request, exif_key="Make", exif_value="Canon")
        self.assertNotContains(response, photo.title)
github zsiciarz / django-pgallery / tests / test_views.py View on Github external
from django.contrib.auth.models import AnonymousUser

from djet.testcases import ViewTestCase

from pgallery.views import GalleryListView, TaggedPhotoListView, ExifPhotoListView
from .factories import GalleryFactory, UserFactory, PhotoFactory


class GalleryListViewTestCase(ViewTestCase):
    view_class = GalleryListView

    def test_draft_invisible(self):
        gallery = GalleryFactory(status="draft", title="Draft gallery")
        request = self.factory.get(user=AnonymousUser())
        response = self.view(request)
        self.assertNotContains(response, gallery.title)

    def test_draft_visible_for_staff(self):
        gallery = GalleryFactory(status="draft", title="Draft gallery")
        user = UserFactory(is_staff=True)
        request = self.factory.get(user=user)
        response = self.view(request)
        self.assertContains(response, gallery.title)
github zsiciarz / django-pgallery / tests / test_views.py View on Github external
def test_draft_invisible(self):
        gallery = GalleryFactory(status="draft", title="Draft gallery")
        request = self.factory.get(user=AnonymousUser())
        response = self.view(request)
        self.assertNotContains(response, gallery.title)

    def test_draft_visible_for_staff(self):
        gallery = GalleryFactory(status="draft", title="Draft gallery")
        user = UserFactory(is_staff=True)
        request = self.factory.get(user=user)
        response = self.view(request)
        self.assertContains(response, gallery.title)


class TaggedPhotoListViewTestCase(ViewTestCase):
    view_class = TaggedPhotoListView

    def test_tag_in_response(self):
        request = self.factory.get()
        response = self.view(request, tag="example_tag")
        self.assertContains(response, "example_tag")


class ExifPhotoListViewTestCase(ViewTestCase):
    view_class = ExifPhotoListView

    def test_photo_found(self):
        photo = PhotoFactory(title="Test photo", exif={"Make": "Canon"})
        request = self.factory.get()
        response = self.view(request, exif_key="Make", exif_value="Canon")
        self.assertContains(response, photo.title)
github sunscrapers / djet / djet / restframework.py View on Github external
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):
        factory_class = APIRequestFactory

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