From 3788b0d9bf06456ee611a8c47334cc8475c051cd Mon Sep 17 00:00:00 2001 From: Nick Farrell Date: Sat, 8 Feb 2014 22:54:35 +1100 Subject: [PATCH 1/2] Python 3 compatibility fix for db_reset --- axes/management/commands/axes_reset.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/axes/management/commands/axes_reset.py b/axes/management/commands/axes_reset.py index 246394c..653e192 100644 --- a/axes/management/commands/axes_reset.py +++ b/axes/management/commands/axes_reset.py @@ -18,6 +18,6 @@ class Command(BaseCommand): count = reset() if count: - print '{0} attempts removed.'.format(count) + print('{0} attempts removed.'.format(count)) else: - print 'No attempts found.' + print('No attempts found.') From 864508bd13612a47602b13f25b5771184a09f61e Mon Sep 17 00:00:00 2001 From: Nick Farrell Date: Sat, 8 Feb 2014 23:38:06 +1100 Subject: [PATCH 2/2] update test cases to be python3 compatible --- axes/tests.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/axes/tests.py b/axes/tests.py index 106e895..7054478 100644 --- a/axes/tests.py +++ b/axes/tests.py @@ -64,12 +64,12 @@ class AccessAttemptTest(TestCase): for i in range(0, FAILURE_LIMIT): response = self._login(existing_username=existing_username) # Check if we are in the same login page - self.assertIn(LOGIN_FORM_KEY, response.content) + self.assertIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) # So, we shouldn't have gotten a lock-out yet. # But we should get one now response = self._login() - self.assertIn(self.LOCKED_MESSAGE, response.content) + self.assertIn(self.LOCKED_MESSAGE, response.content.decode('utf-8')) def test_with_real_username_max(self): """Tests the login lock with a real username @@ -83,7 +83,7 @@ class AccessAttemptTest(TestCase): for i in range(0, FAILURE_LIMIT): response = self._login(existing_username=existing_username) # Check if we are in the same login page - self.assertIn(LOGIN_FORM_KEY, response.content) + self.assertIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) # So, we shouldn't have gotten a lock-out yet. # But we should get one now @@ -91,7 +91,7 @@ class AccessAttemptTest(TestCase): # try to log in a bunch of times response = self._login() - self.assertIn(self.LOCKED_MESSAGE, response.content) + self.assertIn(self.LOCKED_MESSAGE, response.content.decode('utf-8')) def test_with_real_username_max_with_more(self): """Tests the login lock for a bunch of times with a real username @@ -108,7 +108,7 @@ class AccessAttemptTest(TestCase): 'this_is_the_login_form': 1, }) - self.assertNotIn(LOGIN_FORM_KEY, response.content) + self.assertNotIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) def _successful_login(self, username, password): c = Client() @@ -135,7 +135,7 @@ class AccessAttemptTest(TestCase): # Test successful login, this makes the user trusted. response = self._successful_login(valid_username, valid_username) - self.assertNotIn(LOGIN_FORM_KEY, response.content) + self.assertNotIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) self.test_cooling_off(username=valid_username) @@ -150,18 +150,18 @@ class AccessAttemptTest(TestCase): response = self._unsuccessful_login(valid_username) # Check if we are in the same login page - self.assertIn(LOGIN_FORM_KEY, response.content) + self.assertIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) # Lock out the user response = self._unsuccessful_login(valid_username) - self.assertIn(self.LOCKED_MESSAGE, response.content) + self.assertIn(self.LOCKED_MESSAGE, response.content.decode('utf-8')) # Wait for the cooling off period time.sleep(COOLOFF_TIME.total_seconds()) # It should be possible to login again, make sure it is. response = self._successful_login(valid_username, valid_username) - self.assertNotIn(self.LOCKED_MESSAGE, response.content) + self.assertNotIn(self.LOCKED_MESSAGE, response.content.decode('utf-8')) def test_valid_logout(self): """Tests a valid logout and make sure the logout_time is updated @@ -179,7 +179,7 @@ class AccessAttemptTest(TestCase): self.assertNotEquals(AccessLog.objects.latest('id').logout_time, None) - self.assertIn('Logged out', response.content) + self.assertIn('Logged out', response.content.decode('utf-8')) def test_long_user_agent_valid(self): """Tests if can handle a long user agent @@ -192,7 +192,7 @@ class AccessAttemptTest(TestCase): 'this_is_the_login_form': 1, }, HTTP_USER_AGENT=long_user_agent) - self.assertNotIn(LOGIN_FORM_KEY, response.content) + self.assertNotIn(LOGIN_FORM_KEY, response.content.decode('utf-8')) def test_long_user_agent_not_valid(self): """Tests if can handle a long user agent with failure @@ -206,7 +206,7 @@ class AccessAttemptTest(TestCase): self.assertContains(response, LOGIN_FORM_KEY) response = self._login() - self.assertIn(self.LOCKED_MESSAGE, response.content) + self.assertIn(self.LOCKED_MESSAGE, response.content.decode('utf-8')) def test_reset_ip(self): """Tests if can reset an ip address