-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aa696d
commit 59bf35e
Showing
3 changed files
with
128 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
from django.core.management.utils import get_random_secret_key | ||
|
||
SECRET_KEY = get_random_secret_key() | ||
|
||
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}} | ||
|
||
INSTALLED_APPS = [ | ||
"django.contrib.auth", | ||
"django.contrib.contenttypes", | ||
] | ||
|
||
USE_TZ = 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,115 @@ | ||
from django.test import TestCase | ||
from django.test.client import RequestFactory | ||
from django.test.utils import override_settings | ||
from unfold.settings import CONFIG_DEFAULTS, get_config | ||
from unfold.sites import UnfoldAdminSite | ||
|
||
|
||
def deny_permission(request): | ||
return False | ||
|
||
|
||
def allow_permission(request): | ||
return True | ||
|
||
|
||
class NavigationTestCase(TestCase): | ||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"TABS": [ | ||
{ | ||
"items": [ | ||
{ | ||
"title": "Example Title", | ||
"link": "https://example.com", | ||
"permission": lambda request: False, | ||
} | ||
], | ||
} | ||
] | ||
}, | ||
} | ||
) | ||
def test_check_tab_lambda_deny_permission(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
tabs = admin_site.get_tabs_list(request) | ||
self.assertEqual(len(tabs[0]["items"]), 0) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"TABS": [ | ||
{ | ||
"items": [ | ||
{ | ||
"title": "Example Title", | ||
"link": "https://example.com", | ||
"permission": lambda request: True, | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
} | ||
) | ||
def test_check_tab_lambda_allow_permission(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
tabs = admin_site.get_tabs_list(request) | ||
self.assertEqual(len(tabs[0]["items"]), 1) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"TABS": [ | ||
{ | ||
"items": [ | ||
{ | ||
"title": "Example Title", | ||
"link": "https://example.com", | ||
"permission": "tests.test_navigations.deny_permission", | ||
} | ||
], | ||
} | ||
] | ||
}, | ||
} | ||
) | ||
def test_check_tab_path_deny_permission(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
tabs = admin_site.get_tabs_list(request) | ||
self.assertEqual(len(tabs[0]["items"]), 0) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"TABS": [ | ||
{ | ||
"items": [ | ||
{ | ||
"title": "Example Title", | ||
"link": "https://example.com", | ||
"permission": "tests.test_navigations.allow_permission", | ||
} | ||
], | ||
} | ||
] | ||
}, | ||
} | ||
) | ||
def test_check_tab_path_allow_permission(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
tabs = admin_site.get_tabs_list(request) | ||
self.assertEqual(len(tabs[0]["items"]), 1) | ||
get_config.cache_clear() |