Skip to content

Commit

Permalink
generate_metadata.Git - add ability to commit any changes
Browse files Browse the repository at this point in the history
* add shared.GitMixin specific tests
  • Loading branch information
itewk committed Nov 11, 2021
1 parent 8943f81 commit e265481
Show file tree
Hide file tree
Showing 3 changed files with 646 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/ploigos_step_runner/step_implementers/shared/git_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def git_repo(self):
self.__git_repo = Repo(repo_root)
except InvalidGitRepositoryError as error:
raise StepRunnerException(
f'Given git-repo-root ({repo_root}) is not a Git repository'
f'Given git-repo-root ({repo_root}) is not a Git repository: {error}'
) from error

return self.__git_repo
Expand All @@ -128,20 +128,19 @@ def git_url(self): # pylint: disable=too-many-branches
if not self.__git_url:
# get git url from config or current repo remote
git_url = self.get_value(['git-url', 'url'])

if not git_url:
git_url = self.git_repo.remote.url

# get given git username and pass
git_username = self.get_value('git-username')
git_password = self.get_value('git-password')
git_url = self.git_repo.remote().url

# if git url is ssh, throw error if git username or password given
# if git url is http|https combine git username and password with git url
split_git_url = urlsplit(git_url)
if split_git_url.scheme in ['ssh']:
self.__git_url = git_url
elif split_git_url.scheme in ['http', 'https']:
# get given git username and pass
git_username = self.get_value('git-username')
git_password = self.get_value('git-password')

# determine git username
if split_git_url.username and git_username:
print(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from unittest.mock import PropertyMock, patch

from git import InvalidGitRepositoryError
from ploigos_step_runner import StepResult
from ploigos_step_runner import StepResult, StepRunnerException
from ploigos_step_runner.step_implementers.generate_metadata import Git
from testfixtures import TempDirectory
from tests.helpers.base_step_implementer_test_case import \
Expand Down Expand Up @@ -533,8 +532,8 @@ def test_success_pre_release_branch_custom_release_branch_regexes_empty(self, mo

self.assertEqual(actual_step_result, expected_step_result)

@patch('git.Repo')
def test_fail_not_a_git_repo(self, mock_repo):
@patch.object(Git, 'git_repo', new_callable=PropertyMock)
def test_fail_getting_git_repo(self, mock_git_repo):
with TempDirectory() as temp_dir:
# setup
step_config = {
Expand All @@ -547,7 +546,7 @@ def test_fail_not_a_git_repo(self, mock_repo):
)

# setup mocks
mock_repo.side_effect = InvalidGitRepositoryError()
mock_git_repo.side_effect = StepRunnerException('mock error')

# run test
actual_step_result = step_implementer._run_step()
Expand All @@ -559,8 +558,7 @@ def test_fail_not_a_git_repo(self, mock_repo):
sub_step_implementer_name='Git'
)
expected_step_result.success = False
expected_step_result.message = f'Given git-repo-root ({temp_dir.path})' \
' is not a Git repository'
expected_step_result.message = f'mock error'

self.assertEqual(actual_step_result, expected_step_result)

Expand Down
Loading

0 comments on commit e265481

Please sign in to comment.