dda-devops-build/src/main/python/ddadevops/release-mixin/test/test_infrastructure_api.py

43 lines
1.1 KiB
Python
Raw Normal View History

2023-02-24 10:39:38 +00:00
from pathlib import Path
import pytest as pt
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.
from infrastructure_api import GitApi
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
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)
change_test_dir(tmp_path, monkeypatch) # change the context of the script execution to tmp_path
git_api = GitApi()
git_api.init()
git_api.add_file(file_name)
git_api.commit("MINOR release")
# test
latest_commit = git_api.get_latest_commit()
assert "MINOR release" in latest_commit