Move tests from example app into main package.

This commit is contained in:
Jannis Leidel 2020-02-07 11:38:50 +01:00
parent fcc569b0d9
commit 1372cf1f6f
No known key found for this signature in database
GPG key ID: C795956FB489DCA9
2 changed files with 18 additions and 22 deletions

View file

@ -1,16 +1,16 @@
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Permission as DjangoPermission from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, Permission as DjangoPermission
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import MultipleObjectsReturned
from django.db.models import Q from django.db.models import Q
from django.test import TestCase from django.test import TestCase
from django.urls import reverse
import authority import authority
from authority import permissions from authority import permissions
from authority.models import Permission from authority.models import Permission
from authority.exceptions import NotAModel, UnsavedModelInstance from authority.exceptions import NotAModel, UnsavedModelInstance
from authority.compat import get_user_model
# Load the form # Load the form
from authority.forms import UserPermissionForm # noqa from authority.forms import UserPermissionForm # noqa
@ -436,3 +436,18 @@ class GroupPermissionCacheTestCase(SmartCachingTestCase):
"foo", self.group, approved=True, "foo", self.group, approved=True,
) )
self.assertTrue(can_foo_with_group) self.assertTrue(can_foo_with_group)
class AddPermissionTestCase(TestCase):
def test_add_permission_permission_denied_is_403(self):
user = get_user_model().objects.create(username="foo", email="foo@example.com",)
user.set_password("pw")
user.save()
assert self.client.login(username="foo@example.com", password="pw")
url = reverse(
"authority-add-permission-request",
kwargs={"app_label": "foo", "module_name": "Bar", "pk": 1,},
)
r = self.client.get(url)
self.assertEqual(r.status_code, 403)

View file

@ -1,19 +0,0 @@
from django.urls import reverse
from django.test import TestCase
from authority.compat import get_user_model
class AddPermissionTestCase(TestCase):
def test_add_permission_permission_denied_is_403(self):
user = get_user_model().objects.create(username="foo", email="foo@example.com",)
user.set_password("pw")
user.save()
assert self.client.login(username="foo@example.com", password="pw")
url = reverse(
"authority-add-permission-request",
kwargs={"app_label": "foo", "module_name": "Bar", "pk": 1,},
)
r = self.client.get(url)
self.assertEqual(r.status_code, 403)