def test_authenticated_user(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = User.objects.create(username="******", is_superuser=False, is_staff=False)

        with pytest.raises(PermissionDenied):
            views.flush_cache(request)
    def test_authenticated_user(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = mixer.blend("auth.User", is_superuser=False, is_staff=False)

        with pytest.raises(PermissionDenied):
            views.flush_cache(request)
    def test_authenticated_user(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = mixer.blend("auth.User",
                                   is_superuser=False,
                                   is_staff=False)

        with pytest.raises(PermissionDenied):
            views.flush_cache(request)
    def test_anonymous_login_only_mode(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.flush_cache(request)

        assert response.status_code == 302, "Should redirect to login page"
        assert response.url == reverse("login") + "?next=" + url, \
            "Should contain a next parameter for redirect"
    def test_anonymous_login_only_mode(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = AnonymousUser()
        response = views.flush_cache(request)

        assert response.status_code == 302, "Should redirect to login page"
        assert response.url == reverse("login") + "?next=" + url, \
            "Should contain a next parameter for redirect"
    def test_superuser(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = User.objects.get(username="******")
        msgs = patch_contrib_messages(request)
        response = views.flush_cache(request)

        assert response.status_code == 302, "Should redirect to status page"
        assert msgs.added_new
        assert response.url == reverse("productdb_config:status")
    def test_superuser(self):
        url = reverse(self.URL_NAME)
        request = RequestFactory().get(url)
        request.user = User.objects.get(username="******")
        msgs = patch_contrib_messages(request)
        response = views.flush_cache(request)

        assert response.status_code == 302, "Should redirect to status page"
        assert msgs.added_new
        assert response.url == reverse("productdb_config:status")