Esempio n. 1
0
    def test_automatical_retrival_of_github_module(self, tmpdir):
        modules_directory = Path(tmpdir)
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality::*',
                'autoupdate': True,
            },
            modules_directory=modules_directory,
        )

        assert github_module_source.modules({}) == {
            'github::jakobgm/test-module.astrality::botswana': {
                'on_startup': {
                    'run': "echo 'Greetings from Botswana!'",
                },
            },
            'github::jakobgm/test-module.astrality::ghana': {
                'on_startup': {
                    'run': "echo 'Greetings from Ghana!'",
                },
            },
        }

        assert github_module_source.context({}) == {
            'geography': {
                'botswana': {
                    'capitol': 'Gaborone',
                },
                'ghana': {
                    'capitol': 'Accra',
                },
            },
        }
Esempio n. 2
0
    def test_specific_github_modules_enabled(self, test_config_directory,
                                             delete_jakobgm):
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality::botswana'
            },
            modules_directory=test_config_directory / 'test_modules',
        )
        github_module_source.config({})

        assert 'github::jakobgm/test-module.astrality::botswana' in github_module_source
        assert 'github::jakobgm/test-module.astrality::ghana' not in github_module_source
Esempio n. 3
0
    def test_that_all_modules_enabled_syntaxes_behave_identically(
        self,
        test_config_directory,
        delete_jakobgm,
    ):
        github_module_source1 = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality',
            },
            modules_directory=test_config_directory / 'test_modules',
        )
        github_module_source1.config({})

        # Sleep to prevent race conditions
        time.sleep(1)

        github_module_source2 = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality::*',
            },
            modules_directory=test_config_directory / 'test_modules',
        )
        github_module_source2.config({})

        assert github_module_source1 == github_module_source2
Esempio n. 4
0
    def test_that_enabled_repos_are_found(self, test_config_directory,
                                          delete_jakobgm):
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality'
            },
            modules_directory=test_config_directory / 'test_modules',
        )
        github_module_source.config({})

        assert 'github::jakobgm/test-module.astrality::botswana' in github_module_source
        assert 'github::jakobgm/test-module.astrality::ghana' in github_module_source

        assert 'github::jakobgm/test-module.astrality::non_existent' not in github_module_source
        assert 'github::jakobgm/another_repo::ghana' not in github_module_source
        assert 'astrality' not in github_module_source
        assert 'jakobgm' not in github_module_source
Esempio n. 5
0
 def test_that_username_and_repo_is_identified(self, tmpdir):
     modules_directory = Path(tmpdir)
     github_module_source = GithubModuleSource(
         enabling_statement={'name': 'github::jakobgm/astrality'},
         modules_directory=modules_directory,
     )
     assert github_module_source.github_user == 'jakobgm'
     assert github_module_source.github_repo == 'astrality'
Esempio n. 6
0
    def test_valid_names_which_indicate_github_modules(self):
        assert GithubModuleSource.represented_by(
            module_name='github::jakobgm/astrality', )
        assert GithubModuleSource.represented_by(
            module_name='github::jakobgm/astrality::module', )
        assert GithubModuleSource.represented_by(
            module_name='github::jakobgm/astrality::*', )
        assert GithubModuleSource.represented_by(
            module_name='github::user_name./repo-git.ast', )

        assert not GithubModuleSource.represented_by(module_name='w*', )
        assert not GithubModuleSource.represented_by(
            module_name='category::name', )
        assert not GithubModuleSource.represented_by(
            module_name='category::*', )
        assert not GithubModuleSource.represented_by(module_name='*::*', )
        assert not GithubModuleSource.represented_by(module_name='*', )
        assert not GithubModuleSource.represented_by(
            module_name='global_module', )
Esempio n. 7
0
    def test_use_of_autoupdating_github_source(
        self,
        patch_xdg_directory_standard,
    ):
        """When autoupdate is True, the latest revision should be pulled."""
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality',
                'autoupdate': True,
            },
            modules_directory=Path('/what/ever'),
        )

        # The repository is lazely cloned, so we need to get the config
        github_module_source.modules({})

        repo_dir = (patch_xdg_directory_standard /
                    'repositories/github/jakobgm/test-module.astrality')
        assert repo_dir.is_dir()

        # Move master to first commit in repository
        result = run_shell(
            command='git reset --hard d4c9723',
            timeout=5,
            fallback=False,
            working_directory=repo_dir,
        )
        assert result is not False

        # The readme does not exist in this commit
        readme = repo_dir / 'README.rst'
        assert not readme.is_file()

        del github_module_source
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality',
                'autoupdate': True,
            },
            modules_directory=Path('/what/ever'),
        )
        github_module_source.modules({})

        # The autoupdating should update the module to origin/master
        # containing the README.rst file
        assert readme.is_file()
Esempio n. 8
0
    def test_use_of_autoupdating_github_source(self, tmpdir):
        modules_directory = Path(tmpdir)

        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality',
                'autoupdate': True,
            },
            modules_directory=modules_directory,
        )

        # The repository is lazely cloned, so we need to get the config
        github_module_source.modules({})

        repo_dir = modules_directory / 'jakobgm' / 'test-module.astrality'
        assert repo_dir.is_dir()

        # Move master to first commit in repository
        result = run_shell(
            command='git reset --hard d4c9723',
            timeout=5,
            fallback=False,
            working_directory=repo_dir,
        )
        assert result is not False

        # The readme does not exist in this commit
        readme = repo_dir / 'README.rst'
        assert not readme.is_file()

        del github_module_source
        github_module_source = GithubModuleSource(
            enabling_statement={
                'name': 'github::jakobgm/test-module.astrality',
                'autoupdate': True,
            },
            modules_directory=modules_directory,
        )
        github_module_source.modules({})

        # The autoupdating should update the module to origin/master
        # containing the README.rst file
        assert readme.is_file()