Files
edx-platform/lms/djangoapps/courseware/tests/test_comprehensive_theming.py
Kyle McCormick 151bd13666 Use full names for common.djangoapps imports; warn when using old style (#25477)
* Generate common/djangoapps import shims for LMS
* Generate common/djangoapps import shims for Studio
* Stop appending project root to sys.path
* Stop appending common/djangoapps to sys.path
* Import from common.djangoapps.course_action_state instead of course_action_state
* Import from common.djangoapps.course_modes instead of course_modes
* Import from common.djangoapps.database_fixups instead of database_fixups
* Import from common.djangoapps.edxmako instead of edxmako
* Import from common.djangoapps.entitlements instead of entitlements
* Import from common.djangoapps.pipline_mako instead of pipeline_mako
* Import from common.djangoapps.static_replace instead of static_replace
* Import from common.djangoapps.student instead of student
* Import from common.djangoapps.terrain instead of terrain
* Import from common.djangoapps.third_party_auth instead of third_party_auth
* Import from common.djangoapps.track instead of track
* Import from common.djangoapps.util instead of util
* Import from common.djangoapps.xblock_django instead of xblock_django
* Add empty common/djangoapps/__init__.py to fix pytest collection
* Fix pylint formatting violations
* Exclude import_shims/ directory tree from linting
2020-11-10 07:02:01 -05:00

87 lines
3.3 KiB
Python

"""Tests of comprehensive theming."""
from django.conf import settings
from django.contrib import staticfiles
from django.test import TestCase
from path import Path
from common.djangoapps import edxmako
from openedx.core.djangoapps.theming.tests.test_util import with_comprehensive_theme
from openedx.core.lib.tempdir import create_symlink, delete_symlink, mkdtemp_clean
class TestComprehensiveTheming(TestCase):
"""Test comprehensive theming."""
def setUp(self):
super(TestComprehensiveTheming, self).setUp()
# Clear the internal staticfiles caches, to get test isolation.
staticfiles.finders.get_finder.cache_clear()
@with_comprehensive_theme('red-theme')
def test_red_footer(self):
"""
Tests templates from theme are rendered if available.
`red-theme` has header.html and footer.html so this test
asserts presence of the content from header.html and footer.html
"""
resp = self.client.get('/')
self.assertEqual(resp.status_code, 200)
# This string comes from footer.html
self.assertContains(resp, "super-ugly")
def test_theme_outside_repo(self):
# Need to create a temporary theme, and defer decorating the function
# until it is done, which leads to this strange nested-function style
# of test.
# Make a temp directory as a theme.
themes_dir = Path(mkdtemp_clean())
tmp_theme = "temp_theme"
template_dir = themes_dir / tmp_theme / "lms/templates"
template_dir.makedirs()
with open(template_dir / "footer.html", "w") as footer:
footer.write("<footer>TEMPORARY THEME</footer>")
dest_path = Path(settings.COMPREHENSIVE_THEME_DIRS[0]) / tmp_theme
create_symlink(themes_dir / tmp_theme, dest_path)
edxmako.paths.add_lookup('main', themes_dir, prepend=True)
@with_comprehensive_theme(tmp_theme)
def do_the_test(self):
"""A function to do the work so we can use the decorator."""
resp = self.client.get('/')
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "TEMPORARY THEME")
do_the_test(self)
# remove symlinks before running subsequent tests
delete_symlink(dest_path)
def test_default_logo_image(self):
result = staticfiles.finders.find('images/logo.png')
self.assertEqual(result, settings.REPO_ROOT / 'lms/static/images/logo.png')
@with_comprehensive_theme('red-theme')
def test_overridden_logo_image(self):
result = staticfiles.finders.find('red-theme/images/logo.png')
self.assertEqual(result, settings.REPO_ROOT / 'themes/red-theme/lms/static/images/logo.png')
def test_default_favicon(self):
"""
Test default favicon is served if no theme is applied
"""
result = staticfiles.finders.find('images/favicon.ico')
self.assertEqual(result, settings.REPO_ROOT / 'lms/static/images/favicon.ico')
@with_comprehensive_theme('red-theme')
def test_overridden_favicon(self):
"""
Test comprehensive theme override on favicon image.
"""
result = staticfiles.finders.find('red-theme/images/favicon.ico')
self.assertEqual(result, settings.REPO_ROOT / 'themes/red-theme/lms/static/images/favicon.ico')