-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from UW-GAC/feature/app-settings-defaults
Store app settings (with some defaults in a separate file)
- Loading branch information
Showing
16 changed files
with
273 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.23.1.dev2" | ||
__version__ = "0.23.1.dev3" |
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,69 @@ | ||
# App settings. | ||
# Mostly follows django-allauth: | ||
# https://github.com/pennersr/django-allauth/blob/main/allauth/app_settings.py | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
class AppSettings(object): | ||
"""Class to handle settings for django-anvil-consortium-manager.""" | ||
|
||
def __init__(self, prefix): | ||
self.prefix = prefix | ||
|
||
def _setting(self, name, default=None): | ||
from django.conf import settings | ||
|
||
return getattr(settings, self.prefix + name, default) | ||
|
||
@property | ||
def API_SERVICE_ACCOUNT_FILE(self): | ||
"""The path to the service account to use for managing access on AnVIL. Required.""" | ||
x = self._setting("API_SERVICE_ACCOUNT_FILE") | ||
if not x: | ||
raise ImproperlyConfigured("ANVIL_API_SERVICE_ACCOUNT_FILE is required in settings.py") | ||
return x | ||
|
||
@property | ||
def WORKSPACE_ADAPTERS(self): | ||
"""Workspace adapters. Required.""" | ||
x = self._setting("WORKSPACE_ADAPTERS") | ||
if not x: | ||
msg = ( | ||
"ANVIL_WORKSPACE_ADAPTERS must specify at least one adapter. Did you mean to use " | ||
"the default `anvil_consortium_manager.adapters.default.DefaultWorkspaceAdapter`?" | ||
) | ||
raise ImproperlyConfigured(msg) | ||
return x | ||
|
||
@property | ||
def ACCOUNT_LINK_EMAIL_SUBJECT(self): | ||
"""Subject line for AnVIL account verification emails. Default: 'Verify your AnVIL account email'""" | ||
return self._setting("ACCOUNT_LINK_EMAIL_SUBJECT", "Verify your AnVIL account email") | ||
|
||
@property | ||
def ACCOUNT_LINK_REDIRECT(self): | ||
"""The URL for AccountLinkVerify view redirect. Default: settings.LOGIN_REDIRECT_URL.""" | ||
return self._setting("ACCOUNT_LINK_REDIRECT", settings.LOGIN_REDIRECT_URL) | ||
|
||
@property | ||
def ACCOUNT_VERIFY_NOTIFICATION_EMAIL(self): | ||
"""If desired, specify the email address to send an email to after a user verifies an account. Default: None. | ||
Set to None to disable (default). | ||
""" | ||
return self._setting("ACCOUNT_VERIFY_NOTIFICATION_EMAIL", None) | ||
|
||
@property | ||
def ACCOUNT_ADAPTER(self): | ||
"""Account adapter. Default: anvil_consortium_manager.adapters.default.DefaultAccountAdapter.""" | ||
return self._setting("ACCOUNT_ADAPTER", "anvil_consortium_manager.adapters.default.DefaultAccountAdapter") | ||
|
||
|
||
_app_settings = AppSettings("ANVIL_") | ||
|
||
|
||
def __getattr__(name): | ||
# See https://peps.python.org/pep-0562/ | ||
return getattr(_app_settings, name) |
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,76 @@ | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
|
||
from .. import app_settings | ||
|
||
|
||
class TestAppSettings(TestCase): | ||
def test_api_service_account_file(self): | ||
# Using test settings. | ||
self.assertEqual(app_settings.API_SERVICE_ACCOUNT_FILE, "foo") | ||
|
||
@override_settings(ANVIL_API_SERVICE_ACCOUNT_FILE=None) | ||
def test_api_service_account_file_none(self): | ||
with self.assertRaisesMessage( | ||
ImproperlyConfigured, "ANVIL_API_SERVICE_ACCOUNT_FILE is required in settings.py" | ||
): | ||
app_settings.API_SERVICE_ACCOUNT_FILE | ||
|
||
def test_workspace_adapters(self): | ||
# Using test settings. | ||
self.assertEqual( | ||
app_settings.WORKSPACE_ADAPTERS, ["anvil_consortium_manager.adapters.default.DefaultWorkspaceAdapter"] | ||
) | ||
|
||
@override_settings(ANVIL_WORKSPACE_ADAPTERS=None) | ||
def test_workspace_adapters_none(self): | ||
with self.assertRaisesMessage(ImproperlyConfigured, "must specify at least one adapter"): | ||
app_settings.WORKSPACE_ADAPTERS | ||
|
||
@override_settings(ANVIL_WORKSPACE_ADAPTERS=[]) | ||
def test_workspace_adapters_empty_array(self): | ||
with self.assertRaisesMessage(ImproperlyConfigured, "must specify at least one adapter"): | ||
app_settings.WORKSPACE_ADAPTERS | ||
|
||
@override_settings( | ||
ANVIL_WORKSPACE_ADAPTERS=[ | ||
"anvil_consortium_manager.adapters.default.DefaultWorkspaceAdapter", | ||
"anvil_consortium_manager.tests.test_app.adapters.TestWorkspaceAdapter", | ||
] | ||
) | ||
def test_workspace_adapters_multiple(self): | ||
adapters = app_settings.WORKSPACE_ADAPTERS | ||
self.assertEqual(len(adapters), 2) | ||
self.assertIn("anvil_consortium_manager.adapters.default.DefaultWorkspaceAdapter", adapters) | ||
self.assertIn("anvil_consortium_manager.tests.test_app.adapters.TestWorkspaceAdapter", adapters) | ||
|
||
def test_account_link_email_subject(self): | ||
self.assertEqual(app_settings.ACCOUNT_LINK_EMAIL_SUBJECT, "Verify your AnVIL account email") | ||
|
||
@override_settings(ANVIL_ACCOUNT_LINK_EMAIL_SUBJECT="account activation") | ||
def test_account_link_email_subject_custom(self): | ||
self.assertEqual(app_settings.ACCOUNT_LINK_EMAIL_SUBJECT, "account activation") | ||
|
||
def test_account_link_redirect(self): | ||
self.assertEqual(app_settings.ACCOUNT_LINK_REDIRECT, "test_home") | ||
|
||
@override_settings(ANVIL_ACCOUNT_LINK_REDIRECT="test_login") | ||
def test_account_link_redirect_custom(self): | ||
self.assertEqual(app_settings.ACCOUNT_LINK_REDIRECT, "test_login") | ||
|
||
def test_account_verify_notification_email(self): | ||
self.assertEqual(app_settings.ACCOUNT_VERIFY_NOTIFICATION_EMAIL, None) | ||
|
||
@override_settings(ANVIL_ACCOUNT_VERIFY_NOTIFICATION_EMAIL="[email protected]") | ||
def test_account_verify_notification_email_custom(self): | ||
self.assertEqual(app_settings.ACCOUNT_VERIFY_NOTIFICATION_EMAIL, "[email protected]") | ||
|
||
def test_account_adapter(self): | ||
self.assertEqual( | ||
app_settings.ACCOUNT_ADAPTER, "anvil_consortium_manager.adapters.default.DefaultAccountAdapter" | ||
) | ||
|
||
@override_settings(ANVIL_ACCOUNT_ADAPTER="anvil_consortium_manager.test_app.adapters.TestAccountAdapter") | ||
def test_account_adapter_custom(self): | ||
self.assertEqual(app_settings.ACCOUNT_ADAPTER, "anvil_consortium_manager.test_app.adapters.TestAccountAdapter") |
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
Oops, something went wrong.