Skip to content

Commit

Permalink
Unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Nov 6, 2024
1 parent 7cff689 commit be19941
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions tests/test_upstream_issue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import unittest.mock as mock
from unittest.mock import MagicMock
from copy import deepcopy

import sync2jira.upstream_issue as u

Expand Down Expand Up @@ -215,7 +216,7 @@ def test_github_issues_no_token(self,
@mock.patch('sync2jira.intermediary.Issue.from_github')
@mock.patch(PATH + 'Github')
@mock.patch(PATH + 'get_all_github_data')
def test_github_issues_no_token(self,
def test_filter_multiple_labels(self,
mock_get_all_github_data,
mock_github,
mock_issue_from_github):
Expand All @@ -225,26 +226,34 @@ def test_github_issues_no_token(self,
# Set up return values
self.mock_config['sync2jira']['filters']['github']['org/repo']['labels'].extend(['another_tag', 'and_another'])
mock_github.return_value = self.mock_github_client
mock_get_all_github_data.return_value = [self.mock_github_issue_raw]
mock_issue_from_github.return_value = 'Successful Call!'
# We mutate the issue object so we need to pass a copy here
mock_get_all_github_data.return_value = [deepcopy(self.mock_github_issue_raw)]

# Call the function
list(u.github_issues(
upstream='org/repo',
config=self.mock_config
))

# Assert that calls were made correctly
try:
mock_get_all_github_data.assert_called_with(
'https://api.github.com/repos/org/repo/issues?labels=custom_tag%2Canother_tag%2Cand_another&filter1=filter1',
{'Authorization': 'token mock_token'}
)
except AssertionError:
mock_get_all_github_data.assert_called_with(
'https://api.github.com/repos/org/repo/issues?filter1=filter1&labels=custom_tag%2Canother_tag%2Cand_another',
{'Authorization': 'token mock_token'}
)
# Assert that calls were made correctly
expected = 'labels=custom_tag%2Canother_tag%2Cand_another'
actual = mock_get_all_github_data.call_args[0][0]
self.assertIn(expected, actual)

# We mutate the issue object so we need to pass a copy here
mock_get_all_github_data.return_value = [deepcopy(self.mock_github_issue_raw)]

# Call the function again to ensure consistency for subsequent calls
list(u.github_issues(
upstream='org/repo',
config=self.mock_config
))

# Assert that calls were made correctly
expected = 'labels=custom_tag%2Canother_tag%2Cand_another'
actual = mock_get_all_github_data.call_args[0][0]
self.assertIn(expected, actual)

@mock.patch(PATH + 'Github')
@mock.patch('sync2jira.intermediary.Issue.from_github')
Expand Down

0 comments on commit be19941

Please sign in to comment.