mv test to appr. place

This commit is contained in:
Michael Jerger 2023-04-30 11:29:17 +02:00
parent d670605d37
commit 039a5da8f6
5 changed files with 125 additions and 91 deletions

View file

@ -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 .devops_factory import DevopsFactory
from .image import Image from .image import Image
from .c4k import C4k from .c4k import C4k

View file

@ -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", "")

View file

@ -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}")

View file

@ -1,21 +1,20 @@
import os import os
from pybuilder.core import Project from pybuilder.core import Project
from src.main.python.ddadevops.domain.common import Devops
from src.main.python.ddadevops.devops_build import DevopsBuild from src.main.python.ddadevops.devops_build import DevopsBuild
from .domain.test_helper import devops_config from .domain.test_helper import devops_config
class MyDevopsBuild(DevopsBuild):
pass
def test_devops_build(tmp_path): def test_devops_build(tmp_path):
build_dir = "build"
project_name = "testing-project"
module_name = "c4k-test"
tmp_path_str = str(tmp_path) tmp_path_str = str(tmp_path)
project = Project(tmp_path_str, name=project_name) project = Project(tmp_path_str, name="name")
devops_build = DevopsBuild(project, devops_config({})) devops_build = DevopsBuild(
project,
devops_config(
{
"project_root_path": tmp_path_str,
}
),
)
devops_build.initialize_build_dir() devops_build.initialize_build_dir()
assert os.path.exists(f"{devops_build.build_path()}") assert os.path.exists(f"{devops_build.build_path()}")

View file

@ -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", "")