Fix some of the tests
This commit is contained in:
parent
975de636ed
commit
ef51db1403
7 changed files with 26 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue