From 21bafab88269007e5135b861fd610d28438d21b5 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 9 Mar 2023 13:44:50 +0100 Subject: [PATCH] Adapt tests for helper class --- .../release-mixin/test/test_infrastructure.py | 4 +- .../test/test_infrastructure_api.py | 62 +++++++------------ 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/src/main/python/ddadevops/release-mixin/test/test_infrastructure.py b/src/main/python/ddadevops/release-mixin/test/test_infrastructure.py index 72b8222..7e5f701 100644 --- a/src/main/python/ddadevops/release-mixin/test/test_infrastructure.py +++ b/src/main/python/ddadevops/release-mixin/test/test_infrastructure.py @@ -1,6 +1,6 @@ import sys import os -import test_helper as th +from helper import Helper # getting the name of the directory # where the this file is present. @@ -24,6 +24,7 @@ from mock_infrastructure_api import MockGitApi def test_version_repository(tmp_path): # init + th = Helper() th.copy_files(th.TEST_FILE_PATH, tmp_path) sut = VersionRepository(th.TEST_FILE_PATH) version = sut.get_version() @@ -34,6 +35,7 @@ def test_version_repository(tmp_path): def test_release_repository(tmp_path): # init + th = Helper() th.copy_files( th.TEST_FILE_PATH, tmp_path) version_repo = VersionRepository(th.TEST_FILE_PATH) release_type_repo = ReleaseTypeRepository(MockGitApi('MINOR test')) diff --git a/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py b/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py index fcaad52..e857721 100644 --- a/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py +++ b/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py @@ -1,5 +1,6 @@ from pathlib import Path import pytest as pt +from helper import Helper import sys import os @@ -27,18 +28,15 @@ def change_test_dir( tmp_path: Path, monkeypatch: pt.MonkeyPatch): def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch): # init - file_name = 'config.json' - with open(f'test/resources/{file_name}', 'r') as json_file: - contents = json_file.read() - f = tmp_path / file_name - f.write_text(contents) + 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(file_name) + git_api.add_file(th.TEST_FILE_NAME) git_api.commit("MINOR release") # test @@ -48,75 +46,63 @@ def test_git_api(tmp_path: Path, monkeypatch: pt.MonkeyPatch): # file handler tests def test_gradle(tmp_path): # init - file_name = 'config.gradle' - with open(f'test/resources/{file_name}', 'r') as gradle_file: - contents = gradle_file.read() - - f = tmp_path / file_name - f.write_text(contents) + 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(f) + 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 f.read_text() + assert 'version = "12.4.678-SNAPSHOT"' in th.TEST_FILE_PATH.read_text() def test_json(tmp_path): # init - file_name = 'config.json' - with open(f'test/resources/{file_name}', 'r') as gradle_file: - contents = gradle_file.read() - - f = tmp_path / file_name - f.write_text(contents) + 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(f) + 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 f.read_text() + assert '"version": "123.123.456-SNAPSHOT"' in th.TEST_FILE_PATH.read_text() def test_clojure(tmp_path): # init - file_name = 'config.clj' - with open(f'test/resources/{file_name}', 'r') as gradle_file: - contents = gradle_file.read() - - f = tmp_path / file_name - f.write_text(contents) + 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(f) + 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 f.read_text() + assert '1.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text() def test_python(tmp_path): # init - file_name = 'config.py' - with open(f'test/resources/{file_name}', 'r') as gradle_file: - contents = gradle_file.read() - - f = tmp_path / file_name - f.write_text(contents) + 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(f) + 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 f.read_text() \ No newline at end of file + assert '3.1.3-SNAPSHOT' in th.TEST_FILE_PATH.read_text() \ No newline at end of file