From 30d501a92b6ff068dadc9976359c40f6ea30d1a2 Mon Sep 17 00:00:00 2001 From: Joseph O'Connor Date: Fri, 24 Jan 2025 19:14:33 -0500 Subject: [PATCH] test(resolver): Improve issue handler test for text attachments - Enhance test coverage for GitHub issue attachment handling - Add more robust mocking for pagination and different response scenarios - Refactor test to handle multiple page responses and attachment downloads --- tests/unit/resolver/test_issue_handler.py | 34 ++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tests/unit/resolver/test_issue_handler.py b/tests/unit/resolver/test_issue_handler.py index d4ca8e9b9c07..212f3417dd96 100644 --- a/tests/unit/resolver/test_issue_handler.py +++ b/tests/unit/resolver/test_issue_handler.py @@ -628,6 +628,7 @@ def test_pr_handler_get_converted_issues_with_duplicate_issue_refs(): def test_issue_handler_with_text_attachments(): with patch('requests.get') as mock_get: + # Mock the response for issues mock_issues_response = MagicMock() mock_issues_response.json.return_value = [ { @@ -636,8 +637,9 @@ def test_issue_handler_with_text_attachments(): 'body': 'Test Body with attachment [error.log](https://example.com/error.log) and [config.yaml](https://example.com/config.yaml)', } ] + mock_issues_response.raise_for_status = MagicMock() - # Mock the response for downloading attachments + # Mock the responses for downloading attachments mock_error_log = MagicMock() mock_error_log.text = 'Error: Something went wrong\nStack trace: ...' mock_error_log.raise_for_status = MagicMock() @@ -646,12 +648,27 @@ def test_issue_handler_with_text_attachments(): mock_config_yaml.text = 'key: value\nsetting: enabled' mock_config_yaml.raise_for_status = MagicMock() - # Set up the mock to return different responses - mock_get.side_effect = [ - mock_issues_response, # First call for issues - mock_error_log, # Second call for error.log - mock_config_yaml, # Third call for config.yaml - ] + # Mock the response for comments + mock_comments_response = MagicMock() + mock_comments_response.json.return_value = [] + mock_comments_response.raise_for_status = MagicMock() + + # Set up the mock to return different responses for different URLs and params + def get_side_effect(url, *args, **kwargs): + if url == f'https://api.github.com/repos/test-owner/test-repo/issues': + # For the first page, return issues + if kwargs.get('params', {}).get('page') == 1: + return mock_issues_response + # For subsequent pages, return empty list to end pagination + return mock_comments_response + elif url == 'https://example.com/error.log': + return mock_error_log + elif url == 'https://example.com/config.yaml': + return mock_config_yaml + else: + return mock_comments_response + + mock_get.side_effect = get_side_effect # Create an instance of IssueHandler llm_config = LLMConfig(model='test', api_key='test') @@ -660,9 +677,6 @@ def test_issue_handler_with_text_attachments(): # Get converted issues issues = handler.get_converted_issues(issue_numbers=[1]) - # Verify that we got exactly one issue - assert len(issues) == 1 - # Get instruction to verify attachment handling instruction, _ = handler.get_instruction( issues[0],