The frontend passes '' instead of None

Also, tests for the new button display variables
This commit is contained in:
mike cullerton 2022-03-02 13:33:22 -05:00
parent cb65a7dc41
commit 83e2370778
2 changed files with 28 additions and 1 deletions

View File

@ -97,7 +97,7 @@ class GitService(object):
return repo_model
def push_to_remote(self, comment=None):
if comment is None:
if comment is None or comment.strip() == '':
comment = f"Git commit: {datetime.now()}"
repo = self._get_repo()
# get list of changed files

View File

@ -35,6 +35,9 @@ class TestGitService(BaseTest):
def test__get_repo(self, mock_repo):
# _get_repo returns a GitPython Repo object
app.config['GIT_DISPLAY_PUSH'] = True
app.config['GIT_DISPLAY_MERGE'] = False
self.setup_mock_repo(mock_repo)
repo = GitService()._get_repo()
@ -43,6 +46,8 @@ class TestGitService(BaseTest):
self.assertEqual(repo.untracked_files, ['a_file.txt', 'b_file.txt'])
self.assertEqual(repo.index.diff(None)[0].a_path, 'c_file.txt')
self.assertEqual(repo.index.diff(None)[1].a_path, 'd_file.txt')
self.assertTrue(repo.display_push)
self.assertFalse(repo.display_merge)
@patch('crc.services.git_service.Repo')
def test_push_to_remote(self, mock_repo):
@ -58,6 +63,28 @@ class TestGitService(BaseTest):
self.assertIn(call.index.commit('This is my comment'), method_calls)
self.assertIn(call.remotes.origin.push(), method_calls)
@patch('crc.services.git_service.Repo')
def test_push_no_comment(self, mock_repo):
# If no message is passed to push, we generate one.
self.setup_mock_repo(mock_repo)
mock_repo.remotes.origin.push.return_value = 'some_string'
repo = GitService().push_to_remote()
method_calls = repo.method_calls
self.assertIn('Git commit:', method_calls[5].args[0])
@patch('crc.services.git_service.Repo')
def test_push_empty_comment(self, mock_repo):
# If no message is passed to push, we generate one.
self.setup_mock_repo(mock_repo)
mock_repo.remotes.origin.push.return_value = 'some_string'
repo = GitService().push_to_remote(comment=' ')
method_calls = repo.method_calls
self.assertIn('Git commit:', method_calls[5].args[0])
def test_get_remote_url(self):
app.config['GIT_REMOTE_SERVER'] = 'test_server.com'
app.config['GIT_USER_NAME'] = 'test_username'