def test_sync_repo(mocker, db_session, default_repo): mock_vcs_backend = mocker.MagicMock(spec=Vcs) mock_get_vcs = mocker.patch.object(Repository, "get_vcs", return_value=mock_vcs_backend) def log(parent): if parent is None: yield RevisionResult( sha="a" * 40, message="hello world!", author="Example <*****@*****.**>", author_date=datetime(2013, 9, 19, 22, 15, 22), ) mock_vcs_backend.log.side_effect = log sync_repo(repo_id=default_repo.id) mock_get_vcs.assert_called_once_with() mock_vcs_backend.log.assert_any_call(parent=None) mock_vcs_backend.log.assert_any_call(parent="a" * 40) assert default_repo.last_update_attempt is not None assert default_repo.last_update is not None assert default_repo.status == RepositoryStatus.active # build sync is abstracted via sync_with_builder mock_vcs_backend.update.assert_called_once_with()
def sync(repository_full_name): owner_name, repo_name = repository_full_name.split('/', 1) repo = Repository.query.unrestricted_unsafe().filter( Repository.owner_name == owner_name, Repository.name == repo_name, ).first() sync_repo(repo_id=repo.id)
def sync(repository): provider, owner_name, repo_name = repository.split("/", 2) repo = Repository.query.unrestricted_unsafe().filter( Repository.provider == RepositoryProvider(provider), Repository.owner_name == owner_name, Repository.name == repo_name, ).first() sync_repo(repo_id=repo.id)
def test_invalid_public_key(mocker, db_session, default_repo): option = ItemOption(item_id=default_repo.id, name="auth.private-key", value="foo") db_session.add(option) db_session.flush() mock_vcs_backend = mocker.MagicMock(spec=Vcs) mocker.patch.object(Repository, "get_vcs", return_value=mock_vcs_backend) mock_vcs_backend.exists.return_value = False mock_vcs_backend.clone.side_effect = InvalidPublicKey(["git", "clone"], 1) sync_repo(repo_id=default_repo.id) assert default_repo.status == RepositoryStatus.inactive assert not ItemOption.query.get(option.id)
def sync(repository_url): repo = Repository.query.unrestricted_unsafe().filter( Repository.url == repository_url, ).first() sync_repo(repo_id=repo.id)