示例#1
0
 def test_command_injection_exit(fixture_tmpdir):
     """test that subprocess.run isn't raising an exception due to exit 1"""
     mocked_self = mock.MagicMock()
     mocked_self._gitcmd = Gitget._gitcmd
     mocked_self._repodir = fixture_tmpdir
     # must not raise an exception
     Gitget._run_command(mocked_self, ("--version", ";", "exit", "1"))
示例#2
0
    def test_non_existing_commit():
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(repository="https://github.com/simonkowallik/ihac",
                        commit=40 * "1") as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
示例#3
0
 def test_Gitget_tag():
     with Gitget(
             repository="https://github.com/simonkowallik/as3ninjaDemo",
             branch="tag_v1.0",
     ) as gitrepo:
         assert isinstance(gitrepo.info, dict)
         assert gitrepo.info["branch"] == "tag_v1.0"
示例#4
0
    def test_invalid_commit_id():
        with pytest.raises(ValueError) as exception_info:
            with Gitget(repository="https://github.com/simonkowallik/ihac",
                        commit="1234567") as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is ValueError
示例#5
0
 def test_full_clone():
     with Gitget(
             repository="https://github.com/simonkowallik/as3ninjaDemo",
             commit="924f79f8569317d01d1be7d6a77ac8e2b88332ff",
             depth=0,
     ) as gitrepo:
         assert isinstance(gitrepo.info, dict)
示例#6
0
 def test_command_injection_output(fixture_tmpdir):
     """test that subprocess.run output doesn't contain output from injected command"""
     mocked_self = mock.MagicMock()
     mocked_self._gitcmd = Gitget._gitcmd
     mocked_self._repodir = fixture_tmpdir
     output = Gitget._run_command(mocked_self, ("--version", ";", "pwd"))
     assert mocked_self._repodir not in output
示例#7
0
 def test_Gitget_depth0():
     with Gitget(
             repository="https://github.com/simonkowallik/as3ninjaDemo",
             branch="master",
             depth=0,
     ) as gitrepo:
         assert isinstance(gitrepo.info, dict)
         assert gitrepo.info["branch"] == "master"
示例#8
0
    def test_non_existing_repository():
        """test a non-existing repository"""
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository="https://github.com/repository-does-not-exist"
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
示例#9
0
    def test_TimeoutExpired():
        """test TimeoutExpired is raised when an operation takes too long."""
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository="https://github.com/python/cpython") as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
        assert "TimeoutExpired" in str(exception_info.value)
