dda-devops-build/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py

108 lines
No EOL
2.9 KiB
Python

from pathlib import Path
import pytest as pt
from helper import Helper
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
# now we can import the module in the parent
# directory.
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)
def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch):
# init
th = Helper()
th.copy_files(th.TEST_FILE_PATH, tmp_path)
# change the context of the script execution to tmp_path
change_test_dir(tmp_path, monkeypatch)
git_api = GitApi()
git_api.init()
git_api.add_file(th.TEST_FILE_NAME)
git_api.commit("MINOR release")
# test
latest_commit = git_api.get_latest_commit()
assert "MINOR release" in latest_commit
# file handler tests
def test_gradle(tmp_path):
# init
th = Helper('config.gradle')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
repo = VersionRepository(th.TEST_FILE_PATH)
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 th.TEST_FILE_PATH.read_text()
def test_json(tmp_path):
# init
th = Helper('config.json')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
repo = VersionRepository(th.TEST_FILE_PATH)
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 th.TEST_FILE_PATH.read_text()
def test_clojure(tmp_path):
# init
th = Helper('config.clj')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
repo = VersionRepository(th.TEST_FILE_PATH)
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 th.TEST_FILE_PATH.read_text()
def test_python(tmp_path):
# init
th = Helper('config.py')
th.copy_files(th.TEST_FILE_PATH, tmp_path)
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
# test
repo = VersionRepository(th.TEST_FILE_PATH)
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 th.TEST_FILE_PATH.read_text()