# HG changeset patch # User Georges Racinet <georges.racinet@octobus.net> # Date 1670951901 -3600 # Tue Dec 13 18:18:21 2022 +0100 # Branch stable # Node ID 463b3a78f8c1b774d88612db9dc55afbae39a994 # Parent 311ed039b41193d393c0f5440f31caa6cd3b7ad8 RepositoryService.SetFullPath: modernized Gitaly comparison test Less boilerplate with `RpcHelper`, now that it can normalize error details. diff --git a/tests_with_gitaly/test_repository_service.py b/tests_with_gitaly/test_repository_service.py --- a/tests_with_gitaly/test_repository_service.py +++ b/tests_with_gitaly/test_repository_service.py @@ -218,49 +218,32 @@ def test_set_full_path(gitaly_comparison, server_repos_root): fixture = gitaly_comparison - repo_stubs = dict( - hg=RepositoryServiceStub(fixture.hgitaly_channel), - git=RepositoryServiceStub(fixture.gitaly_channel) - ) - - def do_rpc(vcs, path, grpc_repo=fixture.gitaly_repo): - return repo_stubs[vcs].SetFullPath( - SetFullPathRequest(repository=grpc_repo, path=path)) - - def assert_compare(path): - assert do_rpc('hg', path) == do_rpc('git', path) + def normalize_repo_not_found(msg, **kw): + return msg.replace('git repo', 'Mercurial repo') - def assert_error_compare(path, - grpc_repo=None, - msg_normalizer=lambda m: m): - kwargs = dict(grpc_repo=grpc_repo) if grpc_repo is not None else {} - with pytest.raises(Exception) as hg_exc_info: - do_rpc('hg', path, **kwargs) - with pytest.raises(Exception) as git_exc_info: - do_rpc('git', path, **kwargs) - hg_exc, git_exc = hg_exc_info.value, git_exc_info.value - assert hg_exc.code() == git_exc.code() - hg_msg, git_msg = hg_exc.details(), git_exc.details() - assert msg_normalizer(hg_msg) == msg_normalizer(git_msg) + rpc_helper = fixture.rpc_helper( + stub_cls=RepositoryServiceStub, + method_name='SetFullPath', + request_cls=SetFullPathRequest, + error_details_normalizer=normalize_repo_not_found, + ) + assert_compare = rpc_helper.assert_compare + assert_error_compare = rpc_helper.assert_compare_errors # success case - assert_compare('group/project') + assert_compare(path='group/project') # error cases assert_error_compare('') - def normalize_repo_not_found(msg): - return msg.replace('git repo', 'Mercurial repo') - - assert_error_compare('some/full/path', - grpc_repo=Repository( + assert_error_compare(path='some/full/path', + repository=Repository( storage_name=fixture.gitaly_repo.storage_name, relative_path='no/such/repo'), - msg_normalizer=normalize_repo_not_found, ) - assert_error_compare('some/full/path', - grpc_repo=Repository( + assert_error_compare(path='some/full/path', + repository=Repository( relative_path=fixture.gitaly_repo.relative_path, storage_name='unknown'))