-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for LoginRequiredMiddleware, login_not_required decorator
- Loading branch information
1 parent
e3f2418
commit d22d0ac
Showing
7 changed files
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
try: | ||
from django.contrib.auth.decorators import login_not_required | ||
except ImportError: | ||
# For Django < 5.1, copy the current Django implementation | ||
def login_not_required(view_func): | ||
""" | ||
Decorator for views that allows access to unauthenticated requests. | ||
""" | ||
view_func.login_required = False | ||
return view_func |
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
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,39 @@ | ||
import unittest | ||
|
||
import django | ||
from django.test import SimpleTestCase, override_settings | ||
from django.urls import reverse | ||
|
||
|
||
@unittest.skipIf( | ||
django.VERSION < (5, 1), | ||
"Valid on Django 5.1 and above, requires LoginRequiredMiddleware", | ||
) | ||
@override_settings( | ||
DEBUG=True, | ||
MIDDLEWARE=[ | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
"django.contrib.auth.middleware.LoginRequiredMiddleware", | ||
"debug_toolbar.middleware.DebugToolbarMiddleware", | ||
], | ||
) | ||
class LoginNotRequiredTestCase(SimpleTestCase): | ||
def test_panels(self): | ||
for uri in ( | ||
"history_sidebar", | ||
"history_refresh", | ||
"sql_select", | ||
"sql_explain", | ||
"sql_profile", | ||
"template_source", | ||
): | ||
with self.subTest(uri=uri): | ||
response = self.client.get(reverse(f"djdt:{uri}")) | ||
self.assertNotEqual(response.status_code, 200) | ||
|
||
def test_render_panel(self): | ||
response = self.client.get( | ||
reverse("djdt:render_panel"), query_params={"store_id": "store_id"} | ||
) | ||
self.assertEqual(response.status_code, 200) |