mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Created an overridable function to allow for custom user models. Also, changed the account_management tests to get the test_user via the pk.
This commit is contained in:
parent
ee09d5e5d6
commit
c3d2bb52ac
@ -13,18 +13,27 @@ from django.utils.text import slugify
|
||||
|
||||
|
||||
class WagtailTestUtils(object):
|
||||
def login(self):
|
||||
|
||||
@staticmethod
|
||||
def create_test_user():
|
||||
"""
|
||||
Override this method to return an instance of your custom user model
|
||||
"""
|
||||
user_model = get_user_model()
|
||||
# Create a user
|
||||
user_data = {}
|
||||
user_data = dict()
|
||||
user_data[user_model.USERNAME_FIELD] = 'test@email.com'
|
||||
user_data['password'] = 'password'
|
||||
|
||||
for field in user_model.REQUIRED_FIELDS:
|
||||
user_data[field] = field
|
||||
|
||||
user = user_model.objects.create_superuser(**user_data)
|
||||
return user_model.objects.create_superuser(**user_data)
|
||||
|
||||
def login(self):
|
||||
user = self.create_test_user()
|
||||
|
||||
user_model = get_user_model()
|
||||
# Login
|
||||
self.client.login(password='password', **{user_model.USERNAME_FIELD: 'test@email.com'})
|
||||
|
||||
|
@ -135,7 +135,7 @@ class TestAccountSection(TestCase, WagtailTestUtils):
|
||||
This tests that the accounts section is working
|
||||
"""
|
||||
def setUp(self):
|
||||
self.login()
|
||||
self.user = self.login()
|
||||
|
||||
def test_account_view(self):
|
||||
"""
|
||||
@ -199,8 +199,7 @@ class TestAccountSection(TestCase, WagtailTestUtils):
|
||||
self.assertRedirects(response, reverse('wagtailadmin_account'))
|
||||
|
||||
# Check that the password was changed
|
||||
self.assertTrue(get_user_model().objects.get(
|
||||
**{get_user_model().USERNAME_FIELD: 'test@email.com'}).check_password('newpassword'))
|
||||
self.assertTrue(get_user_model().objects.get(pk=self.user.pk).check_password('newpassword'))
|
||||
|
||||
def test_change_password_view_post_password_mismatch(self):
|
||||
"""
|
||||
@ -222,8 +221,7 @@ class TestAccountSection(TestCase, WagtailTestUtils):
|
||||
self.assertTrue("The two password fields didn't match." in response.context['form'].errors['new_password2'])
|
||||
|
||||
# Check that the password was not changed
|
||||
self.assertTrue(get_user_model().objects.get(
|
||||
**{get_user_model().USERNAME_FIELD: 'test@email.com'}).check_password('password'))
|
||||
self.assertTrue(get_user_model().objects.get(pk=self.user.pk).check_password('password'))
|
||||
|
||||
def test_notification_preferences_view(self):
|
||||
"""
|
||||
@ -253,8 +251,7 @@ class TestAccountSection(TestCase, WagtailTestUtils):
|
||||
# Check that the user was redirected to the account page
|
||||
self.assertRedirects(response, reverse('wagtailadmin_account'))
|
||||
|
||||
profile = UserProfile.get_for_user(get_user_model().objects.get(
|
||||
**{get_user_model().USERNAME_FIELD: 'test@email.com'}))
|
||||
profile = UserProfile.get_for_user(get_user_model().objects.get(pk=self.user.pk))
|
||||
|
||||
# Check that the notification preferences are as submitted
|
||||
self.assertFalse(profile.submitted_notifications)
|
||||
|
Loading…
Reference in New Issue
Block a user