From 821e06f82a4d1c38a98c2f4b8d6ec0a9a9273da0 Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 22 Feb 2023 11:33:44 +0100 Subject: [PATCH] Pass VersionRepo to InitReleaseService Update Tests. --- services.py | 48 +++++++++++++++++++++++++++++-------------- test/test_services.py | 12 ++++++----- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/services.py b/services.py index 37445b2..35573bb 100644 --- a/services.py +++ b/services.py @@ -1,12 +1,14 @@ from version_repository import VersionRepository from release_type import ReleaseType from git_repository import GitRepository +from version import Version class InitReleaseService(): - def __init__(self, file): - self.file = file - self.version_repo = None + def __init__(self, version_repo: VersionRepository): + if version_repo is None: + raise Exception('VersionRepo was not created. Did you run create_release_version()?') + self.version_repo = version_repo def __calculate_release_type(self, commit_string = None): if commit_string is None: @@ -14,27 +16,43 @@ class InitReleaseService(): else: return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit() - def get_version(self, release_type): - self.version_repo = VersionRepository(self.file) + def get_version(self, release_type): return self.version_repo.get_version(release_type) def create_release_version(self, commit_string = None): release_type = self.__calculate_release_type(commit_string) - version = self.get_version(release_type).create_release_version() - - self.version_repo.write_file(version.get_version_string()) + version = self.get_version(release_type).create_release_version() + return version - def create_bump_version(self): - if self.version_repo == None: - raise Exception('VersionRepo was not created. Did you run create_release_version()?') + def create_bump_version(self): version = self.get_version(ReleaseType.BUMP).create_bump_version() + return version + - self.version_repo.write_file(version.get_version_string()) - - - class PrepareReleaseService(): + + def __init__(self): + self.version_repo + pass + + def run_tests(self): # maybe auto? + pass + + def prepare_release(self, version: Version): + # self.version_repo.write_file(version.get_version_string()) # side effect + pass + + def prepare_bump(self, version: Version): + # self.version_repo.write_file(version.get_version_string()) # side effect + pass + + + # write + + + # add + # commit pass class TagAndPushReleaseService(): diff --git a/test/test_services.py b/test/test_services.py index 45367f9..a5deaa1 100644 --- a/test/test_services.py +++ b/test/test_services.py @@ -19,6 +19,7 @@ sys.path.append(parent) from services import InitReleaseService from release_type import ReleaseType +from version_repository import VersionRepository def test_init_release_service(tmp_path): # init @@ -29,11 +30,12 @@ def test_init_release_service(tmp_path): f = tmp_path / file_name f.write_text(contents) - release_service = InitReleaseService(f) - release_service.create_release_version(commit_string='Release MINOR') + repo = VersionRepository(f) + release_service = InitReleaseService(repo) + version = release_service.create_release_version(commit_string='Release MINOR') - assert '"version": "123.124.0"' in f.read_text() + assert "123.124.0" in version.get_version_string() - release_service.create_bump_version() + version = release_service.create_bump_version() - assert '"version": "123.124.1-SNAPSHOT"' in f.read_text() \ No newline at end of file + assert "123.123.457-SNAPSHOT" in version.get_version_string() \ No newline at end of file