Exemplo n.º 1
0
    def test_view_post_should_add_resource_author(self):
        data = {"url": "https://example.com"}
        request = self.factory.post(reverse("protector-resource_create"),
                                    data=data)
        request.user = self.user

        ResourceCreateView.as_view()(request)

        self.assertEqual(Resource.objects.first().author, self.user)
Exemplo n.º 2
0
    def test_view_post_should_create_resource_object(self):
        data = {"url": "https://example.com"}
        request = self.factory.post(reverse("protector-resource_create"),
                                    data=data)
        request.user = self.user

        ResourceCreateView.as_view()(request)

        self.assertTrue(Resource.objects.exists())
Exemplo n.º 3
0
    def test_view_post_should_add_resource_password(self):
        data = {"url": "https://example.com"}
        request = self.factory.post(reverse("protector-resource_create"),
                                    data=data)
        request.user = self.user

        ResourceCreateView.as_view()(request)

        resource = Resource.objects.first()
        self.assertIsNotNone(resource.password)
Exemplo n.º 4
0
    def test_view_post_should_add_resource_hashed_url(self):
        data = {"url": "https://example.com"}
        request = self.factory.post(reverse("protector-resource_create"),
                                    data=data)
        request.user = self.user

        ResourceCreateView.as_view()(request)

        resource = Resource.objects.first()
        self.assertTrue(
            resource.protected_url,
            reverse("protector-protected_resource", args=(resource.pk, )),
        )
Exemplo n.º 5
0
    def test_view_contains_form(self):
        request = self.factory.get(reverse("protector-resource_create"))
        request.user = self.user

        response = ResourceCreateView.as_view()(request)

        self.assertEqual(response.context_data["form"].__class__, ResourceForm)
Exemplo n.º 6
0
    def test_view_get_status_code(self):
        request = self.factory.get(reverse("protector-resource_create"))
        request.user = self.user

        response = ResourceCreateView.as_view()(request)

        self.assertEqual(response.status_code, 200)
Exemplo n.º 7
0
    def test_view_should_redirect_to_login_page_when_user_is_not_logged_in(
            self):
        request = self.factory.get(reverse("protector-resource_create"))
        request.user = AnonymousUser()

        response = ResourceCreateView.as_view()(request)

        self.assertEqual(response.status_code, 302)
Exemplo n.º 8
0
from django.urls import path

from protector.views import (
    ResourceCreateView,
    ResourceDetailView,
    ResourceProtectedDetailView,
    DownloadFileView,
)

urlpatterns = [
    path("create/", ResourceCreateView.as_view(), name="protector-resource_create"),
    path(
        "detail/<pk>/", ResourceDetailView.as_view(), name="protector-resource_detail"
    ),
    path(
        "protected/<protected_url>",
        ResourceProtectedDetailView.as_view(),
        name="protector-protected_resource",
    ),
    path(
        "download/<protected_url>/",
        DownloadFileView.as_view(),
        name="protector-download",
    ),
]