From d3b3d4e2032676a70933c441f163c092682fb017 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 14 Aug 2020 16:56:17 +0100 Subject: [PATCH] Fix modeladmin tests for EmailUser --- .../modeladmin/tests/test_page_modeladmin.py | 29 +++++++------------ .../tests/test_simple_modeladmin.py | 12 +++----- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py b/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py index ec2ac4c4c0..6b76a36232 100644 --- a/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py +++ b/wagtail/contrib/modeladmin/tests/test_page_modeladmin.py @@ -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/') diff --git a/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py b/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py index 3295480a60..72c57dd92f 100644 --- a/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py +++ b/wagtail/contrib/modeladmin/tests/test_simple_modeladmin.py @@ -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)