|
@@ -54,15 +54,64 @@ class AdminLoginViewTests(TestCase):
|
|
|
reverse('misago:admin:index'),
|
|
|
data={'username': 'Nope', 'password': 'Nope'})
|
|
|
|
|
|
- self.assertContains(response, 'Login or password is incorrect.')
|
|
|
- self.assertContains(response, 'Sign in')
|
|
|
- self.assertContains(response, 'Username or e-mail')
|
|
|
- self.assertContains(response, 'Password')
|
|
|
+ self.assertContains(response, "Login or password is incorrect.")
|
|
|
+ self.assertContains(response, "Sign in")
|
|
|
+ self.assertContains(response, "Username or e-mail")
|
|
|
+ self.assertContains(response, "Password")
|
|
|
+
|
|
|
+ def test_login_denies_non_staff_non_superuser(self):
|
|
|
+ """login rejects user thats non staff and non superuser"""
|
|
|
+ User = get_user_model()
|
|
|
+ user = User.objects.create_user('Bob', 'bob@test.com', 'Pass.123')
|
|
|
+
|
|
|
+ user.is_staff = False
|
|
|
+ user.is_superuser = False
|
|
|
+ user.save()
|
|
|
+
|
|
|
+ response = self.client.post(
|
|
|
+ reverse('misago:admin:index'),
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
+
|
|
|
+ self.assertContains(response, "Your account does not have admin privileges.")
|
|
|
+
|
|
|
+ def test_login_denies_non_staff_superuser(self):
|
|
|
+ """login rejects user thats non staff and superuser"""
|
|
|
+ User = get_user_model()
|
|
|
+ user = User.objects.create_user('Bob', 'bob@test.com', 'Pass.123')
|
|
|
+
|
|
|
+ user.is_staff = False
|
|
|
+ user.is_superuser = True
|
|
|
+ user.save()
|
|
|
+
|
|
|
+ response = self.client.post(
|
|
|
+ reverse('misago:admin:index'),
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
+
|
|
|
+ self.assertContains(response, "Your account does not have admin privileges.")
|
|
|
+
|
|
|
+ def test_login_signs_in_staff_non_superuser(self):
|
|
|
+ """login passess user thats staff and non superuser"""
|
|
|
+ User = get_user_model()
|
|
|
+ user = User.objects.create_user('Bob', 'bob@test.com', 'Pass.123')
|
|
|
+
|
|
|
+ user.is_staff = True
|
|
|
+ user.is_superuser = False
|
|
|
+ user.save()
|
|
|
|
|
|
- def test_login_returns_200_on_valid_post(self):
|
|
|
- """form handles valid data correctly"""
|
|
|
+ response = self.client.post(
|
|
|
+ reverse('misago:admin:index'),
|
|
|
+ data={'username': 'Bob', 'password': 'Pass.123'})
|
|
|
+
|
|
|
+ self.assertEqual(response.status_code, 302)
|
|
|
+
|
|
|
+ def test_login_signs_in_staff_superuser(self):
|
|
|
+ """login passess user thats staff and superuser"""
|
|
|
User = get_user_model()
|
|
|
- User.objects.create_superuser('Bob', 'bob@test.com', 'Pass.123')
|
|
|
+ user = User.objects.create_user('Bob', 'bob@test.com', 'Pass.123')
|
|
|
+
|
|
|
+ user.is_staff = True
|
|
|
+ user.is_superuser = True
|
|
|
+ user.save()
|
|
|
|
|
|
response = self.client.post(
|
|
|
reverse('misago:admin:index'),
|
|
@@ -95,6 +144,43 @@ class AdminLogoutTests(AdminTestCase):
|
|
|
self.assertContains(response, "Sign in")
|
|
|
|
|
|
|
|
|
+class AdminViewAccessTests(AdminTestCase):
|
|
|
+ def test_admin_denies_non_staff_non_superuser(self):
|
|
|
+ """admin middleware rejects user thats non staff and non superuser"""
|
|
|
+ self.user.is_staff = False
|
|
|
+ self.user.is_superuser = False
|
|
|
+ self.user.save()
|
|
|
+
|
|
|
+ response = self.client.get(reverse('misago:admin:index'))
|
|
|
+ self.assertContains(response, "Sign in")
|
|
|
+
|
|
|
+ def test_admin_denies_non_staff_superuser(self):
|
|
|
+ """admin middleware rejects user thats non staff and superuser"""
|
|
|
+ self.user.is_staff = False
|
|
|
+ self.user.is_superuser = True
|
|
|
+ self.user.save()
|
|
|
+
|
|
|
+ response = self.client.get(reverse('misago:admin:index'))
|
|
|
+ self.assertContains(response, "Sign in")
|
|
|
+
|
|
|
+ def test_admin_passess_in_staff_non_superuser(self):
|
|
|
+ """admin middleware passess user thats staff and non superuser"""
|
|
|
+ self.user.is_staff = True
|
|
|
+ self.user.is_superuser = False
|
|
|
+ self.user.save()
|
|
|
+
|
|
|
+ response = self.client.get(reverse('misago:admin:index'))
|
|
|
+ self.assertContains(response, self.user.username)
|
|
|
+
|
|
|
+ def test_admin_passess_in_staff_superuser(self):
|
|
|
+ """admin middleware passess user thats staff and superuser"""
|
|
|
+ self.user.is_staff = True
|
|
|
+ self.user.is_superuser = True
|
|
|
+ self.user.save()
|
|
|
+
|
|
|
+ response = self.client.get(reverse('misago:admin:index'))
|
|
|
+ self.assertContains(response, self.user.username)
|
|
|
+
|
|
|
class AdminIndexViewTests(AdminTestCase):
|
|
|
def test_view_returns_200(self):
|
|
|
"""admin index view returns 200"""
|