From 3bc273e1d5f652d1b0af3b753f7e443943d8c3c1 Mon Sep 17 00:00:00 2001 From: Maria Fernanda Magallanes Zubillaga Date: Wed, 21 Jun 2023 17:10:07 -0500 Subject: [PATCH] fix: add darklangmiddleware backend for test --- .../backends/dark_lang_middleware_o_test_v1.py | 9 +++++++++ .../backends/dark_lang_middleware_o_v1.py | 6 +++++- eox_tenant/settings/test.py | 1 + .../tenant_aware_functions/released_languages.py | 4 ++++ eox_tenant/tenant_wise/__init__.py | 2 +- eox_tenant/tenant_wise/proxies.py | 11 +++++------ 6 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_test_v1.py diff --git a/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_test_v1.py b/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_test_v1.py new file mode 100644 index 00000000..fa8a0be9 --- /dev/null +++ b/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_test_v1.py @@ -0,0 +1,9 @@ +""" +DarkLangMiddleware Backend for tests. +""" +from unittest.mock import MagicMock + + +def get_dark_lang_middleware(): + """Backend to get the DarkLangMiddleware from openedx.""" + return MagicMock() diff --git a/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_v1.py b/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_v1.py index d04b491d..4504131a 100644 --- a/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_v1.py +++ b/eox_tenant/edxapp_wrapper/backends/dark_lang_middleware_o_v1.py @@ -1,4 +1,8 @@ -from openedx.core.djangoapps.dark_lang.middleware import DarkLangMiddleware +""" +DarkLangMiddleware Backend. +""" +from openedx.core.djangoapps.dark_lang.middleware import DarkLangMiddleware # pylint: disable=import-error + def get_dark_lang_middleware(): """Backend to get the DarkLangMiddleware from openedx.""" diff --git a/eox_tenant/settings/test.py b/eox_tenant/settings/test.py index 61771c7b..4f13d6de 100644 --- a/eox_tenant/settings/test.py +++ b/eox_tenant/settings/test.py @@ -33,6 +33,7 @@ class SettingsClass: GET_THEMING_HELPERS = 'eox_tenant.edxapp_wrapper.backends.theming_helpers_test_v1' EOX_TENANT_USERS_BACKEND = 'eox_tenant.edxapp_wrapper.backends.users_test_v1' EOX_TENANT_BEARER_AUTHENTICATION = 'eox_tenant.edxapp_wrapper.backends.bearer_authentication_test_v1' +DARK_LANG_MIDDLEWARE = 'eox_tenant.edxapp_wrapper.backends.dark_lang_middleware_o_test_v1' COURSE_KEY_PATTERN = r'(?P[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)' COURSE_ID_PATTERN = COURSE_KEY_PATTERN.replace('course_key_string', 'course_id') diff --git a/eox_tenant/tenant_aware_functions/released_languages.py b/eox_tenant/tenant_aware_functions/released_languages.py index 6f996d02..f04553fe 100644 --- a/eox_tenant/tenant_aware_functions/released_languages.py +++ b/eox_tenant/tenant_aware_functions/released_languages.py @@ -1,9 +1,13 @@ +""" +Site/Tenant aware languages filter. +""" from collections import namedtuple from django.conf import settings Language = namedtuple('Language', 'code name') + def tenant_languages(): """Retrieve the list of released languages by tenant. diff --git a/eox_tenant/tenant_wise/__init__.py b/eox_tenant/tenant_wise/__init__.py index 3b89d194..ae98acb9 100644 --- a/eox_tenant/tenant_wise/__init__.py +++ b/eox_tenant/tenant_wise/__init__.py @@ -10,8 +10,8 @@ from django.conf import settings from eox_tenant.constants import LMS_ENVIRONMENT -from eox_tenant.tenant_wise.proxies import TenantSiteConfigProxy, DarkLangMiddlewareProxy from eox_tenant.tenant_aware_functions.released_languages import tenant_languages +from eox_tenant.tenant_wise.proxies import DarkLangMiddlewareProxy, TenantSiteConfigProxy def load_tenant_wise_overrides(): diff --git a/eox_tenant/tenant_wise/proxies.py b/eox_tenant/tenant_wise/proxies.py index 76354b8d..1327c864 100644 --- a/eox_tenant/tenant_wise/proxies.py +++ b/eox_tenant/tenant_wise/proxies.py @@ -8,10 +8,9 @@ import six from django.conf import settings from django.core.cache import cache -from eox_tenant.edxapp_wrapper.dark_lang_middleware import \ - get_dark_lang_middleware -from eox_tenant.edxapp_wrapper.site_configuration_module import \ - get_site_configuration_models + +from eox_tenant.edxapp_wrapper.dark_lang_middleware import get_dark_lang_middleware +from eox_tenant.edxapp_wrapper.site_configuration_module import get_site_configuration_models from eox_tenant.models import Microsite, TenantConfig, TenantOrganization from eox_tenant.utils import clean_serializable_values @@ -215,12 +214,12 @@ def released_langs(self): """ Current list of released languages from settings. """ - + language_options = getattr(settings, "released_languages", "") if settings.LANGUAGE_CODE not in language_options: language_options.append(settings.LANGUAGE_CODE) return language_options - + def process_request(self, request): """ This will be run when you do a request, and prevent user from requesting un-released languages.