moved IS_EDX_DOMAIN dependent feature to edx.org theme

This commit is contained in:
Zia Fazal
2016-01-21 14:47:53 +05:00
committed by Matt Drayer
parent 479ce51bac
commit c0648ab164
25 changed files with 606 additions and 209 deletions

View File

@@ -5,6 +5,7 @@ Test helpers for Comprehensive Theming.
from functools import wraps
import os
import os.path
import contextlib
from mock import patch
@@ -15,6 +16,8 @@ import edxmako
from .core import comprehensive_theme_changes
EDX_THEME_DIR = settings.REPO_ROOT / "themes" / "edx.org"
def with_comprehensive_theme(theme_dir):
"""
@@ -46,11 +49,7 @@ def with_comprehensive_theme(theme_dir):
def with_is_edx_domain(is_edx_domain):
"""
A decorator to run a test as if IS_EDX_DOMAIN is true or false.
We are transitioning away from IS_EDX_DOMAIN and are moving toward an edX
theme. This decorator changes both settings to let tests stay isolated
from the details.
A decorator to run a test as if request originated from edX domain or not.
Arguments:
is_edx_domain (bool): are we an edX domain or not?
@@ -61,16 +60,34 @@ def with_is_edx_domain(is_edx_domain):
def _decorator(func): # pylint: disable=missing-docstring
if is_edx_domain:
# This applies @with_comprehensive_theme to the func.
func = with_comprehensive_theme(settings.REPO_ROOT / "themes" / "edx.org")(func)
# This applies @patch.dict() to the func to set IS_EDX_DOMAIN.
func = patch.dict('django.conf.settings.FEATURES', {"IS_EDX_DOMAIN": is_edx_domain})(func)
func = with_comprehensive_theme(EDX_THEME_DIR)(func)
return func
return _decorator
@contextlib.contextmanager
def with_edx_domain_context(is_edx_domain):
"""
A function to run a test as if request originated from edX domain or not.
Arguments:
is_edx_domain (bool): are we an edX domain or not?
"""
if is_edx_domain:
changes = comprehensive_theme_changes(EDX_THEME_DIR)
with override_settings(COMPREHENSIVE_THEME_DIR=EDX_THEME_DIR, **changes['settings']):
with edxmako.save_lookups():
for template_dir in changes['mako_paths']:
edxmako.paths.add_lookup('main', template_dir, prepend=True)
yield
else:
yield
def dump_theming_info():
"""Dump a bunch of theming information, for debugging."""
for namespace, lookup in edxmako.LOOKUP.items():