From ef51db14032c663cdf7b505b776b52692d9bc54e Mon Sep 17 00:00:00 2001 From: bom Date: Tue, 28 Feb 2023 13:25:47 +0100 Subject: [PATCH] Fix some of the tests --- domain.py | 6 +++--- infrastructure.py | 7 ++++--- release_mixin.py | 8 ++++---- services.py | 8 ++++---- test/test_domain.py | 12 ++++++------ test/test_infrastructure.py | 2 +- test/test_services.py | 7 ++++--- 7 files changed, 26 insertions(+), 24 deletions(-) diff --git a/domain.py b/domain.py index 7fa79bd..bcfedeb 100644 --- a/domain.py +++ b/domain.py @@ -1,5 +1,5 @@ from enum import Enum - +from pathlib import Path class Config(): def __init__(self, main_branch): @@ -49,13 +49,13 @@ class Version(): return self.version_string def create_release_version(self, release_type: ReleaseType): - release_version = Version(self.version_list.copy()) + release_version = Version(self.id, self.version_list.copy()) release_version.is_snapshot = self.is_snapshot release_version.increment(release_type) return release_version def create_bump_version(self): - bump_version = Version(self.version_list.copy()) + bump_version = Version(self.id, self.version_list.copy()) bump_version.is_snapshot = self.is_snapshot bump_version.increment(ReleaseType.BUMP) return bump_version diff --git a/infrastructure.py b/infrastructure.py index 4bf963a..3989ed6 100644 --- a/infrastructure.py +++ b/infrastructure.py @@ -26,7 +26,7 @@ class VersionRepository(): self.file_handler = self.load_file() version_list, is_snapshot = self.parse_file() - version = Version(version_list) + version = Version(self.file, version_list) version.is_snapshot = is_snapshot return version @@ -50,9 +50,10 @@ class ReleaseTypeRepository(): return None class ReleaseRepository(): - def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository): + def __init__(self, version_repository: VersionRepository, release_type_repository: ReleaseTypeRepository, main_branch: str): self.version_repository = version_repository self.release_type_repository = release_type_repository + self.main_branch = main_branch def get_release(self) -> Release: - return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version()) + return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch) diff --git a/release_mixin.py b/release_mixin.py index 3d6c992..648c32a 100644 --- a/release_mixin.py +++ b/release_mixin.py @@ -2,7 +2,7 @@ import copy from ddadevops import DevopsBuild from ddadevops import execute from ddadevops import gopass_field_from_path, gopass_password_from_path -from infrastructure import VersionRepository, GitRepository +from infrastructure import VersionRepository, GitApi from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService from domain import ReleaseType, Version @@ -28,7 +28,7 @@ class ReleaseMixin(DevopsBuild): self.config_file = release_mixin_config['config_file'] self.main_branch = release_mixin_config['main_branch'] self.version_repo = VersionRepository(self.config_file) - self.git_repo = GitRepository() + self.git_api = GitApi() self.release_version = None self.bump_version = None self.commit_string = None @@ -39,7 +39,7 @@ class ReleaseMixin(DevopsBuild): self.bump_version = self.release_version.create_bump_version() def prepare_release(self): - prepare_release_service = PrepareReleaseService(self.version_repo, self.git_repo, self.config_file, self.main_branch) + prepare_release_service = PrepareReleaseService(self.version_repo, self.git_api, self.config_file, self.main_branch) if self.release_version is None or self.bump_version is None: raise Exception('prepare_release was called before init_release') @@ -48,5 +48,5 @@ class ReleaseMixin(DevopsBuild): prepare_release_service.write_and_commit_bump(self.bump_version) def tag_and_push_release(self): - tag_and_push_release_service = TagAndPushReleaseService(self.git_repo) + tag_and_push_release_service = TagAndPushReleaseService(self.git_api) tag_and_push_release_service.tag_and_push_release(self.release_version) diff --git a/services.py b/services.py index e3e87cc..068ee3b 100644 --- a/services.py +++ b/services.py @@ -1,5 +1,5 @@ from pathlib import Path -from infrastructure import ReleaseRepository +from infrastructure import ReleaseRepository, GitApi from domain import Version, ReleaseType @@ -34,13 +34,13 @@ class PrepareReleaseService(): class TagAndPushReleaseService(): - def __init__(self, git_repository: GitRepository): - self.git_repository = git_repository + def __init__(self, git_api: GitApi): + self.git_api = git_api def tag_and_push_release(self, release_version: Version): annotation = 'v' + release_version.get_version_string() message = 'Release ' + annotation - self.git_repository.tag_annotated(annotation, message, 1) + self.git_api.tag_annotated(annotation, message, 1) # self.git_repository.push() diff --git a/test/test_domain.py b/test/test_domain.py index 68fd7bf..412b409 100644 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -20,33 +20,33 @@ sys.path.append(parent) from domain import Version, ReleaseType from infrastructure import VersionRepository -def test_version(): - version = Version([1, 2, 3]) +def test_version(tmp_path): + version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.SNAPSHOT) assert version.get_version_string() == "1.2.3-SNAPSHOT" assert version.version_list == [1, 2, 3] assert version.is_snapshot - version = Version([1, 2, 3]) + version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.BUMP) assert version.get_version_string() == "1.2.4-SNAPSHOT" assert version.version_list == [1, 2, 4] assert version.is_snapshot - version = Version([1, 2, 3]) + version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.PATCH) assert version.get_version_string() == "1.2.4" assert version.version_list == [1, 2, 4] assert not version.is_snapshot - version = Version([1, 2, 3]) + version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.MINOR) assert version.get_version_string() == "1.3.0" assert version.version_list == [1, 3, 0] assert not version.is_snapshot - version = Version([1, 2, 3]) + version = Version(tmp_path, [1, 2, 3]) version.increment(ReleaseType.MAJOR) assert version.get_version_string() == "2.0.0" assert version.version_list == [2, 0, 0] diff --git a/test/test_infrastructure.py b/test/test_infrastructure.py index 1e0ff48..5ae86ec 100644 --- a/test/test_infrastructure.py +++ b/test/test_infrastructure.py @@ -115,7 +115,7 @@ def test_release_repository(tmp_path): f.write_text(contents) # test - sut = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(TestGitApi('MINOR test'))) + sut = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(TestGitApi('MINOR test')), 'main') release = sut.get_release() assert release is not None diff --git a/test/test_services.py b/test/test_services.py index 1eef213..4815e2c 100644 --- a/test/test_services.py +++ b/test/test_services.py @@ -19,7 +19,8 @@ sys.path.append(parent) from services import InitReleaseService from domain import ReleaseType -from infrastructure import VersionRepository +from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository +from infrastructure_api import GitApi def test_init_release_service(tmp_path): # init @@ -30,9 +31,9 @@ def test_init_release_service(tmp_path): f = tmp_path / file_name f.write_text(contents) - repo = VersionRepository(f) + repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main') release_service = InitReleaseService(repo) - version = release_service.create_release_version(commit_string='Release MINOR') + version = release_service.get_version().create_release_version(ReleaseType.MINOR) assert "123.124.0" in version.get_version_string()