-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to reflect changes after Django 1.10: - is_authenticated is a property - authenticate() takes request param - change to reverse location - login and logout are now class-based views in `django.contrib.auth` - added test_middleware to confirm middleware match requests for login and logout views
- Loading branch information
Jordan Reiter
authored and
Jordan Reiter
committed
Mar 22, 2020
1 parent
b9a7658
commit bf1173a
Showing
7 changed files
with
75 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
try: | ||
from unittest import mock | ||
except ImportError: | ||
import mock | ||
|
||
from urllib.parse import quote_plus, urlencode | ||
|
||
from django.conf import settings | ||
from django.test import TestCase, Client, override_settings, modify_settings | ||
|
||
|
||
|
||
@override_settings(MIDDLEWARE=[ | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'cas.middleware.CASMiddleware' | ||
]) | ||
class CASBackendTest(TestCase): | ||
|
||
def setUp(self): | ||
from cas.tests import factories | ||
self.user = factories.UserFactory.create() | ||
self.client = Client() | ||
|
||
def test_login_calls_cas_login(self): | ||
resp = self.client.get('/login/') | ||
self.assertTrue(resp.has_header('Location')) | ||
expected_url = '{}/login?{}'.format( | ||
settings.CAS_SERVER_URL, | ||
urlencode({ | ||
'service': 'http://testserver/login/?next={}'.format(quote_plus('/')) | ||
}) | ||
) | ||
self.assertRedirects(resp, expected_url, fetch_redirect_response=False) | ||
|
||
def test_logout_calls_cas_logout(self): | ||
resp = self.client.get('/logout/') | ||
self.assertTrue(resp.has_header('Location')) | ||
expected_url = '{}/logout?{}'.format( | ||
settings.CAS_SERVER_URL, | ||
urlencode({ | ||
'service': 'http://testserver/' | ||
}) | ||
) | ||
self.assertRedirects(resp, expected_url, fetch_redirect_response=False) |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('', include('django.contrib.auth.urls')), | ||
] |
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