DEPR-33 Remove microsites from site_configuration (#20922)

This commit is contained in:
Jeremy Bowman
2019-08-08 13:02:09 -04:00
committed by GitHub
parent a8fd936d27
commit 1835ee9a45
4 changed files with 29 additions and 84 deletions

View File

@@ -90,6 +90,10 @@ class LmsSearchFilterGeneratorTestCase(ModuleStoreTestCase):
self.assertIn('start_date', filter_dictionary)
self.assertEqual(0, len(field_dictionary['course']))
@patch(
'openedx.core.djangoapps.site_configuration.helpers.get_all_orgs',
Mock(return_value=["LogistrationX", "TestSiteX"])
)
def test_excludes_site_org(self):
"""
By default site orgs not belonging to current site org should be excluded.

View File

@@ -5,8 +5,6 @@ from __future__ import absolute_import
from django.conf import settings
from microsite_configuration import microsite
def get_current_site_configuration():
"""
@@ -106,23 +104,22 @@ def get_value(val_name, default=None, **kwargs):
default: default value tp return if key is not found in the configuration
Returns:
Configuration/Microsite value for the given key.
Configuration value for the given key.
"""
if is_site_configuration_enabled():
# Retrieve the requested field/value from the site configuration
configuration_value = get_configuration_value(val_name, default=default)
else:
# Retrieve the requested field/value from the microsite configuration
configuration_value = microsite.get_value(val_name, default=default, **kwargs)
configuration_value = default
# Attempt to perform a dictionary update using the provided default
# This will fail if either the default or the microsite value is not a dictionary
# This will fail if the default value is not a dictionary
try:
value = dict(default)
value.update(configuration_value)
# If the dictionary update fails, just use the microsite value
# If the dictionary update fails, just use the configuration value
# TypeError: default is not iterable (simple value or None)
# ValueError: default is iterable but not a dict (list, not dict)
# AttributeError: default does not have an 'update' method
@@ -150,7 +147,7 @@ def get_dict(name, default=None):
if is_site_configuration_enabled():
return get_configuration_dict(name, default)
else:
return microsite.get_dict(name, default)
return default.copy()
def has_override_value(name):
@@ -167,36 +164,34 @@ def has_override_value(name):
if is_site_configuration_enabled():
return has_configuration_override(name)
else:
return microsite.has_override_value(name)
return False
def get_value_for_org(org, val_name, default=None):
"""
This returns a configuration value for a site configuration or microsite configuration
This returns a configuration value for a site configuration
which has an org_filter that matches with the argument.
Args:
org (str): Course org filter, this value will be used to filter out the correct site configuration.
name (str): Name of the key for which to return configuration value.
val_name (str): Name of the key for which to return configuration value.
default: default value to return if key is not present in the configuration
Returns:
Configuration value for the given key.
"""
# Here we first look for the asked org inside site configuration, and if org is not present in site configuration
# then we go ahead and look it inside microsite configuration.
# Import is placed here to avoid model import at project startup.
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
if SiteConfiguration.has_org(org):
return SiteConfiguration.get_value_for_org(org, val_name, default)
else:
return microsite.get_value_for_org(org, val_name, default)
return default
def get_current_site_orgs():
"""
This returns the orgs configured in site configuration or microsite configuration for the current site.
This returns the orgs configured in site configuration for the current site.
Returns:
list: A list of organization names.
@@ -211,18 +206,15 @@ def get_current_site_orgs():
def get_all_orgs():
"""
This returns all of the orgs that are considered in site configurations or microsite configuration,
This returns all of the orgs that are considered in site configurations.
This can be used, for example, to do filtering.
Returns:
A list of all organizations present in either microsite configuration or site configuration.
A list of all organizations present in the site configuration.
"""
# Import is placed here to avoid model import at project startup.
from openedx.core.djangoapps.site_configuration.models import SiteConfiguration
site_configuration_orgs = SiteConfiguration.get_all_orgs()
microsite_orgs = microsite.get_all_orgs()
return site_configuration_orgs.union(microsite_orgs)
return SiteConfiguration.get_all_orgs()
def page_title_breadcrumbs(*crumbs, **kwargs):

View File

@@ -160,35 +160,22 @@ class TestHelpers(TestCase):
test_org = test_config['course_org_filter']
with with_site_configuration_context(configuration=test_config):
# Make sure if ORG is not present in site configuration then microsite configuration is used instead
# Make sure if ORG is not present in site configuration then default is used instead
self.assertEqual(
configuration_helpers.get_value_for_org("TestSiteX", "email_from_address"),
"test_site@edx.org"
None
)
# Make sure 'default' is returned if org is present but key is not
self.assertEqual(
configuration_helpers.get_value_for_org(test_org, "email_from_address"),
None
)
# Make sure if ORG is not present in site configuration then microsite configuration is used instead
self.assertEqual(
configuration_helpers.get_value_for_org("LogistrationX", "email_from_address"),
"test_site@edx.org"
)
# This test must come after the above test
with with_site_configuration_context(configuration={"course_org_filter": "TestSiteX", "university": "Test"}):
# Make sure site configuration gets preference over microsite configuration
self.assertEqual(
configuration_helpers.get_value_for_org("TestSiteX", "university"),
"Test"
)
def test_get_all_orgs(self):
"""
Test that get_all_orgs returns organizations defined in both site configuration and microsite configuration.
Test that get_all_orgs returns organizations defined in site configuration
"""
test_orgs = [test_config['course_org_filter'], "LogistrationX", "TestSiteX"]
test_orgs = [test_config['course_org_filter']]
with with_site_configuration_context(configuration=test_config):
self.assertItemsEqual(
list(configuration_helpers.get_all_orgs()),

View File

@@ -4,7 +4,6 @@ Test site_configuration middleware.
"""
from __future__ import absolute_import
import ddt
from mock import patch
from django.conf import settings
@@ -13,31 +12,21 @@ from django.test.client import Client
from django.test.utils import override_settings
from student.tests.factories import UserFactory
from microsite_configuration.microsite import (
get_backend,
)
from microsite_configuration.backends.base import BaseMicrositeBackend
from microsite_configuration.tests.tests import (
DatabaseMicrositeTestCase,
side_effect_for_get_value,
MICROSITE_BACKENDS,
)
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory
from openedx.core.djangolib.testing.utils import skip_unless_lms
# NOTE: We set SESSION_SAVE_EVERY_REQUEST to True in order to make sure
# Sessions are always started on every request
@ddt.ddt
@override_settings(SESSION_SAVE_EVERY_REQUEST=True)
@skip_unless_lms
class SessionCookieDomainMicrositeOverrideTests(DatabaseMicrositeTestCase):
class SessionCookieDomainTests(TestCase):
"""
Tests regarding the session cookie management in the middlware for Microsites
Tests regarding the session cookie management in the middleware for site_configuration
"""
def setUp(self):
super(SessionCookieDomainMicrositeOverrideTests, self).setUp()
super(SessionCookieDomainTests, self).setUp()
# Create a test client, and log it in so that it will save some session
# data.
self.user = UserFactory.create()
@@ -57,46 +46,19 @@ class SessionCookieDomainMicrositeOverrideTests(DatabaseMicrositeTestCase):
}
)
@ddt.data(*MICROSITE_BACKENDS)
def test_session_cookie_domain_no_override(self, site_backend):
def test_session_cookie_domain_no_override(self):
"""
Test sessionid cookie when no override is set
"""
with patch('microsite_configuration.microsite.BACKEND',
get_backend(site_backend, BaseMicrositeBackend)):
response = self.client.get('/')
self.assertNotIn('test_site.localhost', str(response.cookies['sessionid']))
self.assertNotIn('Domain', str(response.cookies['sessionid']))
@ddt.data(*MICROSITE_BACKENDS)
def test_session_cookie_domain_with_microsite_override(self, site_backend):
"""
Makes sure that the cookie being set in a Microsite
is the one specially overridden in configuration
"""
with patch('microsite_configuration.microsite.BACKEND',
get_backend(site_backend, BaseMicrositeBackend)):
response = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
self.assertIn('test_site.localhost', str(response.cookies['sessionid']))
@ddt.data(*MICROSITE_BACKENDS)
def test_microsite_none_cookie_domain(self, site_backend):
"""
Tests to make sure that a Microsite that specifies None for 'SESSION_COOKIE_DOMAIN' does not
set a domain on the session cookie
"""
with patch('microsite_configuration.microsite.get_value') as mock_get_value:
mock_get_value.side_effect = side_effect_for_get_value('SESSION_COOKIE_DOMAIN', None)
with patch('microsite_configuration.microsite.BACKEND',
get_backend(site_backend, BaseMicrositeBackend)):
response = self.client.get('/', HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME)
self.assertNotIn('test_site.localhost', str(response.cookies['sessionid']))
self.assertNotIn('Domain', str(response.cookies['sessionid']))
response = self.client.get('/')
self.assertNotIn('test_site.localhost', str(response.cookies['sessionid']))
self.assertNotIn('Domain', str(response.cookies['sessionid']))
# NOTE: We set SESSION_SAVE_EVERY_REQUEST to True in order to make sure
# Sessions are always started on every request
@override_settings(SESSION_SAVE_EVERY_REQUEST=True)
@skip_unless_lms
class SessionCookieDomainSiteConfigurationOverrideTests(TestCase):
"""
Tests regarding the session cookie management in the middlware for Microsites