Example #1
0
def test_get_repo_object_failure(tmpdir):
    git_url = "https://localhost/git"
    repo_name = "foo"

    git_con = GitConnection(git_url, workspace=tmpdir)
    git_repo = GitRepository(repo_name, git_con)
    assert git_repo._repo is None
Example #2
0
def test_get_repo_object_existing_path(mock_git_repo, tmpdir):
    git_url = "https://localhost/git"
    repo_name = "foo"

    with mock_git_repo(tmpdir, repo_name, git_url):
        git_con = GitConnection(git_url, workspace=tmpdir)
        # The __init__() method calls _get_repo_object()
        git_repo = GitRepository(repo_name, git_con)
        assert isinstance(git_repo._repo, Repo)
Example #3
0
def test_file_contents(mock_git_repo, tmpdir):
    git_url = "https://localhost/git"
    repo_name = "foo"

    with mock_git_repo(tmpdir, repo_name, git_url):
        git_con = GitConnection(git_url, workspace=tmpdir)
        git_repo = GitRepository(repo_name, git_con)

        contents = git_repo.file_contents("README")
        assert contents == "Repository: foo"
Example #4
0
def test_non_existing_file_contents(mock_git_repo, tmpdir):
    git_url = "https://localhost/git"
    repo_name = "foo"

    with mock_git_repo(tmpdir, repo_name, git_url):
        git_con = GitConnection(git_url, workspace=tmpdir)
        git_repo = GitRepository(repo_name, git_con)

        with pytest.raises(CheckoutError) as excinfo:
            git_repo.file_contents("non-existing-file")
        assert "Failed to check out 'non-existing-file'" in str(excinfo.value)
Example #5
0
def test_directory_contents(mock_git_repo, tmpdir):
    git_url = "https://localhost/git"
    repo_name = "foo"

    with mock_git_repo(tmpdir, repo_name, git_url):
        git_con = GitConnection(git_url, workspace=tmpdir)
        git_repo = GitRepository(repo_name, git_con)

        contents = git_repo.directory_contents("/")
        # The contents dict should contain an entry for the README file
        readme_contents = contents["README"]
        assert isinstance(readme_contents, FileContent)
        assert readme_contents.path == "README"
Example #6
0
def test_get_remote_url(url, repo_name, expected):
    git_con = GitConnection(url)
    remote_url = git_con.get_remote_url(repo_name)
    assert remote_url == expected