2023-02-22 10:58:27 +01: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__))
|
2023-03-02 14:26:34 +01:00
|
|
|
|
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-03-02 14:26:34 +01:00
|
|
|
|
2023-02-22 10:58:27 +01:00
|
|
|
# adding the parent directory to
|
|
|
|
# the sys.path.
|
|
|
|
sys.path.append(parent)
|
2023-03-02 14:26:34 +01:00
|
|
|
|
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()
|
2023-03-02 14:26:34 +01:00
|
|
|
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 14:54:48 +01:00
|
|
|
# init
|
2023-03-03 15:07:02 +01:00
|
|
|
prepare_release_service.write_and_commit_bump()
|
2023-03-03 14:54:48 +01:00
|
|
|
|
|
|
|
# test
|
2023-03-03 15:54:11 +01:00
|
|
|
assert prepare_release_service.release_repo.get_release_count == 1
|
2023-03-03 14:54:48 +01:00
|
|
|
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
|
2023-03-03 13:36:39 +01:00
|
|
|
|
|
|
|
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')
|
2023-03-03 15:07:02 +01:00
|
|
|
tag_and_push_release_service = TagAndPushReleaseService(MockGitApi())
|
2023-03-03 13:36:39 +01:00
|
|
|
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
|
2023-03-03 15:07:02 +01:00
|
|
|
assert tag_and_push_release_service.git_api.push_count == 1
|