Example #1
0
    def test_nested_role(self):
        subdir1 = os.path.join(self.roles_dir, "subdir1")
        os.mkdir(subdir1)
        role_dir = os.path.join(subdir1, "my_role")
        os.mkdir(role_dir)

        contents = ContentFinder().find_contents(self.temp_dir)
        assert len(contents) == 0

        dir_in_role = os.path.join(role_dir, "tasks")
        os.mkdir(dir_in_role)

        contents = ContentFinder().find_contents(self.temp_dir)
        assert list(contents)[0].path == "roles/subdir1/my_role"
Example #2
0
 def test_skip_plugin_files(self):
     with open(os.path.join(self.module_dir, '__init__.py'), 'w'):
         pass
     with open(os.path.join(self.module_dir, 'main.go'), 'w'):
         pass
     contents = ContentFinder().find_contents(self.temp_dir)
     assert not any(True for _ in contents)
Example #3
0
 def _load_contents(self):
     """Find and load data for each content inside the collection."""
     found_contents = ContentFinder().find_contents(self.path, self.log)
     for content_type, rel_path in found_contents:
         loader_cls = loaders.get_loader_cls(content_type)
         loader = loader_cls(content_type, rel_path, self.path, self.log)
         content_obj = loader.load()
         yield content_obj
Example #4
0
    def _load_contents(self):
        contents = ContentFinder().find_contents(self.path, self.log)

        # TEMP: logging found contents
        self.log.info('')
        self.log.info('=== Found contents ===')
        for content in contents:
            self.log.info(content.path)
Example #5
0
    def test_error_file_in_roles_dir(self):
        with open(os.path.join(self.role_dir, 'main.yml'), 'w'):
            pass
        my_role_dir = os.path.join(self.role_dir, 'my_role')
        os.mkdir(my_role_dir)

        contents = ContentFinder().find_contents(self.temp_dir)
        content_items = [os.path.basename(c.path) for c in contents]
        assert 'my_role' in content_items
        assert len(content_items) == 1
Example #6
0
    def test_nested_plugin(self):
        subdir1 = os.path.join(self.module_dir, 'subdir1')
        os.mkdir(subdir1)
        subdir2 = os.path.join(subdir1, 'subdir2')
        os.mkdir(subdir2)
        with open(os.path.join(subdir2, 'nested_module.py'), 'w'):
            pass

        contents = ContentFinder().find_contents(self.temp_dir)
        assert list(contents)[0].path == \
            'plugins/modules/subdir1/subdir2/nested_module.py'
Example #7
0
    def test_nested_plugin(self):
        subdir1 = os.path.join(self.module_dir, "subdir1")
        os.mkdir(subdir1)
        subdir2 = os.path.join(subdir1, "subdir2")
        os.mkdir(subdir2)
        with open(os.path.join(subdir2, "nested_module.py"), "w"):
            pass

        contents = ContentFinder().find_contents(self.temp_dir)
        assert list(contents)[
            0].path == "plugins/modules/subdir1/subdir2/nested_module.py"
Example #8
0
    def test_error_file_in_roles_dir(self):
        with open(os.path.join(self.roles_dir, "main.yml"), "w"):
            pass
        my_roles_dir = os.path.join(self.roles_dir, "my_role")
        os.mkdir(my_roles_dir)
        os.mkdir(os.path.join(my_roles_dir, "tasks"))

        contents = ContentFinder().find_contents(self.temp_dir)
        content_items = [os.path.basename(c.path) for c in contents]
        assert "my_role" in content_items
        assert len(content_items) == 1
    def test_find_content(self):
        with open(os.path.join(self.module_dir, '__init__.py'), 'w'):
            pass
        with open(os.path.join(self.module_dir, 'first_module.py'), 'w'):
            pass
        with open(os.path.join(self.module_dir, 'second_module.py'), 'w'):
            pass

        my_role_dir = os.path.join(self.role_dir, 'my_role')
        os.mkdir(my_role_dir)

        contents = ContentFinder().find_contents(self.temp_dir)

        content_items = [os.path.basename(c.path) for c in contents]
        assert 'first_module.py' in content_items
        assert 'second_module.py' in content_items
        assert '__init__.py' not in content_items
        assert 'my_role' in content_items
Example #10
0
    def test_find_content(self):
        with open(os.path.join(self.module_dir, "__init__.py"), "w"):
            pass
        with open(os.path.join(self.module_dir, "first_module.py"), "w"):
            pass
        with open(os.path.join(self.module_dir, "second_module.py"), "w"):
            pass

        my_roles_dir = os.path.join(self.roles_dir, "my_role")
        os.mkdir(my_roles_dir)
        os.mkdir(os.path.join(my_roles_dir, "tasks"))

        contents = ContentFinder().find_contents(self.temp_dir)

        content_items = [os.path.basename(c.path) for c in contents]
        assert "first_module.py" in content_items
        assert "second_module.py" in content_items
        assert "__init__.py" not in content_items
        assert "my_role" in content_items
        assert len(content_items) == 3
Example #11
0
 def test_find_no_content(self):
     contents = ContentFinder().find_contents(self.temp_dir)
     assert not any(True for _ in contents)
Example #12
0
 def test_error_nested_plugin(self):
     my_nested_module = os.path.join(self.module_dir, 'another_dir')
     os.mkdir(my_nested_module)
     with pytest.raises(
             exc.ContentFindError, match='Nested plugins not supported'):
         ContentFinder().find_contents(self.temp_dir)
 def test_error_file_in_roles_dir(self):
     with open(os.path.join(self.role_dir, 'main.yml'), 'w'):
         pass
     with pytest.raises(exc.ContentFindError, match='File inside "roles"'):
         ContentFinder().find_contents(self.temp_dir)