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

52 lines
2 KiB
Python
Raw Normal View History

import pytest as pt
2023-02-22 10:58:27 +01:00
from pathlib import Path
import sys
import os
# getting the name of the directory
# where the this file is present.
current = os.path.dirname(os.path.realpath(__file__))
2023-02-22 10:58:27 +01:00
# Getting the parent directory name
# where the current directory is present.
parent = os.path.dirname(current)
2023-02-22 10:58:27 +01:00
# adding the parent directory to
# the sys.path.
sys.path.append(parent)
2023-02-22 10:58:27 +01:00
# now we can import the module in the parent
# directory.
2023-03-02 16:56:09 +01:00
from services import PrepareReleaseService, TagAndPushReleaseService
2023-03-03 13:36:39 +01:00
from mock_infrastructure import MockReleaseRepository, MockReleaseTypeRepository, MockVersionRepository
from mock_infrastructure_api import MockGitApi
2023-02-22 10:58:27 +01:00
2023-03-03 13:36:39 +01:00
def test_prepare_release_service(): # todo: maybe use mocks for service api tests
2023-02-22 10:58:27 +01:00
# init
2023-03-03 13:36:39 +01:00
mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main')
prepare_release_service = PrepareReleaseService(mock_release_repo)
prepare_release_service.git_api = MockGitApi()
prepare_release_service.write_and_commit_release()
2023-03-03 13:36:39 +01:00
#test
assert prepare_release_service.release_repo.get_release_count == 1
assert prepare_release_service.release.validate_count == 1
assert prepare_release_service.release_repo.version_repository.write_file_count == 1
assert prepare_release_service.git_api.add_file_count == 1
assert prepare_release_service.git_api.commit_count == 1
2023-03-02 16:56:09 +01:00
2023-03-03 13:36:39 +01:00
prepare_release_service.write_and_commit_release() #todo: add asserts
def test_tag_and_push_release_service():
2023-03-02 16:56:09 +01:00
# init
2023-03-03 13:36:39 +01:00
mock_release_repo = MockReleaseRepository(MockVersionRepository(), MockReleaseTypeRepository(MockGitApi()), 'main')
tag_and_push_release_service = TagAndPushReleaseService(MockGitApi())
tag_and_push_release_service.tag_release(mock_release_repo.get_release())
tag_and_push_release_service.push_release()
#test
assert tag_and_push_release_service.git_api.tag_annotated_count == 1
assert tag_and_push_release_service.git_api.push_count == 1