-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2266] Refactor setup to use env variables directly
- Loading branch information
Showing
3 changed files
with
114 additions
and
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
from unittest.mock import patch | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.core.management import call_command | ||
from django.test import TestCase, override_settings | ||
|
||
from open_inwoner.configurations.choices import ColorTypeChoices | ||
|
@@ -7,84 +10,83 @@ | |
from ...bootstrap.siteconfig import SiteConfigurationStep | ||
|
||
|
||
@override_settings( | ||
SITE_NAME="My site", | ||
SITE_SECONDARY_COLOR="#000000", | ||
SITE_ACCENT_COLOR="#000000", | ||
SITE_PRIMARY_FONT_COLOR="#111111", | ||
SITE_SECONDARY_FONT_COLOR="#222222", | ||
SITE_ACCENT_FONT_COLOR="#333333", | ||
SITE_WARNING_BANNER_ENABLED="True", | ||
SITE_WARNING_BANNER_TEXT="warning banner text", | ||
SITE_WARNING_BANNER_BACKGROUND_COLOR="#444444", | ||
SITE_WARNING_BANNER_FONT_COLOR="#555555", | ||
SITE_LOGIN_SHOW=False, | ||
SITE_LOGIN_ALLOW_REGISTRATION=True, | ||
SITE_LOGIN_2FA_SMS=True, | ||
SITE_LOGIN_TEXT="login text", | ||
SITE_REGISTRATION_TEXT="registration text", | ||
SITE_HOME_WELCOME_TITLE="welcome title", | ||
SITE_HOME_WELCOME_INTRO="welcome intro", | ||
SITE_HOME_THEME_TITLE="home theme title", | ||
SITE_HOME_THEME_INTRO="home theme intro", | ||
SITE_THEME_TITLE="theme title", | ||
SITE_THEME_INTRO="theme intro", | ||
SITE_HOME_MAP_TITLE="home map title", | ||
SITE_HOME_MAP_INTRO="home map intro", | ||
SITE_HOME_QUESTIONNAIRE_TITLE="home questionnaire title", | ||
SITE_HOME_QUESTIONNAIRE_INTRO="home questionnaire intro", | ||
SITE_HOME_PRODUCT_FINDER_TITLE="home product finder title", | ||
SITE_HOME_PRODUCT_FINDER_INTRO="home product finder intro", | ||
SITE_SELECT_QUESTIONNAIRE_TITLE="select questionnaire title", | ||
SITE_SELECT_QUESTIONNAIRE_INTRO="select questionnaire intro", | ||
SITE_PLANS_INTRO="plans intro", | ||
SITE_PLANS_NO_PLANS_MESSAGE="plans no plans_message", | ||
SITE_PLANS_EDIT_MESSAGE="plans edit message", | ||
SITE_FOOTER_LOGO_TITLE="footer logo title", | ||
SITE_FOOTER_LOGO_URL="footer logo url", | ||
SITE_HOME_HELP_TEXT="home help text", | ||
SITE_THEME_HELP_TEXT="theme help text", | ||
SITE_PRODUCT_HELP_TEXT="product help text", | ||
SITE_SEARCH_HELP_TEXT="search help text", | ||
SITE_ACCOUNT_HELP_TEXT="account help text", | ||
SITE_QUESTIONNAIRE_HELP_TEXT="questionnaire help text", | ||
SITE_PLAN_HELP_TEXT="plan help text", | ||
SITE_SEARCH_FILTER_CATEGORIES=False, | ||
SITE_SEARCH_FILTER_TAGS=False, | ||
SITE_SEARCH_FILTER_ORGANIZATIONS=False, | ||
SITE_EMAIL_NEW_MESSAGE=False, | ||
SITE_RECIPIENTS_EMAIL_DIGEST=["[email protected]", "[email protected]"], | ||
SITE_CONTACT_PHONENUMBER="12345", | ||
SITE_CONTACT_PAGE="https://test.test", | ||
SITE_GTM_CODE="gtm code", | ||
SITE_GA_CODE="ga code", | ||
SITE_MATOMO_URL="matomo url", | ||
SITE_MATOMO_SITE_ID=88, | ||
SITE_SITEIMPROVE_ID="88", | ||
SITE_COOKIE_INFO_TEXT="cookie info text", | ||
SITE_COOKIE_LINK_TEXT="cookie link text", | ||
SITE_COOKIE_LINK_URL="cookie link url", | ||
SITE_KCM_SURVEY_LINK_TEXT="kcm survey link text", | ||
SITE_KCM_SURVEY_LINK_URL="kcm survey link url", | ||
SITE_OPENID_CONNECT_LOGIN_TEXT="openid connect login_text", | ||
SITE_OPENID_DISPLAY="openid display", | ||
SITE_REDIRECT_TO="redirect to", | ||
SITE_ALLOW_MESSAGES_FILE_SHARING=False, | ||
SITE_HIDE_CATEGORIES_FROM_ANONYMOUS_USERS=True, | ||
SITE_HIDE_SEARCH_FROM_ANONYMOUS_USERS=True, | ||
SITE_DISPLAY_SOCIAL=False, | ||
SITE_EHERKENNING_ENABLED=True, | ||
) | ||
class SiteConfigurationSetupTest(TestCase): | ||
def test_site_configure(self): | ||
configuration_step = SiteConfigurationStep() | ||
|
||
configuration_step.configure() | ||
patch_dict = { | ||
"SITE_NAME": "My site", | ||
"SITE_SECONDARY_COLOR": "#000000", | ||
"SITE_ACCENT_COLOR": "#000000", | ||
"SITE_PRIMARY_FONT_COLOR": "#111111", | ||
"SITE_SECONDARY_FONT_COLOR": "#222222", | ||
"SITE_ACCENT_FONT_COLOR": "#333333", | ||
"SITE_WARNING_BANNER_ENABLED": "True", | ||
"SITE_WARNING_BANNER_TEXT": "warning banner text", | ||
"SITE_WARNING_BANNER_BACKGROUND_COLOR": "#444444", | ||
"SITE_WARNING_BANNER_FONT_COLOR": "#555555", | ||
"SITE_LOGIN_SHOW": "False", | ||
"SITE_LOGIN_ALLOW_REGISTRATION": "True", | ||
"SITE_LOGIN_2FA_SMS": "True", | ||
"SITE_LOGIN_TEXT": "login text", | ||
"SITE_REGISTRATION_TEXT": "registration text", | ||
"SITE_HOME_WELCOME_TITLE": "welcome title", | ||
"SITE_HOME_WELCOME_INTRO": "welcome intro", | ||
"SITE_HOME_THEME_TITLE": "home theme title", | ||
"SITE_HOME_THEME_INTRO": "home theme intro", | ||
"SITE_THEME_TITLE": "theme title", | ||
"SITE_THEME_INTRO": "theme intro", | ||
"SITE_HOME_MAP_TITLE": "home map title", | ||
"SITE_HOME_MAP_INTRO": "home map intro", | ||
"SITE_HOME_QUESTIONNAIRE_TITLE": "home questionnaire title", | ||
"SITE_HOME_QUESTIONNAIRE_INTRO": "home questionnaire intro", | ||
"SITE_HOME_PRODUCT_FINDER_TITLE": "home product finder title", | ||
"SITE_HOME_PRODUCT_FINDER_INTRO": "home product finder intro", | ||
"SITE_SELECT_QUESTIONNAIRE_TITLE": "select questionnaire title", | ||
"SITE_SELECT_QUESTIONNAIRE_INTRO": "select questionnaire intro", | ||
"SITE_PLANS_INTRO": "plans intro", | ||
"SITE_PLANS_NO_PLANS_MESSAGE": "plans no plans_message", | ||
"SITE_PLANS_EDIT_MESSAGE": "plans edit message", | ||
"SITE_FOOTER_LOGO_TITLE": "footer logo title", | ||
"SITE_FOOTER_LOGO_URL": "footer logo url", | ||
"SITE_HOME_HELP_TEXT": "home help text", | ||
"SITE_THEME_HELP_TEXT": "theme help text", | ||
"SITE_PRODUCT_HELP_TEXT": "product help text", | ||
"SITE_SEARCH_HELP_TEXT": "search help text", | ||
"SITE_ACCOUNT_HELP_TEXT": "account help text", | ||
"SITE_QUESTIONNAIRE_HELP_TEXT": "questionnaire help text", | ||
"SITE_PLAN_HELP_TEXT": "plan help text", | ||
"SITE_SEARCH_FILTER_CATEGORIES": "False", | ||
"SITE_SEARCH_FILTER_TAGS": "False", | ||
"SITE_SEARCH_FILTER_ORGANIZATIONS": "False", | ||
"SITE_EMAIL_NEW_MESSAGE": "False", | ||
"SITE_RECIPIENTS_EMAIL_DIGEST": "[email protected],[email protected]", | ||
"SITE_CONTACT_PHONENUMBER": "12345", | ||
"SITE_CONTACT_PAGE": "https://test.test", | ||
"SITE_GTM_CODE": "gtm code", | ||
"SITE_GA_CODE": "ga code", | ||
"SITE_MATOMO_URL": "matomo url", | ||
"SITE_MATOMO_SITE_ID": "88", | ||
"SITE_SITEIMPROVE_ID": "88", | ||
"SITE_COOKIE_INFO_TEXT": "cookie info text", | ||
"SITE_COOKIE_LINK_TEXT": "cookie link text", | ||
"SITE_COOKIE_LINK_URL": "cookie link url", | ||
"SITE_KCM_SURVEY_LINK_TEXT": "kcm survey link text", | ||
"SITE_KCM_SURVEY_LINK_URL": "kcm survey link url", | ||
"SITE_OPENID_CONNECT_LOGIN_TEXT": "openid connect login_text", | ||
"SITE_OPENID_DISPLAY": "openid display", | ||
"SITE_REDIRECT_TO": "redirect to", | ||
"SITE_ALLOW_MESSAGES_FILE_SHARING": "False", | ||
"SITE_HIDE_CATEGORIES_FROM_ANONYMOUS_USERS": "True", | ||
"SITE_HIDE_SEARCH_FROM_ANONYMOUS_USERS": "True", | ||
"SITE_DISPLAY_SOCIAL": "False", | ||
"SITE_EHERKENNING_ENABLED": "True", | ||
} | ||
with patch.dict("os.environ", patch_dict): | ||
args = [] | ||
opts = {"overwrite": True} | ||
call_command("setup_configuration", *args, **opts) | ||
|
||
config = SiteConfiguration.get_solo() | ||
|
||
self.assertTrue(configuration_step.is_configured()) | ||
|
||
self.assertEqual(config.name, "My site") | ||
self.assertEqual(config.secondary_color, "#000000"), | ||
self.assertEqual(config.accent_color, "#000000"), | ||
|
@@ -158,19 +160,13 @@ def test_site_configure(self): | |
self.assertFalse(config.display_social), | ||
self.assertTrue(config.eherkenning_enabled), | ||
|
||
@override_settings( | ||
SITE_NAME="My site", | ||
SITE_SECONDARY_COLOR="#000000", | ||
SITE_ACCENT_COLOR="#000000", | ||
SITE_PRIMARY_FONT_COLOR=None, | ||
SITE_SECONDARY_FONT_COLOR=None, | ||
SITE_ACCENT_FONT_COLOR=None, | ||
SITE_WARNING_BANNER_ENABLED=None, | ||
) | ||
def test_site_configure_use_defaults(self): | ||
configuration_step = SiteConfigurationStep() | ||
patch_dict = {} | ||
|
||
configuration_step.configure() | ||
with patch.dict("os.environ", patch_dict): | ||
args = [] | ||
opts = {"overwrite": True} | ||
call_command("setup_configuration", *args, **opts) | ||
|
||
config = SiteConfiguration.get_solo() | ||
|
||
|
@@ -182,6 +178,7 @@ def test_site_configure_use_defaults(self): | |
|
||
@override_settings( | ||
SITE_NAME=None, | ||
SITE_PRIMARY_COLOR="#000000", | ||
SITE_SECONDARY_COLOR="#000000", | ||
SITE_ACCENT_COLOR="#111111", | ||
) | ||
|
@@ -192,14 +189,15 @@ def test_site_not_configured(self): | |
|
||
self.assertFalse(configuration_step.is_configured()) | ||
|
||
@override_settings( | ||
SITE_NAME="My site", | ||
SITE_SECONDARY_COLOR="#000000", | ||
SITE_ACCENT_COLOR="#111111", | ||
SITE_LOGIN_SHOW="Should be boolean", | ||
) | ||
def test_site_configure_error(self): | ||
configuration_step = SiteConfigurationStep() | ||
|
||
patch_dict = { | ||
"SITE_NAME": "My site", | ||
"SITE_SECONDARY_COLOR": "#000000", | ||
"SITE_ACCENT_COLOR": "#000000", | ||
"SITE_LOGIN_SHOW": "Should be boolean", | ||
} | ||
with self.assertRaises(ValidationError): | ||
configuration_step.configure() | ||
with patch.dict("os.environ", patch_dict): | ||
args = [] | ||
opts = {"overwrite": True} | ||
call_command("setup_configuration", *args, **opts) |