Fix service test and cleanup services
We now create a temporary git repository that creates a release commit. Remove whitespaces, unused imports.
This commit is contained in:
parent
9dc32ac92f
commit
0d36a8a66a
2 changed files with 31 additions and 21 deletions
13
services.py
13
services.py
|
@ -13,17 +13,16 @@ class PrepareReleaseService():
|
||||||
|
|
||||||
self.release_repo.version_repository.write_file(version.get_version_string())
|
self.release_repo.version_repository.write_file(version.get_version_string())
|
||||||
self.git_api.add_file(self.release_repo.version_repository.file)
|
self.git_api.add_file(self.release_repo.version_repository.file)
|
||||||
self.git_api.commit(commit_message)
|
self.git_api.commit(commit_message)
|
||||||
|
|
||||||
def write_and_commit_release(self):
|
def write_and_commit_release(self):
|
||||||
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release {self.release.release_version().get_version_string()}')
|
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release v{self.release.release_version().get_version_string()}')
|
||||||
|
|
||||||
def write_and_commit_bump(self):
|
def write_and_commit_bump(self):
|
||||||
self.__write_and_commit_version(self.release.bump_version(), commit_message=f'Version bump')
|
self.__write_and_commit_version(self.release.bump_version(), commit_message='Version bump')
|
||||||
|
|
||||||
|
|
||||||
class TagAndPushReleaseService():
|
class TagAndPushReleaseService():
|
||||||
|
|
||||||
def __init__(self, git_api: GitApi):
|
def __init__(self, git_api: GitApi):
|
||||||
self.git_api = git_api
|
self.git_api = git_api
|
||||||
|
|
||||||
|
@ -32,5 +31,3 @@ class TagAndPushReleaseService():
|
||||||
message = 'Release ' + annotation
|
message = 'Release ' + annotation
|
||||||
self.git_api.tag_annotated(annotation, message, 1)
|
self.git_api.tag_annotated(annotation, message, 1)
|
||||||
# self.git_api.push()
|
# self.git_api.push()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import pytest as pt
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
@ -5,38 +6,50 @@ import os
|
||||||
# getting the name of the directory
|
# getting the name of the directory
|
||||||
# where the this file is present.
|
# where the this file is present.
|
||||||
current = os.path.dirname(os.path.realpath(__file__))
|
current = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
# Getting the parent directory name
|
# Getting the parent directory name
|
||||||
# where the current directory is present.
|
# where the current directory is present.
|
||||||
parent = os.path.dirname(current)
|
parent = os.path.dirname(current)
|
||||||
|
|
||||||
# adding the parent directory to
|
# adding the parent directory to
|
||||||
# the sys.path.
|
# the sys.path.
|
||||||
sys.path.append(parent)
|
sys.path.append(parent)
|
||||||
|
|
||||||
# now we can import the module in the parent
|
# now we can import the module in the parent
|
||||||
# directory.
|
# directory.
|
||||||
|
|
||||||
from services import InitReleaseService
|
from services import PrepareReleaseService
|
||||||
from domain import ReleaseType
|
from domain import ReleaseType
|
||||||
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
||||||
from infrastructure_api import GitApi
|
from infrastructure_api import GitApi
|
||||||
|
|
||||||
def test_init_release_service(tmp_path):
|
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||||
|
monkeypatch.chdir(tmp_path)
|
||||||
|
|
||||||
|
def test_prepare_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||||
# init
|
# init
|
||||||
file_name = 'config.json'
|
file_name = 'config.json'
|
||||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
with open(f'test/resources/{file_name}', 'r') as json_file:
|
||||||
contents = gradle_file.read()
|
contents = json_file.read()
|
||||||
|
|
||||||
f = tmp_path / file_name
|
f = tmp_path / file_name
|
||||||
f.write_text(contents)
|
f.write_text(contents)
|
||||||
|
change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path
|
||||||
|
|
||||||
|
git_api = GitApi()
|
||||||
|
git_api.init()
|
||||||
|
git_api.add_file(file_name)
|
||||||
|
git_api.commit("MINOR release")
|
||||||
|
|
||||||
repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main')
|
repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main')
|
||||||
release_service = InitReleaseService(repo)
|
prepare_release_service = PrepareReleaseService(repo)
|
||||||
version = release_service.get_version().create_release_version(ReleaseType.MINOR)
|
prepare_release_service.main_branch = "main"
|
||||||
|
prepare_release_service.write_and_commit_release()
|
||||||
|
|
||||||
assert "123.124.0" in version.get_version_string()
|
latest_commit = git_api.get_latest_commit()
|
||||||
|
|
||||||
version = version.create_bump_version()
|
assert '"Release v123.124.0 "\n' in latest_commit
|
||||||
|
|
||||||
assert "123.124.1-SNAPSHOT" in version.get_version_string()
|
prepare_release_service.write_and_commit_bump()
|
||||||
|
latest_commit = git_api.get_latest_commit()
|
||||||
|
|
||||||
|
assert '"Version bump "\n' in latest_commit
|
||||||
|
|
Loading…
Reference in a new issue