def test_get_themes(self): """ Tests template paths are returned from enabled theme. """ expected_themes = [ Theme('test-theme', 'test-theme', get_theme_base_dir('test-theme')), Theme('red-theme', 'red-theme', get_theme_base_dir('red-theme')), Theme('edge.edx.org', 'edge.edx.org', get_theme_base_dir('edge.edx.org')), Theme('edx.org', 'edx.org', get_theme_base_dir('edx.org')), Theme('stanford-style', 'stanford-style', get_theme_base_dir('stanford-style')), ] actual_themes = get_themes() self.assertItemsEqual(expected_themes, actual_themes)
def themed(self, name, theme): """ Returns True if given asset override is provided by the given theme otherwise returns False. Args: name: asset name e.g. 'images/logo.png' theme: theme name e.g. 'red-theme', 'edx.org' Returns: True if given asset override is provided by the given theme otherwise returns False """ if not is_comprehensive_theming_enabled(): return False # in debug mode check static asset from within the project directory if settings.DEBUG: themes_location = get_theme_base_dir(theme, suppress_error=True) # Nothing can be themed if we don't have a theme location or required params. if not all((themes_location, theme, name)): return False themed_path = "/".join( [themes_location, theme, get_project_root_name(), "static/"]) name = name[1:] if name.startswith("/") else name path = safe_join(themed_path, name) return os.path.exists(path) # in live mode check static asset in the static files dir defined by "STATIC_ROOT" setting else: return self.exists(os.path.join(theme, name))
def themed(self, name, theme): """ Returns True if given asset override is provided by the given theme otherwise returns False. Args: name: asset name e.g. 'images/logo.png' theme: theme name e.g. 'red-theme', 'edx.org' Returns: True if given asset override is provided by the given theme otherwise returns False """ if not is_comprehensive_theming_enabled(): return False # in debug mode check static asset from within the project directory if settings.DEBUG: themes_location = get_theme_base_dir(theme, suppress_error=True) # Nothing can be themed if we don't have a theme location or required params. if not all((themes_location, theme, name)): return False themed_path = "/".join([ themes_location, theme, get_project_root_name(), "static/" ]) name = name[1:] if name.startswith("/") else name path = safe_join(themed_path, name) return os.path.exists(path) # in live mode check static asset in the static files dir defined by "STATIC_ROOT" setting else: return self.exists(os.path.join(theme, name))
def test_get_themes_2(self): """ Tests template paths are returned from enabled theme. """ expected_themes = [ Theme('test-theme', 'test-theme', get_theme_base_dir('test-theme'), settings.PROJECT_ROOT), ] actual_themes = get_themes() self.assertItemsEqual(expected_themes, actual_themes)
def get_theme_dir(): """ Fetch the absolute path to the default theme directory """ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "openedx.stanford.lms.envs.aws") os.environ.setdefault("SERVICE_VARIANT", 'lms') django.setup() from openedx.core.djangoapps.theming.helpers import get_theme_base_dir return get_theme_base_dir(settings.DEFAULT_SITE_THEME)
def test_path(self, asset): """ Verify storage returns correct file path depending upon the enabled theme """ with patch( "openedx.core.djangoapps.theming.storage.get_current_theme", return_value=Theme(self.enabled_theme, self.enabled_theme, get_theme_base_dir(self.enabled_theme)), ): returned_path = self.storage.path(asset) expected_path = self.themes_dir / self.enabled_theme / "lms/static/" / asset self.assertEqual(expected_path, returned_path)
def test_url(self, asset): """ Verify storage returns correct url depending upon the enabled theme """ with patch( "openedx.core.djangoapps.theming.storage.get_current_theme", return_value=Theme(self.enabled_theme, self.enabled_theme, get_theme_base_dir(self.enabled_theme)), ): asset_url = self.storage.url(asset) # remove hash key from file url asset_url = re.sub(r"(\.\w+)(\.png|\.ico)$", r"\g<2>", asset_url) expected_url = self.storage.base_url + self.enabled_theme + "/" + asset self.assertEqual(asset_url, expected_url)
def test_get_themes(self): """ Tests template paths are returned from enabled theme. """ expected_themes = [ Theme('dark-theme', 'dark-theme', get_theme_base_dir('dark-theme'), settings.PROJECT_ROOT), Theme('edge.edx.org', 'edge.edx.org', get_theme_base_dir('edge.edx.org'), settings.PROJECT_ROOT), Theme('edx.org', 'edx.org', get_theme_base_dir('edx.org'), settings.PROJECT_ROOT), Theme('open-edx', 'open-edx', get_theme_base_dir('open-edx'), settings.PROJECT_ROOT), Theme('red-theme', 'red-theme', get_theme_base_dir('red-theme'), settings.PROJECT_ROOT), Theme('stanford-style', 'stanford-style', get_theme_base_dir('stanford-style'), settings.PROJECT_ROOT), Theme('test-theme', 'test-theme', get_theme_base_dir('test-theme'), settings.PROJECT_ROOT), ] actual_themes = get_themes() six.assertCountEqual(self, expected_themes, actual_themes)