0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Fix modeladmin tests for EmailUser

This commit is contained in:
Matt Westcott 2020-08-14 16:56:17 +01:00 committed by Matt Westcott
parent da5b5d4161
commit d3b3d4e203
2 changed files with 14 additions and 27 deletions

View File

@ -1,5 +1,4 @@
from django import VERSION as DJANGO_VERSION
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.test import TestCase
@ -278,10 +277,10 @@ class TestChooseParentViewForNonSuperuser(TestCase, WagtailTestUtils):
permission_type='add'
)
user = get_user_model().objects._create_user(username='test2', email='test2@email.com', password='password', is_staff=True, is_superuser=False)
user = self.create_user(username='test2', password='password')
user.groups.add(business_editors)
# Login
self.client.login(username='test2', password='password')
self.login(username='test2', password='password')
def test_simple(self):
response = self.client.get('/admin/tests/businesschild/choose_parent/')
@ -291,40 +290,32 @@ class TestChooseParentViewForNonSuperuser(TestCase, WagtailTestUtils):
self.assertNotContains(response, 'Private Business Index')
class TestEditorAccess(TestCase):
class TestEditorAccess(TestCase, WagtailTestUtils):
fixtures = ['test_specific.json']
expected_status_code = 403
def login(self):
def setUp(self):
# Create a user
user = get_user_model().objects._create_user(username='test2', email='test2@email.com', password='password', is_staff=True, is_superuser=False)
user = self.create_user(username='test2', password='password')
user.groups.add(Group.objects.get(pk=2))
# Login
self.client.login(username='test2', password='password')
return user
def setUp(self):
self.login()
self.login(username='test2', password='password')
def test_delete_permitted(self):
response = self.client.get('/admin/tests/eventpage/delete/4/')
self.assertEqual(response.status_code, self.expected_status_code)
class TestModeratorAccess(TestCase):
class TestModeratorAccess(TestCase, WagtailTestUtils):
fixtures = ['test_specific.json']
expected_status_code = 302
def login(self):
def setUp(self):
# Create a user
user = get_user_model().objects._create_user(username='test3', email='test3@email.com', password='password', is_staff=True, is_superuser=False)
user = self.create_user(username='test3', password='password')
user.groups.add(Group.objects.get(pk=1))
# Login
self.client.login(username='test2', password='password')
return user
def setUp(self):
self.login()
self.login(username='test3', password='password')
def test_delete_permitted(self):
response = self.client.get('/admin/tests/eventpage/delete/4/')

View File

@ -1,7 +1,6 @@
from io import BytesIO
from unittest import mock
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.core import checks
from django.test import TestCase
@ -514,22 +513,19 @@ class TestDeleteViewModelReprPrimary(TestCase, WagtailTestUtils):
self.assertEqual(response.status_code, 302)
class TestEditorAccess(TestCase):
class TestEditorAccess(TestCase, WagtailTestUtils):
fixtures = ['modeladmintest_test.json']
expected_status_code = 403
def login(self):
def setUp(self):
# Create a user
user = get_user_model().objects._create_user(username='test2', email='test2@email.com', password='password', is_staff=True, is_superuser=False)
user = self.create_user(username='test2', password='password')
user.groups.add(Group.objects.get(pk=2))
# Login
self.client.login(username='test2', password='password')
self.login(username='test2', password='password')
return user
def setUp(self):
self.login()
def test_index_permitted(self):
response = self.client.get('/admin/modeladmintest/book/')
self.assertEqual(response.status_code, self.expected_status_code)