2023-03-02 13:26:34 +00:00
|
|
|
import pytest as pt
|
2023-02-22 09:58:27 +00:00
|
|
|
from pathlib import Path
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
# getting the name of the directory
|
|
|
|
# where the this file is present.
|
|
|
|
current = os.path.dirname(os.path.realpath(__file__))
|
2023-03-02 13:26:34 +00:00
|
|
|
|
2023-02-22 09:58:27 +00:00
|
|
|
# Getting the parent directory name
|
|
|
|
# where the current directory is present.
|
|
|
|
parent = os.path.dirname(current)
|
2023-03-02 13:26:34 +00:00
|
|
|
|
2023-02-22 09:58:27 +00:00
|
|
|
# adding the parent directory to
|
|
|
|
# the sys.path.
|
|
|
|
sys.path.append(parent)
|
2023-03-02 13:26:34 +00:00
|
|
|
|
2023-02-22 09:58:27 +00:00
|
|
|
# now we can import the module in the parent
|
|
|
|
# directory.
|
|
|
|
|
2023-03-02 15:56:09 +00:00
|
|
|
from services import PrepareReleaseService, TagAndPushReleaseService
|
2023-02-28 12:25:47 +00:00
|
|
|
from infrastructure import VersionRepository, ReleaseRepository, ReleaseTypeRepository
|
|
|
|
from infrastructure_api import GitApi
|
2023-02-22 09:58:27 +00:00
|
|
|
|
2023-03-02 13:26:34 +00:00
|
|
|
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|
|
|
monkeypatch.chdir(tmp_path)
|
|
|
|
|
2023-03-02 17:16:03 +00:00
|
|
|
def test_prepare_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch): # todo: maybe use mocks for service api tests
|
2023-02-22 09:58:27 +00:00
|
|
|
# init
|
|
|
|
file_name = 'config.json'
|
2023-03-02 13:26:34 +00:00
|
|
|
with open(f'test/resources/{file_name}', 'r') as json_file:
|
|
|
|
contents = json_file.read()
|
2023-02-22 09:58:27 +00:00
|
|
|
f = tmp_path / file_name
|
|
|
|
f.write_text(contents)
|
2023-03-02 13:26:34 +00:00
|
|
|
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")
|
2023-02-22 09:58:27 +00:00
|
|
|
|
2023-02-28 12:25:47 +00:00
|
|
|
repo = ReleaseRepository(VersionRepository(f), ReleaseTypeRepository(GitApi()), 'main')
|
2023-03-02 13:26:34 +00:00
|
|
|
prepare_release_service = PrepareReleaseService(repo)
|
|
|
|
prepare_release_service.main_branch = "main"
|
|
|
|
prepare_release_service.write_and_commit_release()
|
|
|
|
|
|
|
|
latest_commit = git_api.get_latest_commit()
|
2023-02-22 09:58:27 +00:00
|
|
|
|
2023-03-02 13:26:34 +00:00
|
|
|
assert '"Release v123.124.0 "\n' in latest_commit
|
2023-02-22 09:58:27 +00:00
|
|
|
|
2023-03-02 13:26:34 +00:00
|
|
|
prepare_release_service.write_and_commit_bump()
|
|
|
|
latest_commit = git_api.get_latest_commit()
|
2023-02-22 09:58:27 +00:00
|
|
|
|
2023-03-02 13:26:34 +00:00
|
|
|
assert '"Version bump "\n' in latest_commit
|
2023-03-02 15:56:09 +00:00
|
|
|
|
|
|
|
def test_tag_and_push_release_service(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|
|
|
# init
|
|
|
|
file_name = 'config.json'
|
|
|
|
with open(f'test/resources/{file_name}', 'r') as json_file:
|
|
|
|
contents = json_file.read()
|
|
|
|
f = tmp_path / file_name
|
|
|
|
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')
|
|
|
|
|
|
|
|
prepare_release_service = PrepareReleaseService(repo)
|
|
|
|
prepare_release_service.main_branch = "main"
|
|
|
|
prepare_release_service.write_and_commit_release()
|
|
|
|
|
|
|
|
tag_and_push_release_service = TagAndPushReleaseService(git_api)
|
|
|
|
tag_and_push_release_service.tag_release(repo.get_release())
|
|
|
|
|
|
|
|
assert 'v123.124.0\n' in git_api.get_latest_tag()
|