More test fixes.
This commit is contained in:
@@ -1,172 +0,0 @@
|
||||
"""
|
||||
Test Microsite filebased backends.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
import unittest
|
||||
from mock import patch
|
||||
|
||||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from microsite_configuration.backends.base import (
|
||||
BaseMicrositeBackend,
|
||||
BaseMicrositeTemplateBackend,
|
||||
)
|
||||
from microsite_configuration import microsite
|
||||
from student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
|
||||
|
||||
@patch(
|
||||
'microsite_configuration.microsite.BACKEND',
|
||||
microsite.get_backend(
|
||||
'microsite_configuration.backends.filebased.FilebasedMicrositeBackend', BaseMicrositeBackend
|
||||
)
|
||||
)
|
||||
class FilebasedMicrositeBackendTests(TestCase):
|
||||
"""
|
||||
Go through and test the FilebasedMicrositeBackend class
|
||||
"""
|
||||
def setUp(self):
|
||||
super(FilebasedMicrositeBackendTests, self).setUp()
|
||||
self.microsite_subdomain = 'test-site'
|
||||
|
||||
def tearDown(self):
|
||||
super(FilebasedMicrositeBackendTests, self).tearDown()
|
||||
microsite.clear()
|
||||
|
||||
def test_get_value(self):
|
||||
"""
|
||||
Tests microsite.get_value works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertEqual(microsite.get_value('platform_name'), 'Test Site')
|
||||
|
||||
def test_is_request_in_microsite(self):
|
||||
"""
|
||||
Tests microsite.is_request_in_microsite works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertTrue(microsite.is_request_in_microsite())
|
||||
|
||||
def test_has_override_value(self):
|
||||
"""
|
||||
Tests microsite.has_override_value works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertTrue(microsite.has_override_value('platform_name'))
|
||||
|
||||
def test_get_value_for_org(self):
|
||||
"""
|
||||
Tests microsite.get_value_for_org works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertEqual(
|
||||
microsite.get_value_for_org('TestSiteX', 'platform_name'),
|
||||
'Test Site'
|
||||
)
|
||||
|
||||
# if no config is set
|
||||
microsite.clear()
|
||||
with patch('django.conf.settings.MICROSITE_CONFIGURATION', False):
|
||||
self.assertEqual(
|
||||
microsite.get_value_for_org('TestSiteX', 'platform_name', 'Default Value'),
|
||||
'Default Value'
|
||||
)
|
||||
|
||||
def test_get_all_orgs(self):
|
||||
"""
|
||||
Tests microsite.get_all_orgs works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertEqual(
|
||||
microsite.get_all_orgs(),
|
||||
set(['TestSiteX', 'LogistrationX'])
|
||||
)
|
||||
|
||||
# if no config is set
|
||||
microsite.clear()
|
||||
with patch('django.conf.settings.MICROSITE_CONFIGURATION', False):
|
||||
self.assertEqual(
|
||||
microsite.get_all_orgs(),
|
||||
set()
|
||||
)
|
||||
|
||||
def test_clear(self):
|
||||
"""
|
||||
Tests microsite.clear works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
self.assertEqual(
|
||||
microsite.get_value('platform_name'),
|
||||
'Test Site'
|
||||
)
|
||||
microsite.clear()
|
||||
self.assertIsNone(microsite.get_value('platform_name'))
|
||||
|
||||
def test_get_all_configs(self):
|
||||
"""
|
||||
Tests microsite.get_all_config works as expected.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
configs = microsite.get_all_config()
|
||||
self.assertEqual(len(list(configs.keys())), 3)
|
||||
|
||||
def test_set_config_by_domain(self):
|
||||
"""
|
||||
Tests microsite.set_config_by_domain works as expected.
|
||||
"""
|
||||
microsite.clear()
|
||||
# if microsite config does not exist default config should be used
|
||||
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',
|
||||
microsite.get_backend(
|
||||
'microsite_configuration.backends.filebased.FilebasedMicrositeTemplateBackend', BaseMicrositeTemplateBackend
|
||||
)
|
||||
)
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
class FilebasedMicrositeTemplateBackendTests(ModuleStoreTestCase):
|
||||
"""
|
||||
Go through and test the FilebasedMicrositeTemplateBackend class
|
||||
"""
|
||||
def setUp(self):
|
||||
super(FilebasedMicrositeTemplateBackendTests, self).setUp()
|
||||
self.microsite_subdomain = 'test-site'
|
||||
self.course = CourseFactory.create()
|
||||
self.user = UserFactory.create(username="Bob", email="bob@example.com", password="edx")
|
||||
self.client.login(username=self.user.username, password="edx")
|
||||
|
||||
def test_get_template_path(self):
|
||||
"""
|
||||
Tests get template path works for both relative and absolute paths.
|
||||
"""
|
||||
microsite.set_by_domain(self.microsite_subdomain)
|
||||
CourseEnrollmentFactory(
|
||||
course_id=self.course.id,
|
||||
user=self.user
|
||||
)
|
||||
|
||||
response = self.client.get(
|
||||
reverse('syllabus', args=[six.text_type(self.course.id)]),
|
||||
HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME,
|
||||
)
|
||||
|
||||
self.assertContains(response, "Microsite relative path template contents")
|
||||
self.assertContains(response, "Microsite absolute path template contents")
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user