Ejemplo n.º 1
0
def test_destroy_and_multiple_remotes(mock_repo, monkeypatch):
    """
    GIVEN GitRepo initialized with a path and repo
    WHEN destroy_and_reclone is called
    AND the repo has multiple remotes
    THEN Repo.clone_from is called
    AND create_remote is called
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    clone = GitRepo(repo=mock_repo)
    local_dir = '/tmp/8f697668fgitwrappertest'
    clone.repo.working_dir = local_dir

    remote = Mock(spec=git.Remote)
    remote.configure_mock(name="otherremote", url="http://example.com/another")
    clone.repo.remotes.append(remote)

    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        new_repo_mock = Mock()
        mock_clone.return_value = new_repo_mock
        clone.destroy_and_reclone()
        assert mock_clone.called is True
        mock_clone.assert_called_with('http://example.com',
                                      local_dir,
                                      bare=False)
        new_repo_mock.create_remote.assert_called_with(
            "otherremote",
            "http://example.com/another"
        )
Ejemplo n.º 2
0
def test_destroy_no_path_no_repo(monkeypatch):
    """
    GIVEN GitRepo initialized with no path or repo object
    WHEN destroy_and_reclone is called
    THEN an exception is raised
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    with pytest.raises(Exception):
        clone = GitRepo('', None)
        clone.destroy_and_reclone()
Ejemplo n.º 3
0
def test_destroy_no_remotes(mock_repo, monkeypatch):
    """
    GIVEN GitRepo initialized with a path and repo
    WHEN destroy_and_reclone is called
    AND the repo does not have any remotes configured
    THEN an exception is raised
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    clone = GitRepo(repo=mock_repo)

    with pytest.raises(exceptions.RepoCreationException):
        clone.repo.remotes = {}
        clone.destroy_and_reclone()
Ejemplo n.º 4
0
def test_destroy_and_reclone(clone_repo_root, clone_repo_url):
    repo_root = clone_repo_root
    repo_url = clone_repo_url

    # Start by creating a new repo to destroy
    GitRepo.clone(repo_url, repo_root)

    # Get a timestamp for a random file
    f_path = os.path.join(repo_root, 'requirements.txt')
    orig_timestamp = os.path.getmtime(f_path)

    # Run the reclone action
    clone = GitRepo(repo_root)
    clone.destroy_and_reclone()

    # Ensure timestamp changed
    new_timestamp = os.path.getmtime(f_path)
    assert new_timestamp != orig_timestamp
Ejemplo n.º 5
0
def test_destroy_and_reclone(mock_repo, monkeypatch):
    """
    GIVEN GitRepo initialized with a path and repo
    WHEN destroy_and_reclone is called
    THEN Repo.clone_from is called
    WITH the expected remote url and local working dir
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    clone = GitRepo(repo=mock_repo)
    local_dir = '/tmp/8f697668fgitwrappertest'
    clone.repo.working_dir = local_dir

    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        clone.destroy_and_reclone()
        assert mock_clone.called is True
        mock_clone.assert_called_with('http://example.com',
                                      local_dir,
                                      bare=False)
Ejemplo n.º 6
0
def test_destroy_no_remote_named_origin(mock_repo, monkeypatch):
    """
    GIVEN GitRepo initialized with a path and repo
    WHEN destroy_and_reclone is called
    AND the repo does not have a remote named origin
    THEN Repo.clone_from is called
    WITH the remote url and local working dir from another remote
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    clone = GitRepo(repo=mock_repo)
    local_dir = '/tmp/8f697667fgitwrappertest'
    clone.repo.working_dir = local_dir

    remote = Mock(spec=git.Remote)
    remote.configure_mock(name="onlyremote", url="http://example.com/another")
    clone.repo.remotes = [remote]

    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        clone.destroy_and_reclone()
        assert mock_clone.called is True
        mock_clone.assert_called_with('http://example.com/another',
                                      local_dir,
                                      bare=False)
Ejemplo n.º 7
0
def test_destroy_and_remote_creation_fails(mock_repo, monkeypatch):
    """
    GIVEN GitRepo initialized with a path and repo
    WHEN destroy_and_reclone is called
    AND the repo has several remotes
    AND create_remote fails
    THEN a RemoteException is raised
    """
    monkeypatch.setattr(shutil, 'rmtree', Mock())
    clone = GitRepo(repo=mock_repo)
    local_dir = '/tmp/8f697668fgitwrappertest'
    clone.repo.working_dir = local_dir

    remote = Mock(spec=git.Remote)
    remote.configure_mock(name="otherremote", url="http://example.com/another")
    clone.repo.remotes.append(remote)

    with patch('git.repo.base.Repo.clone_from') as mock_clone:
        new_repo_mock = Mock()
        mock_clone.return_value = new_repo_mock
        with pytest.raises(exceptions.RemoteException):
            new_repo_mock.create_remote.side_effect = git.GitCommandError('remote', '')
            clone.destroy_and_reclone()
        assert mock_clone.called is True