diff --git a/src/main/python/ddadevops/release-mixin/test/test_services.py b/src/main/python/ddadevops/release-mixin/test/test_services.py index 4b3926c..51fa89b 100644 --- a/src/main/python/ddadevops/release-mixin/test/test_services.py +++ b/src/main/python/ddadevops/release-mixin/test/test_services.py @@ -19,61 +19,33 @@ sys.path.append(parent) # directory. from services import PrepareReleaseService, TagAndPushReleaseService -from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository -from infrastructure_api import GitApi +from mock_infrastructure import MockReleaseRepository, MockReleaseTypeRepository, MockVersionRepository +from mock_infrastructure_api import MockGitApi -def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch): - monkeypatch.chdir(tmp_path) - -def test_prepare_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch): # todo: maybe use mocks for service api tests +def test_prepare_release_service(): # todo: maybe use mocks for service api tests # init - file_name = 'config.json' - with open(f'test/resources/{file_name}', 'r') as json_file: - contents = json_file.read() - f = tmp_path / file_name - f.write_text(contents) - change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path - - git_api = GitApi() - git_api.init() - git_api.add_file(file_name) - git_api.commit("MINOR release") - - repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main') - prepare_release_service = PrepareReleaseService(repo) - prepare_release_service.main_branch = "main" + mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main') + prepare_release_service = PrepareReleaseService(mock_release_repo) + prepare_release_service.git_api = MockGitApi() prepare_release_service.write_and_commit_release() - latest_commit = git_api.get_latest_commit() + #test + assert prepare_release_service.release_repo.get_release_count == 1 + assert prepare_release_service.release.validate_count == 1 + assert prepare_release_service.release_repo.version_repository.write_file_count == 1 + assert prepare_release_service.git_api.add_file_count == 1 + assert prepare_release_service.git_api.commit_count == 1 - assert '"Release v123.124.0 "\n' in latest_commit - - prepare_release_service.write_and_commit_bump() - latest_commit = git_api.get_latest_commit() - - assert '"Version bump "\n' in latest_commit - -def test_tag_and_push_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch): + prepare_release_service.write_and_commit_release() #todo: add asserts + +def test_tag_and_push_release_service(): # init - file_name = 'config.json' - with open(f'test/resources/{file_name}', 'r') as json_file: - contents = json_file.read() - f = tmp_path / file_name - f.write_text(contents) - change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path + mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main') + tag_and_push_release_service = TagAndPushReleaseService(MockGitApi()) + tag_and_push_release_service.tag_release(mock_release_repo.get_release()) + tag_and_push_release_service.push_release() - git_api = GitApi() - git_api.init() - git_api.add_file(file_name) - git_api.commit("MINOR release") - - repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main') - - prepare_release_service = PrepareReleaseService(repo) - prepare_release_service.main_branch = "main" - prepare_release_service.write_and_commit_release() - - tag_and_push_release_service = TagAndPushReleaseService(git_api) - tag_and_push_release_service.tag_release(repo.get_release()) - - assert 'v123.124.0\n' in git_api.get_latest_tag() + #test + assert tag_and_push_release_service.git_api.tag_annotated_count == 1 + assert tag_and_push_release_service.git_api.push_count == 1 +