-
Notifications
You must be signed in to change notification settings - Fork 819
#898 Added the ability to customize classes for django admin #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4748dee
#898 Added the ability to customize classes for django admin
folt 521d053
#898 fix line too long
folt 74782f7
#898 fix flake8 style
folt b5d5250
#898 fix flake8 style
folt d59b0c2
#898 fix flake8 style
folt d9d4341
#898 add test for import error
folt 4947989
#898 add test custom admin class
folt abcad5a
#898 fix flake8 style
folt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
| from django.contrib import admin | ||
|
|
||
|
|
||
| class CustomApplicationAdmin(admin.ModelAdmin): | ||
| list_display = ("id",) | ||
|
|
||
|
|
||
| class CustomAccessTokenAdmin(admin.ModelAdmin): | ||
| list_display = ("id",) | ||
|
|
||
|
|
||
| class CustomGrantAdmin(admin.ModelAdmin): | ||
| list_display = ("id",) | ||
|
|
||
|
|
||
| class CustomRefreshTokenAdmin(admin.ModelAdmin): | ||
| list_display = ("id",) |
This file contains hidden or 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,90 @@ | ||
| from django.test import TestCase | ||
| from django.test.utils import override_settings | ||
|
|
||
| from oauth2_provider.admin import ( | ||
| get_access_token_admin_class, | ||
| get_application_admin_class, | ||
| get_grant_admin_class, | ||
| get_refresh_token_admin_class, | ||
| ) | ||
| from oauth2_provider.settings import OAuth2ProviderSettings, oauth2_settings | ||
| from tests.admin import ( | ||
| CustomAccessTokenAdmin, | ||
| CustomApplicationAdmin, | ||
| CustomGrantAdmin, | ||
| CustomRefreshTokenAdmin, | ||
| ) | ||
|
|
||
|
|
||
| class TestAdminClass(TestCase): | ||
| def test_import_error_message_maintained(self): | ||
| """ | ||
| Make sure import errors are captured and raised sensibly. | ||
| """ | ||
| settings = OAuth2ProviderSettings({"CLIENT_ID_GENERATOR_CLASS": "invalid_module.InvalidClassName"}) | ||
| with self.assertRaises(ImportError): | ||
| settings.CLIENT_ID_GENERATOR_CLASS | ||
|
|
||
| def test_get_application_admin_class(self): | ||
| """ | ||
| Test for getting class for application admin. | ||
| """ | ||
| application_admin_class = get_application_admin_class() | ||
| default_application_admin_class = oauth2_settings.APPLICATION_ADMIN_CLASS | ||
| assert application_admin_class == default_application_admin_class | ||
|
|
||
| def test_get_access_token_admin_class(self): | ||
| """ | ||
| Test for getting class for access token admin. | ||
| """ | ||
| access_token_admin_class = get_access_token_admin_class() | ||
| default_access_token_admin_class = oauth2_settings.ACCESS_TOKEN_ADMIN_CLASS | ||
| assert access_token_admin_class == default_access_token_admin_class | ||
|
|
||
| def test_get_grant_admin_class(self): | ||
| """ | ||
| Test for getting class for grant admin. | ||
| """ | ||
| grant_admin_class = get_grant_admin_class() | ||
| default_grant_admin_class = oauth2_settings.GRANT_ADMIN_CLASS | ||
| assert grant_admin_class, default_grant_admin_class | ||
|
|
||
| def test_get_refresh_token_admin_class(self): | ||
| """ | ||
| Test for getting class for refresh token admin. | ||
| """ | ||
| refresh_token_admin_class = get_refresh_token_admin_class() | ||
| default_refresh_token_admin_class = oauth2_settings.REFRESH_TOKEN_ADMIN_CLASS | ||
| assert refresh_token_admin_class == default_refresh_token_admin_class | ||
|
|
||
| @override_settings(OAUTH2_PROVIDER={"APPLICATION_ADMIN_CLASS": "tests.admin.CustomApplicationAdmin"}) | ||
| def test_get_custom_application_admin_class(self): | ||
| """ | ||
| Test for getting custom class for application admin. | ||
| """ | ||
| application_admin_class = get_application_admin_class() | ||
| assert application_admin_class == CustomApplicationAdmin | ||
|
|
||
| @override_settings(OAUTH2_PROVIDER={"ACCESS_TOKEN_ADMIN_CLASS": "tests.admin.CustomAccessTokenAdmin"}) | ||
| def test_get_custom_access_token_admin_class(self): | ||
| """ | ||
| Test for getting custom class for access token admin. | ||
| """ | ||
| access_token_admin_class = get_access_token_admin_class() | ||
| assert access_token_admin_class == CustomAccessTokenAdmin | ||
|
|
||
| @override_settings(OAUTH2_PROVIDER={"GRANT_ADMIN_CLASS": "tests.admin.CustomGrantAdmin"}) | ||
| def test_get_custom_grant_admin_class(self): | ||
| """ | ||
| Test for getting custom class for grant admin. | ||
| """ | ||
| grant_admin_class = get_grant_admin_class() | ||
| assert grant_admin_class == CustomGrantAdmin | ||
|
|
||
| @override_settings(OAUTH2_PROVIDER={"REFRESH_TOKEN_ADMIN_CLASS": "tests.admin.CustomRefreshTokenAdmin"}) | ||
| def test_get_custom_refresh_token_admin_class(self): | ||
| """ | ||
| Test for getting custom class for refresh token admin. | ||
| """ | ||
| refresh_token_admin_class = get_refresh_token_admin_class() | ||
| assert refresh_token_admin_class == CustomRefreshTokenAdmin |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you decided to pass DEFAULTS if we're not passing anything? This looks legit to me, tho I am wondering why it was {} and not DEFAULTS before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the library settings are very similar to the django-rest-framework settings.
My changes are inspired from there
This will allow tests to cover configuration errors. Previously, there were no tests for settings at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, thanks!