示例#10
0
    def test_commit_missing_in_clone():
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository="https://github.com/simonkowallik/as3ninjaDemo",
                    commit="924f79f8569317d01d1be7d6a77ac8e2b88332ff",
                    depth=3,
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
示例#11
0
    def test_Gitget_depth_negative():
        with pytest.raises(ValueError) as exception_info:
            with Gitget(
                    repository="https://github.com/simonkowallik/ihac",
                    branch="master",
                    depth=-1,
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is ValueError
示例#12
0
    def test_custom_repodir(fixture_tmpdir):
        repodir = fixture_tmpdir
        with Gitget(
                repository="https://github.com/simonkowallik/ihac",
                branch="master",
                repodir=repodir,
        ) as gitrepo:
            assert isinstance(gitrepo.info, dict)
            assert gitrepo.info["branch"] == "master"

        assert Path(repodir).exists()
示例#13
0
    def test_custom_repodir_2ndclone_force(fixture_tmpdir):
        repodir = fixture_tmpdir
        # first clone
        with Gitget(
                repository="https://github.com/simonkowallik/ihac",
                branch="master",
                repodir=repodir,
        ) as gitrepo:
            assert isinstance(gitrepo.info, dict)
            assert gitrepo.info["branch"] == "master"

        # second clone to existing repo
        with Gitget(
                repository="https://github.com/simonkowallik/ihac",
                branch="master",
                repodir=repodir,
                force=True,
        ) as gitrepo:
            assert isinstance(gitrepo.info, dict)
            assert gitrepo.info["branch"] == "master"
示例#14
0
    def test_non_existing_repository():
        # TODO: this prompts for user+password. requires credential handling
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository=
                    "https://github.com/simonkowallik/does-not-exist",
                    branch="doesnt-exist",
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
示例#15
0
    def test_custom_repodir_2ndclone_noforce(fixture_tmpdir):
        repodir = fixture_tmpdir
        # first clone
        with Gitget(
                repository="https://github.com/simonkowallik/ihac",
                branch="master",
                repodir=repodir,
        ) as gitrepo:
            assert isinstance(gitrepo.info, dict)
            assert gitrepo.info["branch"] == "master"

        # second clone to existing repo without force raises exception
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository="https://github.com/simonkowallik/ihac",
                    branch="master",
                    repodir=repodir,
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
示例#16
0
    def test_rmrepodir(fixture_tmpdir):
        repodir = fixture_tmpdir
        with Gitget(
                repository="https://github.com/simonkowallik/as3ninjaDemo",
                branch="master",
                repodir=repodir,
        ) as gitrepo:
            assert isinstance(gitrepo.info, dict)
            assert gitrepo.info["branch"] == "master"
            gitrepo.rmrepodir()

        assert Path(repodir).exists() is False
示例#17
0
    def test_private_repository():
        """test a private repository requiring authentication.
        This test will prompt for credentials if not authenticated and will run into a timeout.
        """
        with pytest.raises(GitgetException) as exception_info:
            with Gitget(
                    repository=
                    "https://github.com/simonkowallik/some-private-repository"
            ) as gitrepo:
                print(gitrepo.info)

        assert exception_info.type is GitgetException
        assert "CalledProcessError" in str(exception_info.value)
示例#18
0
 def test_Gitget_tag():
     with Gitget(repository="https://github.com/simonkowallik/ihac",
                 branch="2.0") as gitrepo:
         assert isinstance(gitrepo.info, dict)
         assert gitrepo.info["branch"] == "2.0"
示例#19
0
 def test_Gitget_repo_only():
     with Gitget(
             repository="https://github.com/simonkowallik/ihac") as gitrepo:
         assert isinstance(gitrepo.info, dict)
         assert gitrepo.info["branch"] == "master"
示例#20
0
 def test_sh_quote__command_injection():
     teststring = "'; ls /; echo"
     result = Gitget._sh_quote(teststring)
     assert result == "''\"'\"'; ls /; echo'"
示例#21
0
 def test_sh_quote__simple_quote():
     teststring = "a b c"
     result = Gitget._sh_quote(teststring)
     assert result == f"'{teststring}'"
示例#22
0
 def test_sh_quote__integer():
     teststring = 1234
     result = Gitget._sh_quote(teststring)
     assert result == f"{teststring}"
示例#23
0
 def test_sh_quote__no_quote():
     teststring = "abc"
     result = Gitget._sh_quote(teststring)
     assert result == f"{teststring}"
示例#24
0
 def test_HEAD_invalid():
     teststring = "HEAD~ invalid"
     result = Gitget._sh_quote(teststring)
     assert result == f"'{teststring}'"
示例#25
0
 def test_dir_exists_on_with():
     with Gitget(
             repository="https://github.com/simonkowallik/ihac") as gitrepo:
         assert Path(gitrepo.repodir + "/.git").exists()
示例#26
0
 def test_datetime_format_string():
     result = Gitget._datetime_format("1234567890")
     assert result == "2009-02-13T23:31:30Z"
示例#27
0
 def test_HEAD_no_int():
     teststring = "HEAD~no_int"
     result = Gitget._sh_quote(teststring)
     assert result == f"'{teststring}'"
示例#28
0
 def test_datetime_format_int():
     result = Gitget._datetime_format(1234567890)
     assert result == "2009-02-13T23:31:30Z"
示例#29
0
 def test_datetime_format_returns_string():
     result = Gitget._datetime_format("1234567890")
     assert isinstance(result, str)
示例#30
0
 def test_shell_false(mocker):
     """test that subprocess.run is using shell=False"""
     mocked_run = mocker.patch("as3ninja.gitget.run")
     Gitget._run_command(mock.MagicMock(), ("ls"))
     assert "shell=False" in str(mocked_run.call_args)