Adds unit test or list create perms

This commit is contained in:
Mouse Reeve 2022-07-28 11:42:05 -07:00
parent cb4945c384
commit 85dce81b6a

View file

@ -3,6 +3,7 @@ import json
from unittest.mock import patch
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import PermissionDenied
from django.template.response import TemplateResponse
from django.test import TestCase
from django.test.client import RequestFactory
@ -28,6 +29,9 @@ class ListViews(TestCase):
localname="mouse",
remote_id="https://example.com/users/mouse",
)
self.another_user = models.User.objects.create_user(
"rat@local.com", "rat@rat.com", "ratword", local=True, localname="rat"
)
self.anonymous_user = AnonymousUser
self.anonymous_user.is_authenticated = False
@ -167,3 +171,20 @@ class ListViews(TestCase):
self.assertEqual(new_list.description, "wow")
self.assertEqual(new_list.privacy, "unlisted")
self.assertEqual(new_list.curation, "open")
def test_lists_create_permission_denied(self):
"""create list view"""
view = views.Lists.as_view()
request = self.factory.post(
"",
{
"name": "A list",
"description": "wow",
"privacy": "unlisted",
"curation": "open",
"user": self.local_user.id,
},
)
request.user = self.another_user
with self.assertRaises(PermissionDenied):
view(request)