2023-02-24 10:39:38 +00:00
|
|
|
from pathlib import Path
|
2023-03-03 12:35:24 +00:00
|
|
|
import pytest as pt
|
2023-03-09 12:44:50 +00:00
|
|
|
from helper import Helper
|
2023-02-24 10:39:38 +00:00
|
|
|
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.
|
|
|
|
|
2023-03-09 12:15:35 +00:00
|
|
|
from infrastructure_api import GitApi
|
|
|
|
from infrastructure import VersionRepository
|
|
|
|
from domain import ReleaseType
|
2023-03-03 12:35:24 +00:00
|
|
|
|
|
|
|
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
|
2023-03-09 12:44:50 +00:00
|
|
|
th = Helper()
|
|
|
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# change the context of the script execution to tmp_path
|
|
|
|
change_test_dir(tmp_path, monkeypatch)
|
2023-03-03 12:35:24 +00:00
|
|
|
|
|
|
|
git_api = GitApi()
|
|
|
|
git_api.init()
|
2023-03-09 12:44:50 +00:00
|
|
|
git_api.add_file(th.TEST_FILE_NAME)
|
2023-03-03 12:35:24 +00:00
|
|
|
git_api.commit("MINOR release")
|
|
|
|
|
2023-03-03 14:07:02 +00:00
|
|
|
# test
|
2023-03-03 12:35:24 +00:00
|
|
|
latest_commit = git_api.get_latest_commit()
|
|
|
|
assert "MINOR release" in latest_commit
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# file handler tests
|
|
|
|
def test_gradle(tmp_path):
|
|
|
|
# init
|
2023-03-09 12:44:50 +00:00
|
|
|
th = Helper('config.gradle')
|
|
|
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
|
|
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# test
|
2023-03-09 12:44:50 +00:00
|
|
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
2023-03-09 12:15:35 +00:00
|
|
|
version = repo.get_version()
|
|
|
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
|
|
|
repo.write_file(version.get_version_string())
|
|
|
|
|
|
|
|
# check
|
2023-03-09 12:44:50 +00:00
|
|
|
assert 'version = "12.4.678-SNAPSHOT"' in th.TEST_FILE_PATH.read_text()
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_json(tmp_path):
|
|
|
|
# init
|
2023-03-09 12:44:50 +00:00
|
|
|
th = Helper('config.json')
|
|
|
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
|
|
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# test
|
2023-03-09 12:44:50 +00:00
|
|
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
2023-03-09 12:15:35 +00:00
|
|
|
version = repo.get_version()
|
|
|
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
|
|
|
repo.write_file(version.get_version_string())
|
|
|
|
|
|
|
|
# check
|
2023-03-09 12:44:50 +00:00
|
|
|
assert '"version": "123.123.456-SNAPSHOT"' in th.TEST_FILE_PATH.read_text()
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_clojure(tmp_path):
|
|
|
|
# init
|
2023-03-09 12:44:50 +00:00
|
|
|
th = Helper('config.clj')
|
|
|
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
|
|
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# test
|
2023-03-09 12:44:50 +00:00
|
|
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
2023-03-09 12:15:35 +00:00
|
|
|
version = repo.get_version()
|
|
|
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
|
|
|
repo.write_file(version.get_version_string())
|
|
|
|
|
|
|
|
# check
|
2023-03-09 12:44:50 +00:00
|
|
|
assert '1.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text()
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_python(tmp_path):
|
|
|
|
# init
|
2023-03-09 12:44:50 +00:00
|
|
|
th = Helper('config.py')
|
|
|
|
th.copy_files(th.TEST_FILE_PATH, tmp_path)
|
|
|
|
th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME
|
2023-03-09 12:15:35 +00:00
|
|
|
|
|
|
|
# test
|
2023-03-09 12:44:50 +00:00
|
|
|
repo = VersionRepository(th.TEST_FILE_PATH)
|
2023-03-09 12:15:35 +00:00
|
|
|
version = repo.get_version()
|
|
|
|
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
|
|
|
repo.write_file(version.get_version_string())
|
|
|
|
|
|
|
|
# check
|
2023-03-09 12:44:50 +00:00
|
|
|
assert '3.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text()
|