From 4e2a9bd02ddd1cefa9e45348ec94b7eaeccdd541 Mon Sep 17 00:00:00 2001 From: Camilo Nova Date: Wed, 9 Apr 2014 07:11:02 -0500 Subject: [PATCH] Fixes object type issue, response is not an string --- axes/tests.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/axes/tests.py b/axes/tests.py index 3054594..11706e6 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.assertContains(response.content.decode('utf-8'), LOGIN_FORM_KEY) + self.assertContains(response, LOGIN_FORM_KEY) # So, we shouldn't have gotten a lock-out yet. # But we should get one now response = self._login() - self.assertContains(response.content.decode('utf-8'), self.LOCKED_MESSAGE) + self.assertContains(response, self.LOCKED_MESSAGE) 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.assertContains(response.content.decode('utf-8'), LOGIN_FORM_KEY) + self.assertContains(response, LOGIN_FORM_KEY) # 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.assertContains(response.content.decode('utf-8'), self.LOCKED_MESSAGE) + self.assertContains(response, self.LOCKED_MESSAGE) 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.assertNotContains(response.content.decode('utf-8'), LOGIN_FORM_KEY, status_code=302) + self.assertNotContains(response, LOGIN_FORM_KEY, status_code=302) 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.assertNotContains(response.content.decode('utf-8'), LOGIN_FORM_KEY, status_code=302) + self.assertNotContains(response, LOGIN_FORM_KEY, status_code=302) 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.assertContains(response.content.decode('utf-8'), LOGIN_FORM_KEY) + self.assertContains(response, LOGIN_FORM_KEY) # Lock out the user response = self._unsuccessful_login(valid_username) - self.assertContains(response.content.decode('utf-8'), self.LOCKED_MESSAGE) + self.assertContains(response, self.LOCKED_MESSAGE) # 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.assertNotContains(response.content.decode('utf-8'), self.LOCKED_MESSAGE, status_code=302) + self.assertNotContains(response, self.LOCKED_MESSAGE, status_code=302) 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.assertContains(response.content.decode('utf-8'), 'Logged out') + self.assertContains(response, 'Logged out') 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.assertNotContains(response.content.decode('utf-8'), LOGIN_FORM_KEY, status_code=302) + self.assertNotContains(response, LOGIN_FORM_KEY, status_code=302) 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.assertContains(response.content.decode('utf-8'), self.LOCKED_MESSAGE) + self.assertContains(response, self.LOCKED_MESSAGE) def test_reset_ip(self): """Tests if can reset an ip address