Commit 2c7ddb1d by Felipe Montoya

Delegating the conditional to the has_configuration_Set method, which is…

Delegating the conditional to the has_configuration_Set method, which is overriden by the database backend, so the enable_pre_startup works well for both backends.

Adding tests

Fix quality issues
parent e5108dc7
......@@ -290,9 +290,8 @@ class BaseMicrositeBackend(AbstractBaseMicrositeBackend):
in non-mako templates must be loaded before the django startup
"""
microsites_root = settings.MICROSITE_ROOT_DIR
microsite_config_dict = settings.MICROSITE_CONFIGURATION
if microsite_config_dict:
if self.has_configuration_set():
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'].append(microsites_root)
......
"""
Test Microsite base backends.
"""
import logging
from mock import patch
from django.conf import settings
from django.test import TestCase
from microsite_configuration import microsite
from microsite_configuration.backends.base import (
AbstractBaseMicrositeBackend,
BaseMicrositeBackend
)
log = logging.getLogger(__name__)
class NullBackend(AbstractBaseMicrositeBackend):
"""
......@@ -130,3 +138,36 @@ class AbstractBaseMicrositeBackendTests(TestCase):
with self.assertRaises(NotImplementedError):
backend.get_all_orgs()
@patch(
'microsite_configuration.microsite.BACKEND',
microsite.get_backend(
'microsite_configuration.backends.base.BaseMicrositeBackend', BaseMicrositeBackend
)
)
class BaseMicrositeBackendTests(TestCase):
"""
Go through and test the BaseMicrositeBackend class for behavior which is not
overriden in subclasses
"""
def test_enable_microsites_pre_startup(self):
"""
Tests microsite.test_enable_microsites_pre_startup works as expected.
"""
# remove microsite root directory paths first
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] = [
path for path in settings.DEFAULT_TEMPLATE_ENGINE['DIRS']
if path != settings.MICROSITE_ROOT_DIR
]
with patch('microsite_configuration.backends.base.BaseMicrositeBackend.has_configuration_set',
return_value=False):
microsite.enable_microsites_pre_startup(log)
self.assertNotIn(settings.MICROSITE_ROOT_DIR,
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
with patch('microsite_configuration.backends.base.BaseMicrositeBackend.has_configuration_set',
return_value=True):
microsite.enable_microsites_pre_startup(log)
self.assertIn(settings.MICROSITE_ROOT_DIR,
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
......@@ -105,22 +105,6 @@ class DatabaseMicrositeBackendTests(DatabaseMicrositeTestCase):
microsite.clear()
self.assertIsNone(microsite.get_value('platform_name'))
def test_enable_microsites_pre_startup(self):
"""
Tests microsite.test_enable_microsites_pre_startup works as expected.
"""
# remove microsite root directory paths first
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] = [
path for path in settings.DEFAULT_TEMPLATE_ENGINE['DIRS']
if path != settings.MICROSITE_ROOT_DIR
]
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': False}):
microsite.enable_microsites_pre_startup(log)
self.assertNotIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': True}):
microsite.enable_microsites_pre_startup(log)
self.assertIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
@patch('edxmako.paths.add_lookup')
def test_enable_microsites(self, add_lookup):
"""
......@@ -173,6 +157,15 @@ class DatabaseMicrositeBackendTests(DatabaseMicrositeTestCase):
with self.assertRaises(Exception):
microsite.set_by_domain('test.microsite2.com')
def test_has_configuration_set(self):
"""
Tests microsite.has_configuration_set works as expected on this backend.
"""
self.assertTrue(microsite.BACKEND.has_configuration_set())
Microsite.objects.all().delete()
self.assertFalse(microsite.BACKEND.has_configuration_set())
@patch(
'microsite_configuration.microsite.TEMPLATES_BACKEND',
......
......@@ -122,6 +122,15 @@ class FilebasedMicrositeBackendTests(TestCase):
microsite.set_by_domain('unknown')
self.assertEqual(microsite.get_value('university'), 'default_university')
def test_has_configuration_set(self):
"""
Tests microsite.has_configuration_set works as expected.
"""
self.assertTrue(microsite.BACKEND.has_configuration_set())
with patch('django.conf.settings.MICROSITE_CONFIGURATION', {}):
self.assertFalse(microsite.BACKEND.has_configuration_set())
@patch(
'microsite_configuration.microsite.TEMPLATES_BACKEND',
......
......@@ -2,6 +2,9 @@
"""
Tests microsite_configuration templatetags and helper functions.
"""
import logging
from mock import patch
from django.test import TestCase
from django.conf import settings
from microsite_configuration.templatetags import microsite as microsite_tags
......@@ -9,6 +12,8 @@ from microsite_configuration import microsite
from microsite_configuration.backends.base import BaseMicrositeBackend
from microsite_configuration.backends.database import DatabaseMicrositeBackend
log = logging.getLogger(__name__)
class MicrositeTests(TestCase):
"""
......@@ -74,3 +79,20 @@ class MicrositeTests(TestCase):
),
DatabaseMicrositeBackend
)
def test_enable_microsites_pre_startup(self):
"""
Tests microsite.test_enable_microsites_pre_startup is not used if the feature is turned off.
"""
# remove microsite root directory paths first
settings.DEFAULT_TEMPLATE_ENGINE['DIRS'] = [
path for path in settings.DEFAULT_TEMPLATE_ENGINE['DIRS']
if path != settings.MICROSITE_ROOT_DIR
]
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': False}):
microsite.enable_microsites_pre_startup(log)
self.assertNotIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
with patch.dict('django.conf.settings.FEATURES', {'USE_MICROSITES': True}):
microsite.enable_microsites_pre_startup(log)
self.assertIn(settings.MICROSITE_ROOT_DIR, settings.DEFAULT_TEMPLATE_ENGINE['DIRS'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment