-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow renew_token as pluggable and tests for same
- Loading branch information
Showing
3 changed files
with
62 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,20 +24,19 @@ | |
refresh_url = reverse("durin_refresh") | ||
|
||
new_settings = durin_settings.defaults.copy() | ||
EXPIRY_DATETIME_FORMAT = "%H:%M %d/%m/%y" | ||
new_settings["EXPIRY_DATETIME_FORMAT"] = EXPIRY_DATETIME_FORMAT | ||
|
||
|
||
class AuthTestCase(APITestCase): | ||
def setUp(self): | ||
self.authclient = Client.objects.create(name="authclientfortest") | ||
username = "john.doe" | ||
email = "[email protected]" | ||
password = "hunter2" | ||
self.user = User.objects.create_user(username, email, password) | ||
self.creds = { | ||
"username": username, | ||
"password": password, | ||
"client": "authclientfortest", | ||
"client": self.authclient.name, | ||
} | ||
|
||
username2 = "jane.doe" | ||
|
@@ -47,11 +46,10 @@ def setUp(self): | |
self.creds2 = { | ||
"username": username2, | ||
"password": password2, | ||
"client": "authclientfortest", | ||
"client": self.authclient.name, | ||
} | ||
|
||
self.client_names = ["web", "mobile", "cli"] | ||
self.authclient = Client.objects.create(name="authclientfortest") | ||
|
||
def test_create_clients(self): | ||
self.assertEqual(Client.objects.count(), 1) | ||
|
@@ -114,7 +112,8 @@ def test_login_returns_serialized_token_and_username_field(self): | |
|
||
def test_login_returns_configured_expiry_datetime_format(self): | ||
self.assertEqual(AuthToken.objects.count(), 0) | ||
|
||
EXPIRY_DATETIME_FORMAT = "%H:%M %d/%m/%y" | ||
new_settings["EXPIRY_DATETIME_FORMAT"] = EXPIRY_DATETIME_FORMAT | ||
with override_settings(REST_DURIN=new_settings): | ||
reload(views) | ||
self.assertEqual( | ||
|
@@ -267,7 +266,7 @@ def test_invalid_auth_header_return_401(self): | |
resp2 = self.client.get(root_url) | ||
self.assertEqual(resp2.status_code, 401) | ||
|
||
def test_login_should_renew_token_for_existing_client(self): | ||
def test_login_same_token_existing_client(self): | ||
self.assertEqual(AuthToken.objects.count(), 0) | ||
resp1 = self.client.post(login_url, self.creds, format="json") | ||
self.assertEqual(resp1.status_code, 200) | ||
|
@@ -281,17 +280,46 @@ def test_login_should_renew_token_for_existing_client(self): | |
1, | ||
"should renew token, instead of creating new.", | ||
) | ||
self.assertNotEqual( | ||
self.assertEqual( | ||
resp1.data["expiry"], | ||
resp2.data["expiry"], | ||
"token expiry should be renewed by login", | ||
"token expiry should be same after login", | ||
) | ||
self.assertEqual( | ||
resp1.data["token"], | ||
resp2.data["token"], | ||
"login should return existing token", | ||
) | ||
|
||
def test_login_renew_token_existing_client(self): | ||
self.assertEqual(AuthToken.objects.count(), 0) | ||
new_settings["REFRESH_TOKEN_ON_LOGIN"] = True | ||
with override_settings(REST_DURIN=new_settings): | ||
reload(views) | ||
resp1 = self.client.post(login_url, self.creds, format="json") | ||
self.assertEqual(resp1.status_code, 200) | ||
self.assertIn("token", resp1.data) | ||
resp2 = self.client.post(login_url, self.creds, format="json") | ||
self.assertEqual(resp2.status_code, 200) | ||
self.assertIn("token", resp2.data) | ||
|
||
reload(views) | ||
self.assertEqual( | ||
AuthToken.objects.count(), | ||
1, | ||
"should renew token, instead of creating new.", | ||
) | ||
self.assertNotEqual( | ||
resp1.data["expiry"], | ||
resp2.data["expiry"], | ||
"token expiry should be renewed after login", | ||
) | ||
self.assertEqual( | ||
resp1.data["token"], | ||
resp2.data["token"], | ||
"token key must remain same", | ||
) | ||
|
||
def test_refresh_view_and_renewed_signal(self): | ||
self.signal_was_called = False | ||
|
||
|