From be199410b9dee6a6d50b0952a5d5119867ca64c9 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 6 Nov 2024 19:29:28 +0100 Subject: [PATCH] Unit test fixes --- tests/test_upstream_issue.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/test_upstream_issue.py b/tests/test_upstream_issue.py index 675b84d5..4d3181da 100644 --- a/tests/test_upstream_issue.py +++ b/tests/test_upstream_issue.py @@ -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 @@ -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): @@ -225,8 +226,9 @@ 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( @@ -234,17 +236,24 @@ def test_github_issues_no_token(self, 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')