From 1e2d521584d37939d8c94d2ac2022d60a8e1ca4a Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Sat, 26 Jan 2013 17:33:14 -0500 Subject: [PATCH] Added a test for a valid login case and make a better assert for the admin page because is not redirected to another url --- axes/tests.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/axes/tests.py b/axes/tests.py index f0cacb9..d5a8ae2 100644 --- a/axes/tests.py +++ b/axes/tests.py @@ -28,7 +28,7 @@ class AccessAttemptTest(TestCase): for i in range(0, random.randrange(10, 50)): username = "person%s" % i email = "%s@example.org" % username - u = User.objects.create_user(email=email, username=username) + u = User.objects.create_user(email=email, username=username, password=username) u.is_staff = True u.save() @@ -56,7 +56,7 @@ class AccessAttemptTest(TestCase): for i in range(0, FAILURE_LIMIT - 1): response = self._attempt_login(existing_username=existing_username) # Check if we are in the same login page - self.assertEquals(response.status_code, 200) + self.assertIn('this_is_the_login_form', response.content) # So, we shouldn't have gotten a lock-out yet. # But we should get one now @@ -70,7 +70,7 @@ class AccessAttemptTest(TestCase): for i in range(0, FAILURE_LIMIT - 1): response = self._attempt_login(existing_username=existing_username) # Check if we are in the same login page - self.assertEquals(response.status_code, 200) + self.assertIn('this_is_the_login_form', response.content) # So, we shouldn't have gotten a lock-out yet. # But we should get one now @@ -81,3 +81,11 @@ class AccessAttemptTest(TestCase): def test_with_real_username_max_with_more(self): self.test_login_max_with_more_attempts(existing_username=True) + + def test_valid_login(self): + valid_username = self._random_username(existing_username=True) + response = self.client.post(reverse('admin:index'), { + 'username': valid_username, + 'password': valid_username + }) + self.assertNotIn('authentication_form', response.context)