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

38 lines
1.9 KiB
Python

from src.main.python.ddadevops.release_mixin.services import PrepareReleaseService, TagAndPushReleaseService
from mock_infrastructure import MockReleaseRepository, MockReleaseTypeRepository, MockVersionRepository
from mock_infrastructure_api import MockGitApi
def test_prepare_release_service(): # todo: maybe use mocks for service api tests
# init
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()
#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
# init
prepare_release_service.write_and_commit_bump()
# test
assert prepare_release_service.release_repo.get_release_count == 1
assert prepare_release_service.release.validate_count == 2
assert prepare_release_service.release_repo.version_repository.write_file_count == 2
assert prepare_release_service.git_api.add_file_count == 2
assert prepare_release_service.git_api.commit_count == 2
def test_tag_and_push_release_service():
# init
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