dda-devops-build/src/test/python/release_mixin/test_release_mixin.py

53 lines
1.5 KiB
Python
Raw Normal View History

2023-03-02 16:08:18 +01:00
import pytest as pt
2023-02-22 15:15:23 +01:00
from pathlib import Path
2023-03-09 14:26:30 +01:00
from pybuilder.core import Project
2023-02-22 15:15:23 +01:00
from src.main.python.ddadevops.release_mixin.release_mixin import ReleaseMixin, create_release_mixin_config
from src.main.python.ddadevops.release_mixin.infrastructure_api import GitApi
2023-02-22 15:15:23 +01:00
from .helper import Helper
2023-02-22 15:15:23 +01:00
MAIN_BRANCH = 'main'
2023-02-22 16:19:36 +01:00
STAGE = 'test'
PROJECT_ROOT_PATH = '.'
MODULE = 'test'
BUILD_DIR_NAME = "build_dir"
2023-02-22 15:15:23 +01:00
2023-03-09 14:26:30 +01:00
def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch):
monkeypatch.chdir(tmp_path)
2023-02-22 15:15:23 +01:00
class MyBuild(ReleaseMixin):
pass
def initialize(project, CONFIG_FILE):
project.build_depends_on('ddadevops>=3.1.2')
config = create_release_mixin_config(CONFIG_FILE, MAIN_BRANCH)
2023-02-23 14:40:10 +01:00
config.update({'stage': STAGE,
'module': MODULE,
'project_root_path': PROJECT_ROOT_PATH,
'build_dir_name': BUILD_DIR_NAME})
2023-02-22 15:15:23 +01:00
build = MyBuild(project, config)
return build
2023-03-09 14:26:30 +01:00
def test_release_mixin(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.add_file(th.TEST_FILE_NAME)
git_api.commit("MAJOR release")
build = initialize(project, th.TEST_FILE_PATH)
build.prepare_release()
release_version = build.version_repo.get_version()
# test
assert "124.0.1-SNAPSHOT" in release_version.get_version_string()