Pass VersionRepo to InitReleaseService

Update Tests.
This commit is contained in:
erik 2023-02-22 11:33:44 +01:00
parent 1d2cb7882e
commit 821e06f82a
2 changed files with 40 additions and 20 deletions

View file

@ -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:
@ -15,26 +17,42 @@ class InitReleaseService():
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)
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())
return version
def create_bump_version(self):
if self.version_repo == None:
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
version = self.get_version(ReleaseType.BUMP).create_bump_version()
self.version_repo.write_file(version.get_version_string())
return version
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():

View file

@ -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()
assert "123.123.457-SNAPSHOT" in version.get_version_string()