kopia lustrzana https://github.com/wagtail/wagtail
Fix page / account management / filter tests for EmailUser
rodzic
d3b3d4e203
commit
1ca113fba5
|
@ -73,7 +73,7 @@ class TestPageMove(TestCase, WagtailTestUtils):
|
|||
# to verify that a user without bulk delete permission is able to move a page with a child page
|
||||
|
||||
self.client.logout()
|
||||
user = get_user_model().objects.get(username='siteeditor')
|
||||
user = get_user_model().objects.get(email='siteeditor@example.com')
|
||||
self.login(user)
|
||||
|
||||
# ensure the bulk_delete is not applicable to this user
|
||||
|
|
|
@ -107,7 +107,7 @@ class TestRevisions(TestCase, WagtailTestUtils):
|
|||
editors_group = Group.objects.get(name='Site-wide editors')
|
||||
editors_group.page_permissions.update(page_id=st_patricks.id)
|
||||
|
||||
editor = get_user_model().objects.get(username='siteeditor')
|
||||
editor = get_user_model().objects.get(email='siteeditor@example.com')
|
||||
|
||||
self.login(editor)
|
||||
response = self.request_preview_revision()
|
||||
|
|
|
@ -67,7 +67,7 @@ class TestDraftAccess(TestCase, WagtailTestUtils):
|
|||
def test_draft_access_authorized(self):
|
||||
"""Test that user with edit permission can view draft."""
|
||||
# give user the permission to edit page
|
||||
user = get_user_model().objects.get(username='bob')
|
||||
user = get_user_model().objects.get(email='bob@example.com')
|
||||
user.groups.add(Group.objects.get(name='Moderators'))
|
||||
user.save()
|
||||
|
||||
|
|
|
@ -611,7 +611,7 @@ class TestAccountManagementForNonModerator(TestCase, WagtailTestUtils):
|
|||
self.submitter = self.create_user('submitter', 'submitter@example.com', 'password')
|
||||
self.submitter.groups.add(Group.objects.get(name='Editors'))
|
||||
|
||||
self.login(username=self.submitter.username, password='password')
|
||||
self.login(username='submitter', password='password')
|
||||
|
||||
def test_notification_preferences_form_is_reduced_for_non_moderators(self):
|
||||
"""
|
||||
|
@ -640,7 +640,7 @@ class TestAccountManagementForAdminOnlyUser(TestCase, WagtailTestUtils):
|
|||
)
|
||||
self.admin_only_user.groups.add(admin_only_group)
|
||||
|
||||
self.login(username=self.admin_only_user.username, password='password')
|
||||
self.login(username='admin_only_user', password='password')
|
||||
|
||||
def test_notification_preferences_view_redirects_for_admin_only_users(self):
|
||||
"""
|
||||
|
@ -745,7 +745,7 @@ class TestPasswordReset(TestCase, WagtailTestUtils):
|
|||
from django.utils.http import urlsafe_base64_encode
|
||||
|
||||
# Get user
|
||||
self.user = get_user_model().objects.get(username='test')
|
||||
self.user = get_user_model().objects.get(email='test@email.com')
|
||||
|
||||
# Generate a password reset token
|
||||
self.password_reset_token = PasswordResetTokenGenerator().make_token(self.user)
|
||||
|
@ -818,7 +818,7 @@ class TestPasswordReset(TestCase, WagtailTestUtils):
|
|||
self.assertRedirects(response, reverse('wagtailadmin_password_reset_complete'))
|
||||
|
||||
# Check that the password was changed
|
||||
self.assertTrue(get_user_model().objects.get(username='test').check_password('newpassword'))
|
||||
self.assertTrue(get_user_model().objects.get(email='test@email.com').check_password('newpassword'))
|
||||
|
||||
def test_password_reset_confirm_view_post_password_mismatch(self):
|
||||
"""
|
||||
|
@ -846,7 +846,7 @@ class TestPasswordReset(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(username='test').check_password('password'))
|
||||
self.assertTrue(get_user_model().objects.get(email='test@email.com').check_password('password'))
|
||||
|
||||
def test_password_reset_done_view(self):
|
||||
"""
|
||||
|
@ -872,7 +872,7 @@ class TestPasswordReset(TestCase, WagtailTestUtils):
|
|||
|
||||
def test_password_reset_sensitive_post_parameters(self):
|
||||
request = RequestFactory().post('wagtailadmin_password_reset_confirm', data={})
|
||||
request.user = get_user_model().objects.get(username='test')
|
||||
request.user = get_user_model().objects.get(email='test@email.com')
|
||||
change_password(request)
|
||||
self.assertTrue(hasattr(request, 'sensitive_post_parameters'))
|
||||
self.assertEqual(request.sensitive_post_parameters, '__ALL__')
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestFilteredModelChoiceField(TestCase, WagtailTestUtils):
|
|||
|
||||
class UserForm(forms.Form):
|
||||
users = FilteredModelChoiceField(
|
||||
queryset=User.objects.order_by('username'), filter_field='id_group', filter_accessor='groups'
|
||||
queryset=User.objects.order_by(User.USERNAME_FIELD), filter_field='id_group', filter_accessor='groups'
|
||||
)
|
||||
|
||||
form = UserForm()
|
||||
|
@ -42,13 +42,15 @@ class TestFilteredModelChoiceField(TestCase, WagtailTestUtils):
|
|||
expected_html = """
|
||||
<select name="users" data-widget="filtered-select" data-filter-field="id_group" required id="id_users">
|
||||
<option value="" selected>---------</option>
|
||||
<option value="%(david)s" data-filter-value="%(musicians)s,%(actors)s">david</option>
|
||||
<option value="%(kevin)s" data-filter-value="%(actors)s">kevin</option>
|
||||
<option value="%(morten)s" data-filter-value="%(musicians)s">morten</option>
|
||||
<option value="%(david)s" data-filter-value="%(musicians)s,%(actors)s">%(david_username)s</option>
|
||||
<option value="%(kevin)s" data-filter-value="%(actors)s">%(kevin_username)s</option>
|
||||
<option value="%(morten)s" data-filter-value="%(musicians)s">%(morten_username)s</option>
|
||||
</select>
|
||||
""" % {
|
||||
'david': self.david.pk, 'kevin': self.kevin.pk, 'morten': self.morten.pk,
|
||||
'musicians': self.musicians.pk, 'actors': self.actors.pk,
|
||||
'david_username': self.david.get_username(), 'kevin_username': self.kevin.get_username(),
|
||||
'morten_username': self.morten.get_username(),
|
||||
}
|
||||
self.assertHTMLEqual(html, expected_html)
|
||||
|
||||
|
@ -56,7 +58,7 @@ class TestFilteredModelChoiceField(TestCase, WagtailTestUtils):
|
|||
|
||||
class UserForm(forms.Form):
|
||||
users = FilteredModelChoiceField(
|
||||
queryset=User.objects.order_by('username'), filter_field='id_group',
|
||||
queryset=User.objects.order_by(User.USERNAME_FIELD), filter_field='id_group',
|
||||
filter_accessor=lambda user: user.groups.all()
|
||||
)
|
||||
|
||||
|
@ -65,12 +67,14 @@ class TestFilteredModelChoiceField(TestCase, WagtailTestUtils):
|
|||
expected_html = """
|
||||
<select name="users" data-widget="filtered-select" data-filter-field="id_group" required id="id_users">
|
||||
<option value="" selected>---------</option>
|
||||
<option value="%(david)s" data-filter-value="%(musicians)s,%(actors)s">david</option>
|
||||
<option value="%(kevin)s" data-filter-value="%(actors)s">kevin</option>
|
||||
<option value="%(morten)s" data-filter-value="%(musicians)s">morten</option>
|
||||
<option value="%(david)s" data-filter-value="%(musicians)s,%(actors)s">%(david_username)s</option>
|
||||
<option value="%(kevin)s" data-filter-value="%(actors)s">%(kevin_username)s</option>
|
||||
<option value="%(morten)s" data-filter-value="%(musicians)s">%(morten_username)s</option>
|
||||
</select>
|
||||
""" % {
|
||||
'david': self.david.pk, 'kevin': self.kevin.pk, 'morten': self.morten.pk,
|
||||
'musicians': self.musicians.pk, 'actors': self.actors.pk,
|
||||
'david_username': self.david.get_username(), 'kevin_username': self.kevin.get_username(),
|
||||
'morten_username': self.morten.get_username(),
|
||||
}
|
||||
self.assertHTMLEqual(html, expected_html)
|
||||
|
|
|
@ -768,7 +768,7 @@ class TestCanChoosePage(TestCase, WagtailTestUtils):
|
|||
def test_with_user_no_permission(self):
|
||||
homepage = Page.objects.get(url_path='/home/')
|
||||
# event editor does not have permissions on homepage
|
||||
event_editor = get_user_model().objects.get(username='eventeditor')
|
||||
event_editor = get_user_model().objects.get(email='eventeditor@example.com')
|
||||
permission_proxy = UserPagePermissionsProxy(event_editor)
|
||||
result = can_choose_page(homepage, permission_proxy, self.desired_classes, user_perm='copy_to')
|
||||
self.assertFalse(result)
|
||||
|
|
Ładowanie…
Reference in New Issue