Merge branch 'master' into private_to_public_319d54e
This commit is contained in:
@@ -11,7 +11,6 @@ from logging import getLogger
|
||||
import crum
|
||||
from django.conf import settings
|
||||
|
||||
from microsite_configuration import microsite
|
||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||
from openedx.core.djangoapps.theming.helpers_dirs import (
|
||||
Theme,
|
||||
@@ -28,15 +27,8 @@ logger = getLogger(__name__) # pylint: disable=invalid-name
|
||||
@request_cached()
|
||||
def get_template_path(relative_path, **kwargs):
|
||||
"""
|
||||
This is a proxy function to hide microsite_configuration behind comprehensive theming.
|
||||
|
||||
The calculated value is cached for the lifetime of the current request.
|
||||
"""
|
||||
# We need to give priority to theming over microsites
|
||||
# So, we apply microsite override only if there is no associated site theme
|
||||
# and associated microsite is present.
|
||||
if not current_request_has_associated_site_theme() and microsite.is_request_in_microsite():
|
||||
relative_path = microsite.get_template_path(relative_path, **kwargs)
|
||||
return relative_path
|
||||
|
||||
|
||||
@@ -45,18 +37,7 @@ def is_request_in_themed_site():
|
||||
This is a proxy function to hide microsite_configuration behind comprehensive theming.
|
||||
"""
|
||||
# We need to give priority to theming/site-configuration over microsites
|
||||
return configuration_helpers.is_site_configuration_enabled() or microsite.is_request_in_microsite()
|
||||
|
||||
|
||||
def get_template(uri):
|
||||
"""
|
||||
This is a proxy function to hide microsite_configuration behind comprehensive theming.
|
||||
:param uri: uri of the template
|
||||
"""
|
||||
# We need to give priority to theming over microsites
|
||||
# So, we apply microsite template override only when there is no associated theme,
|
||||
if not current_request_has_associated_site_theme():
|
||||
return microsite.get_template(uri)
|
||||
return configuration_helpers.is_site_configuration_enabled()
|
||||
|
||||
|
||||
def get_template_path_with_theme(relative_path):
|
||||
@@ -332,15 +313,9 @@ def is_comprehensive_theming_enabled():
|
||||
Returns:
|
||||
(bool): True if comprehensive theming is enabled else False
|
||||
"""
|
||||
# We need to give priority to theming over microsites
|
||||
if settings.ENABLE_COMPREHENSIVE_THEMING and current_request_has_associated_site_theme():
|
||||
return True
|
||||
|
||||
# Disable theming for microsites
|
||||
# Microsite configurations take priority over the default site theme.
|
||||
if microsite.is_request_in_microsite():
|
||||
return False
|
||||
|
||||
return settings.ENABLE_COMPREHENSIVE_THEMING
|
||||
|
||||
|
||||
|
||||
@@ -68,148 +68,43 @@ class TestHelpers(TestCase):
|
||||
Tests to make sure the is_comprehensive_theming_enabled function works as expected.
|
||||
Here are different scenarios that we need to test
|
||||
|
||||
1. Theming is enabled, there is a SiteTheme record and microsite configuration for the current site.
|
||||
1. Theming is enabled and there is a SiteTheme record.
|
||||
is_comprehensive_theming_enabled should return True
|
||||
2. Theming is enabled, there is no SiteTheme record but there is microsite configuration for the current site.
|
||||
2. Theming is enabled and there is no SiteTheme record.
|
||||
is_comprehensive_theming_enabled should return False
|
||||
3. Theming is enabled, there is neither a SiteTheme record nor microsite configuration for the current site.
|
||||
is_comprehensive_theming_enabled should return True
|
||||
4. Theming is disabled, there is a SiteTheme record and microsite configuration for the current site.
|
||||
3. Theming is disabled, there is a SiteTheme record for the current site.
|
||||
is_comprehensive_theming_enabled should return False
|
||||
5. Theming is disabled, there is no SiteTheme record but there is microsite configuration for the current site.
|
||||
is_comprehensive_theming_enabled should return False
|
||||
6. Theming is disabled, there is neither a SiteTheme record nor microsite configuration for the current site.
|
||||
4. Theming is disabled, there is no SiteTheme record.
|
||||
is_comprehensive_theming_enabled should return False
|
||||
"""
|
||||
# Theming is enabled, there is a SiteTheme record and microsite configuration for the current site
|
||||
# Theming is enabled, there is a SiteTheme record
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
self.assertTrue(theming_helpers.is_comprehensive_theming_enabled())
|
||||
self.assertTrue(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
# Theming is enabled, there is no SiteTheme record but there is microsite configuration for the current site.
|
||||
# Theming is enabled, there is not a SiteTheme record
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
self.assertTrue(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
with override_settings(ENABLE_COMPREHENSIVE_THEMING=False):
|
||||
# Theming is disabled, there is a SiteTheme record
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
self.assertFalse(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
# Theming is enabled, there is neither a SiteTheme record nor microsite configuration for the current site.
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
self.assertTrue(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
with override_settings(ENABLE_COMPREHENSIVE_THEMING=False):
|
||||
# Theming is disabled, there is a SiteTheme record and microsite configuration for the current site.
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
self.assertFalse(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
# Theming is disabled, there is no SiteTheme record but
|
||||
# there is microsite configuration for the current site.
|
||||
# Theming is disabled, there is no SiteTheme record
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
self.assertFalse(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
# Theming is disabled, there is neither a SiteTheme record nor microsite configuration for the current site.
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
self.assertFalse(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
def test_get_template(self):
|
||||
"""
|
||||
Tests to make sure the get_template function works as expected.
|
||||
"""
|
||||
# if the current site has associated SiteTheme then get_template should return None
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
|
||||
mock_microsite_backend.get_template = Mock(return_value="/microsite/about.html")
|
||||
self.assertIsNone(theming_helpers.get_template("about.html"))
|
||||
|
||||
# if the current site does not have associated SiteTheme then get_template should return microsite override
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
|
||||
mock_microsite_backend.get_template = Mock(return_value="/microsite/about.html")
|
||||
self.assertEqual(theming_helpers.get_template("about.html"), "/microsite/about.html")
|
||||
|
||||
def test_get_template_path(self):
|
||||
"""
|
||||
Tests to make sure the get_template_path function works as expected.
|
||||
"""
|
||||
# if the current site has associated SiteTheme then get_template_path should return the argument as is.
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
|
||||
mock_microsite_backend.get_template = Mock(return_value="/microsite/about.html")
|
||||
self.assertEqual(theming_helpers.get_template_path("about.html"), "about.html")
|
||||
|
||||
RequestCache.clear_all_namespaces()
|
||||
|
||||
# if the current site does not have associated SiteTheme then get_template_path should return microsite override
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.current_request_has_associated_site_theme",
|
||||
Mock(return_value=False),
|
||||
):
|
||||
with patch(
|
||||
"openedx.core.djangoapps.theming.helpers.microsite.is_request_in_microsite",
|
||||
Mock(return_value=True),
|
||||
):
|
||||
with patch("microsite_configuration.microsite.TEMPLATES_BACKEND") as mock_microsite_backend:
|
||||
mock_microsite_backend.get_template_path = Mock(return_value="/microsite/about.html")
|
||||
self.assertEqual(theming_helpers.get_template_path("about.html"), "/microsite/about.html")
|
||||
self.assertFalse(theming_helpers.is_comprehensive_theming_enabled())
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
"""
|
||||
Tests for microsites and comprehensive themes.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.test import TestCase
|
||||
|
||||
from openedx.core.djangoapps.theming.models import SiteTheme
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
|
||||
|
||||
@skip_unless_lms
|
||||
class TestComprehensiveThemeLMS(TestCase):
|
||||
"""
|
||||
Test html, sass and static file overrides for comprehensive themes.
|
||||
"""
|
||||
def __add_site_theme__(self, domain, theme):
|
||||
"""
|
||||
Add a Site and SiteTheme record for the given domain and theme
|
||||
Args:
|
||||
domain: domain to which attach the new Site
|
||||
theme: theme to apply on the new site
|
||||
"""
|
||||
site, __ = Site.objects.get_or_create(domain=domain, name=domain)
|
||||
SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme)
|
||||
|
||||
def test_theme_footer(self):
|
||||
"""
|
||||
Test that theme footer is used instead of microsite footer.
|
||||
"""
|
||||
# Add SiteTheme with the same domain name as microsite
|
||||
self.__add_site_theme__(domain=settings.MICROSITE_TEST_HOSTNAME, theme="test-theme")
|
||||
|
||||
# Test that requesting on a host, where both theme and microsite is applied
|
||||
# theme gets priority over microsite.
|
||||
resp = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
# This string comes from footer.html of test-theme
|
||||
self.assertContains(resp, "This is a footer for test-theme.")
|
||||
|
||||
def test_microsite_footer(self):
|
||||
"""
|
||||
Test that microsite footer is used instead of default theme footer.
|
||||
"""
|
||||
# Test that if theming is enabled but there is no SiteTheme for the current site, then
|
||||
# DEFAULT_SITE_THEME does not interfere with microsites
|
||||
resp = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
# This string comes from footer.html of test_site, which is a microsite
|
||||
self.assertContains(resp, "This is a Test Site footer")
|
||||
@@ -120,14 +120,6 @@ def get_login_session_form(request):
|
||||
restrictions={'max_length': DEFAULT_MAX_PASSWORD_LENGTH}
|
||||
)
|
||||
|
||||
form_desc.add_field(
|
||||
"remember",
|
||||
field_type="checkbox",
|
||||
label=_("Remember me"),
|
||||
default=False,
|
||||
required=False,
|
||||
)
|
||||
|
||||
return form_desc
|
||||
|
||||
|
||||
|
||||
@@ -640,19 +640,6 @@ class LoginSessionViewTest(UserAPITestCase):
|
||||
"supplementalText": "",
|
||||
"supplementalLink": "",
|
||||
},
|
||||
{
|
||||
"name": "remember",
|
||||
"defaultValue": False,
|
||||
"type": "checkbox",
|
||||
"required": False,
|
||||
"label": "Remember me",
|
||||
"placeholder": "",
|
||||
"instructions": "",
|
||||
"restrictions": {},
|
||||
"errorMessages": {},
|
||||
"supplementalText": "",
|
||||
"supplementalLink": "",
|
||||
},
|
||||
])
|
||||
|
||||
def test_login(self):
|
||||
|
||||
Reference in New Issue
Block a user