Fix authentication app tests
Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -8,8 +8,7 @@ from django.urls import reverse
|
||||
from mayan.apps.common.tests import GenericViewTestCase
|
||||
from mayan.apps.smart_settings.classes import Namespace
|
||||
from mayan.apps.user_management.tests.literals import (
|
||||
TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD, TEST_ADMIN_USERNAME,
|
||||
TEST_USER_PASSWORD_EDITED
|
||||
TEST_CASE_USER_EMAIL, TEST_CASE_USER_PASSWORD, TEST_CASE_USER_USERNAME,
|
||||
)
|
||||
|
||||
from ..settings import setting_maximum_session_length
|
||||
@@ -19,11 +18,12 @@ from .literals import TEST_EMAIL_AUTHENTICATION_BACKEND
|
||||
|
||||
class UserLoginTestCase(GenericViewTestCase):
|
||||
"""
|
||||
Test that users can login via the supported authentication methods
|
||||
Test that users can login using the supported authentication methods
|
||||
"""
|
||||
authenticated_url = '{}?next={}'.format(
|
||||
reverse(settings.LOGIN_URL), reverse(viewname='documents:document_list')
|
||||
)
|
||||
auto_login_user = False
|
||||
|
||||
def setUp(self):
|
||||
super(UserLoginTestCase, self).setUp()
|
||||
@@ -42,7 +42,7 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
@override_settings(AUTHENTICATION_LOGIN_METHOD='username')
|
||||
def test_username_login(self):
|
||||
logged_in = self.login(
|
||||
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
|
||||
username=TEST_CASE_USER_USERNAME, password=TEST_CASE_USER_PASSWORD
|
||||
)
|
||||
self.assertTrue(logged_in)
|
||||
response = self._request_authenticated_view()
|
||||
@@ -53,12 +53,12 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
def test_email_login(self):
|
||||
with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)):
|
||||
logged_in = self.login(
|
||||
username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD
|
||||
username=TEST_CASE_USER_USERNAME, password=TEST_CASE_USER_PASSWORD
|
||||
)
|
||||
self.assertFalse(logged_in)
|
||||
|
||||
logged_in = self.login(
|
||||
email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD
|
||||
email=TEST_CASE_USER_EMAIL, password=TEST_CASE_USER_PASSWORD
|
||||
)
|
||||
self.assertTrue(logged_in)
|
||||
|
||||
@@ -75,8 +75,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'username': TEST_ADMIN_USERNAME,
|
||||
'password': TEST_ADMIN_PASSWORD
|
||||
'username': TEST_CASE_USER_USERNAME,
|
||||
'password': TEST_CASE_USER_PASSWORD
|
||||
}
|
||||
)
|
||||
response = self._request_authenticated_view()
|
||||
@@ -93,7 +93,7 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'email': TEST_ADMIN_EMAIL, 'password': TEST_ADMIN_PASSWORD
|
||||
'email': TEST_CASE_USER_EMAIL, 'password': TEST_CASE_USER_PASSWORD
|
||||
}, follow=True
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@@ -106,8 +106,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
def test_username_remember_me(self):
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'username': TEST_ADMIN_USERNAME,
|
||||
'password': TEST_ADMIN_PASSWORD,
|
||||
'username': TEST_CASE_USER_USERNAME,
|
||||
'password': TEST_CASE_USER_PASSWORD,
|
||||
'remember_me': True
|
||||
}, follow=True
|
||||
)
|
||||
@@ -125,8 +125,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
def test_username_dont_remember_me(self):
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'username': TEST_ADMIN_USERNAME,
|
||||
'password': TEST_ADMIN_PASSWORD,
|
||||
'username': TEST_CASE_USER_USERNAME,
|
||||
'password': TEST_CASE_USER_PASSWORD,
|
||||
'remember_me': False
|
||||
}, follow=True
|
||||
)
|
||||
@@ -141,8 +141,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)):
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'email': TEST_ADMIN_EMAIL,
|
||||
'password': TEST_ADMIN_PASSWORD,
|
||||
'email': TEST_CASE_USER_EMAIL,
|
||||
'password': TEST_CASE_USER_PASSWORD,
|
||||
'remember_me': True
|
||||
}, follow=True
|
||||
)
|
||||
@@ -161,8 +161,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)):
|
||||
response = self.post(
|
||||
viewname=settings.LOGIN_URL, data={
|
||||
'email': TEST_ADMIN_EMAIL,
|
||||
'password': TEST_ADMIN_PASSWORD,
|
||||
'email': TEST_CASE_USER_EMAIL,
|
||||
'password': TEST_CASE_USER_PASSWORD,
|
||||
'remember_me': False
|
||||
}
|
||||
)
|
||||
@@ -176,7 +176,7 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
def test_password_reset(self):
|
||||
response = self.post(
|
||||
viewname='authentication:password_reset_view', data={
|
||||
'email': TEST_ADMIN_EMAIL,
|
||||
'email': TEST_CASE_USER_EMAIL,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -188,15 +188,15 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
response = self.post(
|
||||
viewname='authentication:password_reset_confirm_view',
|
||||
args=uid_token[-3:-1], data={
|
||||
'new_password1': TEST_USER_PASSWORD_EDITED,
|
||||
'new_password2': TEST_USER_PASSWORD_EDITED,
|
||||
'new_password1': TEST_CASE_USER_PASSWORD,
|
||||
'new_password2': TEST_CASE_USER_PASSWORD,
|
||||
}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.login(
|
||||
username=TEST_ADMIN_USERNAME, password=TEST_USER_PASSWORD_EDITED
|
||||
username=TEST_CASE_USER_USERNAME, password=TEST_CASE_USER_PASSWORD
|
||||
)
|
||||
|
||||
response = self._request_authenticated_view()
|
||||
@@ -209,8 +209,8 @@ class UserLoginTestCase(GenericViewTestCase):
|
||||
path='{}?next={}'.format(
|
||||
reverse(settings.LOGIN_URL), TEST_REDIRECT_URL
|
||||
), data={
|
||||
'username': TEST_ADMIN_USERNAME,
|
||||
'password': TEST_ADMIN_PASSWORD,
|
||||
'username': TEST_CASE_USER_USERNAME,
|
||||
'password': TEST_CASE_USER_PASSWORD,
|
||||
'remember_me': False
|
||||
}, follow=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user