Add test infrastructure and fixtures for University Agent unit tests#17
Open
devin-ai-integration[bot] wants to merge 5 commits into
Open
Add test infrastructure and fixtures for University Agent unit tests#17devin-ai-integration[bot] wants to merge 5 commits into
devin-ai-integration[bot] wants to merge 5 commits into
Conversation
- Created tests/unit/ directory for unit tests - Created tests/fixtures/ directory with mock data files - Added university_api_responses.json with realistic API response scenarios - Added university_search_responses.json with search test scenarios - Created conftest.py with shared pytest fixtures: - mock_app_config: Mock AppConfig for testing components - mock_app_config_with_api_key: Pre-configured with test API key - mock_requests_get: Mock requests.get() for HTTP testing - university_api_responses: Loads mock API response data - university_search_responses: Loads search scenario data - mock_google_ai_chat_completion: Mock GoogleAIChatCompletion - mock_requests_exception: Mock requests exception for error testing This infrastructure supports upcoming unit tests for: - UniversityPlugin class - GeminiChatCompletionFactory class
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Created comprehensive test suite for UniversityPlugin with 14 test cases - Test search_universities() method with various scenarios (successful, empty, limit) - Test get_universities_by_country() method with various scenarios - Test university data parsing and transformation from JSON to Pydantic models - Test UniversitySearchResult response format validation - All HTTP requests are properly mocked using pytest fixtures from Task 5.5 - Tests validate 10 result limit for search_universities and 20 for get_universities_by_country - Tests verify proper handling of nullable state_province field - All tests pass and lint checks pass
- Add TestUniversityPluginErrorHandling class with 8 tests: - Test network failures (RequestException) for both methods - Test generic exceptions for both methods - Test timeout scenarios for both methods - Test HTTP errors (404, 500) for both methods - Add TestUniversityPluginInputValidation class with 6 tests: - Test empty string inputs - Test special characters in inputs - Test very long query strings - Test unicode characters - Add TestUniversityPluginMalformedResponses class with 7 tests: - Test invalid JSON responses - Test missing required fields - Test unexpected data types - Test non-list API responses - Test null responses - Test partial data handling All tests use mocked HTTP requests and validate error handling behavior according to the plugin implementation. Total: 21 new tests.
…zation - Create tests/unit/test_gemini_completion_factory.py with 5 test cases - Test successful initialization with valid API key - Test API key storage and retrieval from AppConfig - Test behavior with missing/None API key - Test parent class initialization is called correctly - Test get_configs() returns empty list - All tests pass and ruff linting passes - Uses fixtures from conftest.py (mock_app_config, mock_app_config_with_api_key)
- Added 17 new tests covering model validation and factory methods - Tests cover all 4 supported Gemini models (1.5-flash, 1.5-pro, 1.0-pro, 2.0-flash-lite) - Verify get_chat_completion_for_model_name() with valid/invalid models - Test get_model_type_for_name() returns ModelType.GOOGLE - Test model_supports_structured_output() returns True for all models - Test create_chat_completion() with default and custom parameters - All GoogleAIChatCompletion API calls are mocked to prevent actual API requests - Total 22 tests (5 existing + 17 new), all passing with clean ruff lint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements comprehensive unit test coverage for the University Agent components as part of Tasks 5.1, 5.4, and 5.5. It adds test infrastructure with reusable fixtures and creates 59 new unit tests covering the UniversityPlugin and GeminiChatCompletionFactory classes.
Link to Devin run: https://app.devin.ai/sessions/1bb810da59f64d8e8a22acab3c5602fc
Requested by: Shawn Azman (@ShawnAzman)
Changes
Test Infrastructure (Task 5.5)
tests/conftest.pywith 7 pytest fixtures:mock_app_configandmock_app_config_with_api_keyfor configuration mockingmock_requests_getandmock_requests_exceptionfor HTTP request mockingmock_google_ai_chat_completionfor Google Gemini API mockinguniversity_api_responsesanduniversity_search_responsesfor loading test datatests/fixtures/university_api_responses.jsonwith mock API response data (279 lines)tests/fixtures/university_search_responses.jsonwith search scenario dataUniversityPlugin Tests (Task 5.1) - 37 tests
search_universitiesandget_universities_by_country) with various scenarios including successful responses, empty results, and result limitsUniversitySearchResultstructure and formatGeminiChatCompletionFactory Tests (Task 5.4) - 22 tests
get_configs()returns empty listModelType.GOOGLEreturned for all supported modelscreate_chat_completion()Type of Change
Important Review Points
"state-province"(hyphenated) which maps tostate_province(underscored) in the Pydantic model. Verify this matches the actual universities.hipolabs.com API format.search_universities()returns max 10 results andget_universities_by_country()returns max 20 results. Confirm these limits are implemented in the actual UniversityPlugin code (lines 59 and 105 in custom_plugins.py per task description).unittest.mock.patch()to prevent actual API requests during testing.Test Results
Additional Comments