Commit 5ccc80b4 by Saleem Latif

Fix footer test failures

parent 69410948
...@@ -6,6 +6,7 @@ from django.test import TestCase ...@@ -6,6 +6,7 @@ from django.test import TestCase
from path import path # pylint: disable=no-name-in-module from path import path # pylint: disable=no-name-in-module
from django.contrib import staticfiles from django.contrib import staticfiles
import edxmako
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from openedx.core.lib.tempdir import mkdtemp_clean, create_symlink, delete_symlink from openedx.core.lib.tempdir import mkdtemp_clean, create_symlink, delete_symlink
...@@ -49,6 +50,8 @@ class TestComprehensiveTheming(TestCase): ...@@ -49,6 +50,8 @@ class TestComprehensiveTheming(TestCase):
dest_path = path(settings.COMPREHENSIVE_THEME_DIRS[0]) / tmp_theme dest_path = path(settings.COMPREHENSIVE_THEME_DIRS[0]) / tmp_theme
create_symlink(themes_dir / tmp_theme, dest_path) create_symlink(themes_dir / tmp_theme, dest_path)
edxmako.paths.add_lookup('main', themes_dir, prepend=True)
@with_comprehensive_theme(tmp_theme) @with_comprehensive_theme(tmp_theme)
def do_the_test(self): def do_the_test(self):
"""A function to do the work so we can use the decorator.""" """A function to do the work so we can use the decorator."""
......
...@@ -106,6 +106,8 @@ def get_template_path_with_theme(relative_path): ...@@ -106,6 +106,8 @@ def get_template_path_with_theme(relative_path):
Returns: Returns:
(str): template path in current site's theme (str): template path in current site's theme
""" """
relative_path = os.path.normpath(relative_path)
theme = get_current_theme() theme = get_current_theme()
if not theme: if not theme:
......
...@@ -25,8 +25,7 @@ class TestComprehensiveThemeLMS(TestCase): ...@@ -25,8 +25,7 @@ class TestComprehensiveThemeLMS(TestCase):
# Clear the internal staticfiles caches, to get test isolation. # Clear the internal staticfiles caches, to get test isolation.
staticfiles.finders.get_finder.cache_clear() staticfiles.finders.get_finder.cache_clear()
@override_settings(COMPREHENSIVE_THEME_DIRS=[settings.TEST_THEME.dirname()]) @with_comprehensive_theme("test-theme")
@with_comprehensive_theme(settings.TEST_THEME.basename())
def test_footer(self): def test_footer(self):
""" """
Test that theme footer is used instead of default footer. Test that theme footer is used instead of default footer.
...@@ -36,8 +35,7 @@ class TestComprehensiveThemeLMS(TestCase): ...@@ -36,8 +35,7 @@ class TestComprehensiveThemeLMS(TestCase):
# This string comes from header.html of test-theme # This string comes from header.html of test-theme
self.assertContains(resp, "This is a footer for test-theme.") self.assertContains(resp, "This is a footer for test-theme.")
@override_settings(COMPREHENSIVE_THEME_DIRS=[settings.TEST_THEME.dirname()]) @with_comprehensive_theme("test-theme")
@with_comprehensive_theme(settings.TEST_THEME.basename())
def test_logo_image(self): def test_logo_image(self):
""" """
Test that theme logo is used instead of default logo. Test that theme logo is used instead of default logo.
...@@ -61,8 +59,7 @@ class TestComprehensiveThemeCMS(TestCase): ...@@ -61,8 +59,7 @@ class TestComprehensiveThemeCMS(TestCase):
# Clear the internal staticfiles caches, to get test isolation. # Clear the internal staticfiles caches, to get test isolation.
staticfiles.finders.get_finder.cache_clear() staticfiles.finders.get_finder.cache_clear()
@override_settings(COMPREHENSIVE_THEME_DIRS=[settings.TEST_THEME.dirname()]) @with_comprehensive_theme("test-theme")
@with_comprehensive_theme(settings.TEST_THEME.basename())
def test_template_override(self): def test_template_override(self):
""" """
Test that theme templates are used instead of default templates. Test that theme templates are used instead of default templates.
......
...@@ -32,9 +32,6 @@ def with_comprehensive_theme(theme_dir_name): ...@@ -32,9 +32,6 @@ def with_comprehensive_theme(theme_dir_name):
site, __ = Site.objects.get_or_create(domain=domain, name=domain) site, __ = Site.objects.get_or_create(domain=domain, name=domain)
site_theme, __ = SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme_dir_name) site_theme, __ = SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme_dir_name)
for _dir in settings.COMPREHENSIVE_THEME_DIRS:
edxmako.paths.add_lookup('main', _dir, prepend=True)
with patch('openedx.core.djangoapps.theming.helpers.get_current_site_theme', with patch('openedx.core.djangoapps.theming.helpers.get_current_site_theme',
return_value=site_theme): return_value=site_theme):
with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site): with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site):
...@@ -57,9 +54,6 @@ def with_comprehensive_theme_context(theme=None): ...@@ -57,9 +54,6 @@ def with_comprehensive_theme_context(theme=None):
site, __ = Site.objects.get_or_create(domain=domain, name=theme) site, __ = Site.objects.get_or_create(domain=domain, name=theme)
site_theme, __ = SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme) site_theme, __ = SiteTheme.objects.get_or_create(site=site, theme_dir_name=theme)
for _dir in settings.COMPREHENSIVE_THEME_DIRS:
edxmako.paths.add_lookup('main', _dir, prepend=True)
with patch('openedx.core.djangoapps.theming.helpers.get_current_site_theme', with patch('openedx.core.djangoapps.theming.helpers.get_current_site_theme',
return_value=site_theme): return_value=site_theme):
with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site): with patch('openedx.core.djangoapps.theming.helpers.get_current_site', return_value=site):
......
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