Exemple #1
0
    def test_get_theme_base_dir(self):
        """
        Tests get_theme_base_dir returns correct directory for a theme.
        """
        theme_dirs = settings.COMPREHENSIVE_THEME_DIRS

        self.assertEqual(get_theme_base_dir("test-theme"), theme_dirs[0])
        self.assertEqual(get_theme_base_dir("test-theme-2"), theme_dirs[0])
        self.assertEqual(get_theme_base_dir("test-theme-3"), theme_dirs[1])
Exemple #2
0
    def test_get_theme_base_dir(self):
        """
        Tests get_theme_base_dir returns correct directory for a theme.
        """
        theme_dirs = settings.COMPREHENSIVE_THEME_DIRS

        self.assertEqual(get_theme_base_dir("test-theme"), theme_dirs[0])
        self.assertEqual(get_theme_base_dir("test-theme-2"), theme_dirs[0])
        self.assertEqual(get_theme_base_dir("test-theme-3"), theme_dirs[1])
Exemple #3
0
    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,
                "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
        return self.exists(os.path.join(theme, name))
Exemple #4
0
    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,
                "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_path(self):
        """
        Verify storage returns correct file path depending upon the enabled theme
        """
        asset = "images/default-logo.png"
        with patch("ecommerce.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 / "static" / asset

            self.assertEqual(expected_path, returned_path)
Exemple #6
0
    def test_path(self):
        """
        Verify storage returns correct file path depending upon the enabled theme
        """
        asset = "images/default-logo.png"
        with patch(
            "ecommerce.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 / "static" / asset

            self.assertEqual(expected_path, returned_path)
    def test_url(self):
        """
        Verify storage returns correct url depending upon the enabled theme
        """
        asset = "images/default-logo.png"
        with patch("ecommerce.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
            expected_url = self.storage.base_url + self.enabled_theme + "/" + asset

            self.assertEqual(asset_url, expected_url)
Exemple #8
0
    def test_url(self):
        """
        Verify storage returns correct url depending upon the enabled theme
        """
        asset = "images/default-logo.png"
        with patch(
            "ecommerce.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
            expected_url = self.storage.base_url + self.enabled_theme + "/" + asset

            self.assertEqual(asset_url, expected_url)
Exemple #9
0
 def test_get_theme_base_dir_suppress_error(self):
     """
     Tests get_theme_base_dir returns None if theme is not found istead of raising an error.
     """
     self.assertIsNone(get_theme_base_dir("non-existent-theme", suppress_error=True))
Exemple #10
0
 def test_get_theme_base_dir_error(self):
     """
     Tests get_theme_base_dir raises value error if theme is not found in themes dir.
     """
     with self.assertRaises(ValueError):
         get_theme_base_dir("non-existent-theme")
Exemple #11
0
 def test_get_theme_base_dir_suppress_error(self):
     """
     Tests get_theme_base_dir returns None if theme is not found istead of raising an error.
     """
     self.assertIsNone(get_theme_base_dir("non-existent-theme", suppress_error=True))
Exemple #12
0
 def test_get_theme_base_dir_error(self):
     """
     Tests get_theme_base_dir raises value error if theme is not found in themes dir.
     """
     with self.assertRaises(ValueError):
         get_theme_base_dir("non-existent-theme")