Move api tests to api test file
Some formatting and missing imports
This commit is contained in:
parent
2c2f528371
commit
27f2bf2d2e
2 changed files with 88 additions and 5 deletions
|
@ -13,9 +13,11 @@ class MockSystemAPI():
|
|||
|
||||
class MockGitApi():
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, commit_string = ""):
|
||||
self.system_api = MockSystemAPI()
|
||||
self.tag_annotated_count = 0
|
||||
self.get_latest_commit_count = 0
|
||||
self.commit_string = commit_string
|
||||
self.tag_annotated_count = 0
|
||||
self.add_file_count = 0
|
||||
self.commit_count = 0
|
||||
self.push_count = 0
|
||||
|
@ -24,7 +26,8 @@ class MockGitApi():
|
|||
return " "
|
||||
|
||||
def get_latest_commit(self):
|
||||
return " "
|
||||
self.get_latest_commit_count += 1
|
||||
return self.commit_string
|
||||
|
||||
def tag_annotated(self, annotation: str, message: str, count: int):
|
||||
self.tag_annotated_count += 1
|
||||
|
|
|
@ -18,7 +18,9 @@ sys.path.append(parent)
|
|||
# now we can import the module in the parent
|
||||
# directory.
|
||||
|
||||
from infrastructure_api import GitApi
|
||||
from infrastructure_api import GitApi
|
||||
from infrastructure import VersionRepository
|
||||
from domain import ReleaseType
|
||||
|
||||
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
||||
monkeypatch.chdir(tmp_path)
|
||||
|
@ -30,7 +32,9 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
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
|
||||
|
||||
# change the context of the script execution to tmp_path
|
||||
change_test_dir(tmp_path, monkeypatch)
|
||||
|
||||
git_api = GitApi()
|
||||
git_api.init()
|
||||
|
@ -40,3 +44,79 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
|
|||
# test
|
||||
latest_commit = git_api.get_latest_commit()
|
||||
assert "MINOR release" in latest_commit
|
||||
|
||||
# file handler tests
|
||||
def test_gradle(tmp_path):
|
||||
# init
|
||||
file_name = 'config.gradle'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
|
||||
|
||||
|
||||
def test_json(tmp_path):
|
||||
# init
|
||||
file_name = 'config.json'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
||||
|
||||
|
||||
def test_clojure(tmp_path):
|
||||
# init
|
||||
file_name = 'config.clj'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '1.1.3-SNAPSHOT' in f.read_text()
|
||||
|
||||
|
||||
def test_python(tmp_path):
|
||||
# init
|
||||
file_name = 'config.py'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
assert '3.1.3-SNAPSHOT' in f.read_text()
|
Loading…
Reference in a new issue