Use EnvironmentKeys, refactor in test accordingly

This commit is contained in:
erik 2023-04-11 16:16:08 +02:00
parent f51afe8bbc
commit 3776116383
2 changed files with 9 additions and 9 deletions

View file

@ -1,4 +1,4 @@
from .domain import Release, Version, ReleaseType from .domain import Release, Version, ReleaseType, EnvironmentKeys
from .infrastructure_api import FileHandler, GitApi, EnvironmentApi from .infrastructure_api import FileHandler, GitApi, EnvironmentApi
class VersionRepository(): class VersionRepository():
@ -33,7 +33,7 @@ class VersionRepository():
class ReleaseTypeRepository(): class ReleaseTypeRepository():
def __init__(self, git_api: GitApi, environment_api: EnvironmentApi): def __init__(self, git_api: GitApi, environment_api: EnvironmentApi):
self.git_api = git_api self.git_api = git_api
self.environment_api = environment_api self.environment_api = environment_api
@classmethod @classmethod
def from_git(cls, git_api: GitApi): def from_git(cls, git_api: GitApi):
@ -60,7 +60,7 @@ class ReleaseTypeRepository():
return None return None
def __get_release_type_environment(self) -> ReleaseType | None: def __get_release_type_environment(self) -> ReleaseType | None:
release_name = self.environment_api.get('RELEASE_TYPE') release_name = self.environment_api.get(EnvironmentKeys.DDADEVOPS_RELEASE_TYPE.name)
if release_name is None: if release_name is None:
return None return None

View file

@ -54,27 +54,27 @@ def test_release_type_repository_git():
assert release_type == None assert release_type == None
def test_release_type_repository_env(): def test_release_type_repository_env():
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'MINOR test'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'MINOR test'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type is ReleaseType.MINOR assert release_type is ReleaseType.MINOR
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'MINOR'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'MINOR'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type is ReleaseType.MINOR assert release_type is ReleaseType.MINOR
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'Major bla'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'Major bla'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type == ReleaseType.MAJOR assert release_type == ReleaseType.MAJOR
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'Patch bla'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'Patch bla'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type == ReleaseType.PATCH assert release_type == ReleaseType.PATCH
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'Snapshot bla'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'Snapshot bla'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type == ReleaseType.SNAPSHOT assert release_type == ReleaseType.SNAPSHOT
sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'RELEASE_TYPE': 'Random text'})) sut = ReleaseTypeRepository.from_environment(MockEnvironmentApi({'DDADEVOPS_RELEASE_TYPE': 'Random text'}))
release_type = sut.get_release_type() release_type = sut.get_release_type()
assert release_type == None assert release_type == None