Example #1
0
 def test_improperly_configured_error_for_invalid_dir(self):
     """
     Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not an existent path.
     """
     with override_settings(COMPREHENSIVE_THEME_DIRS=["/path/to/non/existent/dir"]):
         with self.assertRaises(ImproperlyConfigured):
             get_theme_base_dirs()
Example #2
0
 def test_improperly_configured_error_for_relative_paths(self):
     """
     Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not an existent path.
     """
     with override_settings(COMPREHENSIVE_THEME_DIRS=["ecommerce/tests/themes/tes-theme"]):
         with self.assertRaises(ImproperlyConfigured):
             get_theme_base_dirs()
Example #3
0
 def test_improperly_configured_error_for_relative_paths(self):
     """
     Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not an existent path.
     """
     with override_settings(COMPREHENSIVE_THEME_DIRS=["ecommerce/tests/themes/tes-theme"]):
         with self.assertRaises(ImproperlyConfigured):
             get_theme_base_dirs()
Example #4
0
 def test_improperly_configured_error_for_invalid_dir(self):
     """
     Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not an existent path.
     """
     with override_settings(COMPREHENSIVE_THEME_DIRS=["/path/to/non/existent/dir"]):
         with self.assertRaises(ImproperlyConfigured):
             get_theme_base_dirs()
Example #5
0
 def test_get_themes(self):
     """
     Tests get_themes returns all themes in themes directory.
     """
     theme_dirs = get_theme_base_dirs()
     expected_themes = [
         Theme('test-theme', 'test-theme', theme_dirs[0]),
         Theme('test-theme-2', 'test-theme-2', theme_dirs[0]),
         Theme('test-theme-3', 'test-theme-3', theme_dirs[1]),
     ]
     actual_themes = get_themes()
     self.assertItemsEqual(expected_themes, actual_themes)
Example #6
0
 def test_get_themes(self):
     """
     Tests get_themes returns all themes in themes directory.
     """
     theme_dirs = get_theme_base_dirs()
     expected_themes = [
         Theme('test-theme', 'test-theme', theme_dirs[0]),
         Theme('test-theme-2', 'test-theme-2', theme_dirs[0]),
         Theme('test-theme-3', 'test-theme-3', theme_dirs[1]),
     ]
     actual_themes = get_themes()
     self.assertItemsEqual(expected_themes, actual_themes)
    def parse_arguments(*args, **options):  # pylint: disable=unused-argument
        """
        Parse and validate arguments for update_assets command.

        Args:
            *args: Positional arguments passed to the update_assets command
            **options: optional arguments passed to the update_assets command
        Returns:
            A tuple containing parsed values for themes, system, source comments and output style.
            1. themes (list): list of Theme objects
            2. system (bool): True if system sass need to be compiled, False otherwise
            3. source_comments (bool): True if source comments need to be included in output, False otherwise
            4. output_style (str): Coding style for compiled css files.
        """
        given_themes = options.get("themes", ["all"])
        output_style = options.get("output_style", "nested")
        system = options.get("system", True)
        source_comments = options.get("source_comments", False)
        collect = options.get("collect", True)

        available_themes = {t.theme_dir_name: t for t in get_themes()}

        if 'no' in given_themes or 'all' in given_themes:
            # Raise error if 'all' or 'no' is present and theme names are also given.
            if len(given_themes) > 1:
                raise CommandError(
                    "Invalid themes value, It must either be 'all' or 'no' or list of themes."
                )
        # Raise error if any of the given theme name is invalid
        # (theme name would be invalid if it does not exist in themes directory)
        elif (not set(given_themes).issubset(list(available_themes.keys()))
              ) and is_comprehensive_theming_enabled():
            raise CommandError(
                "Given themes '{invalid_themes}' do not exist inside themes directory '{themes_dir}'"
                .format(
                    invalid_themes=", ".join(
                        set(given_themes) - set(available_themes.keys())),
                    themes_dir=get_theme_base_dirs(),
                ), )

        if "all" in given_themes:
            themes = get_themes()
        elif "no" in given_themes:
            themes = []
        else:
            # convert theme names to Theme objects
            themes = [available_themes.get(theme) for theme in given_themes]

        return themes, system, source_comments, output_style, collect
Example #8
0
    def test_improperly_configured_error(self):
        """
        Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not a string.
        """
        with override_settings(COMPREHENSIVE_THEME_DIRS=[None]):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()

        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS=''):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()
        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS=None):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()
        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS="ecommerce/tests/themes/tes-theme"):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()
Example #9
0
    def test_improperly_configured_error(self):
        """
        Tests ImproperlyConfigured error is raised when COMPREHENSIVE_THEME_DIRS is not a string.
        """
        with override_settings(COMPREHENSIVE_THEME_DIRS=[None]):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()

        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS=''):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()
        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS=None):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()
        # Test that COMPREHENSIVE_THEME_DIRS must be list
        with override_settings(COMPREHENSIVE_THEME_DIRS="ecommerce/tests/themes/tes-theme"):
            with self.assertRaises(ImproperlyConfigured):
                get_theme_base_dirs()