Skip to content

Commit

Permalink
test(resolver): Improve issue handler test for text attachments
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
oconnorjoseph committed Jan 25, 2025
1 parent eab97af commit 30d501a
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions tests/unit/resolver/test_issue_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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()
Expand All @@ -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')
Expand All @@ -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],
Expand Down

0 comments on commit 30d501a

Please sign in to comment.