diff --git a/src/main/python/ddadevops/domain/__init__.py b/src/main/python/ddadevops/domain/__init__.py index 4bd528a..8121e0d 100644 --- a/src/main/python/ddadevops/domain/__init__.py +++ b/src/main/python/ddadevops/domain/__init__.py @@ -1,4 +1,4 @@ -from .common import Validateable, DnsRecord, Devops, BuildType +from .common import Validateable, DnsRecord, Devops, BuildType, MixinType from .devops_factory import DevopsFactory from .image import Image from .c4k import C4k diff --git a/src/test/python/release_mixin/test_release_mixin.py b/src/test/python/release_mixin/test_release_mixin.py deleted file mode 100644 index 62a890d..0000000 --- a/src/test/python/release_mixin/test_release_mixin.py +++ /dev/null @@ -1,80 +0,0 @@ -import pytest as pt -from pathlib import Path -from pybuilder.core import Project - -from src.main.python.ddadevops.release_mixin import ReleaseMixin -from src.main.python.ddadevops.infrastructure.release_mixin import GitApi, EnvironmentApi -from src.main.python.ddadevops.domain import Devops, ReleaseContext, Release - -from .helper import Helper - -MAIN_BRANCH = 'main' -STAGE = 'test' -PROJECT_ROOT_PATH = '.' -MODULE = 'test' -BUILD_DIR_NAME = "build_dir" - -def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch): - monkeypatch.chdir(tmp_path) - -class MyBuild(ReleaseMixin): - pass - -def initialize_with_object(project, CONFIG_FILE): - project.build_depends_on('ddadevops>=3.1.2') - devops = Devops(STAGE, PROJECT_ROOT_PATH, MODULE, "release_test", BUILD_DIR_NAME) - release = Release(devops, MAIN_BRANCH, CONFIG_FILE) - build = MyBuild(project, release) - return build - -def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch): - - # init - th = Helper() - th.copy_files(th.TEST_FILE_PATH, tmp_path) - th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME - - change_test_dir(tmp_path, monkeypatch) - project = Project(tmp_path) - - git_api = GitApi() - git_api.init() - git_api.set_user_config("ex.ample@mail.com", "Ex Ample") - git_api.add_file(th.TEST_FILE_NAME) - git_api.commit("MAJOR release") - - build = initialize_with_object(project, th.TEST_FILE_PATH) - build.prepare_release() - release_version = build.release_repo.version_repository.get_version() - - # test - assert "124.0.1-SNAPSHOT" in release_version.get_version_string() - -def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch): - - # init - th = Helper() - th.copy_files(th.TEST_FILE_PATH, tmp_path) - th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME - - change_test_dir(tmp_path, monkeypatch) - project = Project(tmp_path) - - git_api = GitApi() - git_api.init() - git_api.set_user_config("ex.ample@mail.com", "Ex Ample") - git_api.add_file(th.TEST_FILE_NAME) - git_api.commit("Commit Message") - - environment_api = EnvironmentApi() - environment_api.set("DDADEVOPS_RELEASE_TYPE", "MAJOR") - - build = initialize_with_object(project, th.TEST_FILE_PATH) - build.prepare_release() - release_version = build.release_repo.version_repository.get_version() - - # test - assert "124.0.1-SNAPSHOT" in release_version.get_version_string() - - # tear down - environment_api.set("DDADEVOPS_RELEASE_TYPE", "") diff --git a/src/test/python/resource_helper.py b/src/test/python/resource_helper.py new file mode 100644 index 0000000..7de20b5 --- /dev/null +++ b/src/test/python/resource_helper.py @@ -0,0 +1,12 @@ +from pathlib import Path +from src.main.python.ddadevops.infrastructure import ExecutionApi + +class ResourceHelper(): + def __init__(self, file_name = 'config.json'): + self.TEST_FILE_NAME = file_name + self.TEST_FILE_ROOT = Path('src/test/resources/') + self.TEST_FILE_PATH = self.TEST_FILE_ROOT / self.TEST_FILE_NAME + + def copy_files(self, source: Path, target: Path): + api = ExecutionApi() + api.execute(f"cp {source} {target}") diff --git a/src/test/python/test_devops_build.py b/src/test/python/test_devops_build.py index 006d46b..c107058 100644 --- a/src/test/python/test_devops_build.py +++ b/src/test/python/test_devops_build.py @@ -1,21 +1,20 @@ import os from pybuilder.core import Project -from src.main.python.ddadevops.domain.common import Devops from src.main.python.ddadevops.devops_build import DevopsBuild from .domain.test_helper import devops_config -class MyDevopsBuild(DevopsBuild): - pass - - def test_devops_build(tmp_path): - build_dir = "build" - project_name = "testing-project" - module_name = "c4k-test" tmp_path_str = str(tmp_path) - project = Project(tmp_path_str, name=project_name) - devops_build = DevopsBuild(project, devops_config({})) + project = Project(tmp_path_str, name="name") + devops_build = DevopsBuild( + project, + devops_config( + { + "project_root_path": tmp_path_str, + } + ), + ) devops_build.initialize_build_dir() assert os.path.exists(f"{devops_build.build_path()}") diff --git a/src/test/python/test_release_mixin.py b/src/test/python/test_release_mixin.py new file mode 100644 index 0000000..b0772a3 --- /dev/null +++ b/src/test/python/test_release_mixin.py @@ -0,0 +1,103 @@ +import pytest as pt +from pathlib import Path +from pybuilder.core import Project + +from src.main.python.ddadevops.release_mixin import ReleaseMixin +from src.main.python.ddadevops.infrastructure.release_mixin import ( + GitApi, + EnvironmentApi, +) +from src.main.python.ddadevops.domain import Devops, ReleaseContext, Release + +from .resource_helper import ResourceHelper +from .domain.test_helper import devops_config + +MAIN_BRANCH = "main" +STAGE = "test" +PROJECT_ROOT_PATH = "." +MODULE = "test" +BUILD_DIR_NAME = "build_dir" + +# def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch): +# monkeypatch.chdir(tmp_path) + +# class MyBuild(ReleaseMixin): +# pass + + +def test_release_mixin(tmp_path): + tmp_path_str = str(tmp_path) + + project = Project(tmp_path_str, name="name") + sut = ReleaseMixin( + project, + devops_config( + { + "project_root_path": tmp_path_str, + "build_types": [], + "mixin_types": ["RELEASE"], + } + ), + ) + sut.initialize_build_dir() + assert os.path.exists(f"{devops_build.build_path()}") + + +# def initialize_with_object(project, CONFIG_FILE): +# project.build_depends_on('ddadevops>=3.1.2') +# devops = Devops(STAGE, PROJECT_ROOT_PATH, MODULE, "release_test", BUILD_DIR_NAME) +# release = Release(devops, MAIN_BRANCH, CONFIG_FILE) +# build = MyBuild(project, release) +# return build + +# def test_release_mixin_git(tmp_path: Path, monkeypatch: pt.MonkeyPatch): + +# # init +# th = Helper() +# th.copy_files(th.TEST_FILE_PATH, tmp_path) +# th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME + +# change_test_dir(tmp_path, monkeypatch) +# project = Project(tmp_path) + +# git_api = GitApi() +# git_api.init() +# git_api.set_user_config("ex.ample@mail.com", "Ex Ample") +# git_api.add_file(th.TEST_FILE_NAME) +# git_api.commit("MAJOR release") + +# build = initialize_with_object(project, th.TEST_FILE_PATH) +# build.prepare_release() +# release_version = build.release_repo.version_repository.get_version() + +# # test +# assert "124.0.1-SNAPSHOT" in release_version.get_version_string() + +# def test_release_mixin_environment(tmp_path: Path, monkeypatch: pt.MonkeyPatch): + +# # init +# th = Helper() +# th.copy_files(th.TEST_FILE_PATH, tmp_path) +# th.TEST_FILE_PATH = tmp_path / th.TEST_FILE_NAME + +# change_test_dir(tmp_path, monkeypatch) +# project = Project(tmp_path) + +# git_api = GitApi() +# git_api.init() +# git_api.set_user_config("ex.ample@mail.com", "Ex Ample") +# git_api.add_file(th.TEST_FILE_NAME) +# git_api.commit("Commit Message") + +# environment_api = EnvironmentApi() +# environment_api.set("DDADEVOPS_RELEASE_TYPE", "MAJOR") + +# build = initialize_with_object(project, th.TEST_FILE_PATH) +# build.prepare_release() +# release_version = build.release_repo.version_repository.get_version() + +# # test +# assert "124.0.1-SNAPSHOT" in release_version.get_version_string() + +# # tear down +# environment_api.set("DDADEVOPS_RELEASE_TYPE", "")