Spaces:
Sleeping
Sleeping
Monideep Chakraborti
Deploy GQuery AI - Biomedical Research Assistant with Multi-Database Integration
36b34ac
| """ | |
| Test configuration and fixtures for GQuery AI. | |
| This module provides common test utilities, fixtures, and configuration | |
| for the entire test suite. | |
| """ | |
| import asyncio | |
| import os | |
| from pathlib import Path | |
| from typing import Generator | |
| from unittest.mock import Mock | |
| import pytest | |
| # Test configuration | |
| def pytest_configure(config) -> None: | |
| """Configure pytest.""" | |
| # Set test environment | |
| os.environ["ENVIRONMENT"] = "test" | |
| os.environ["DEBUG"] = "true" | |
| # Disable external API calls during tests | |
| os.environ["NCBI__API_KEY"] = "test_key" | |
| os.environ["OPENAI__API_KEY"] = "test_key" | |
| def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]: | |
| """Create an instance of the default event loop for the test session.""" | |
| loop = asyncio.get_event_loop_policy().new_event_loop() | |
| yield loop | |
| loop.close() | |
| def mock_settings(): | |
| """Mock settings for testing.""" | |
| from gquery.config.settings import Settings | |
| settings = Settings( | |
| debug=True, | |
| environment="test", | |
| database=Mock(), | |
| redis=Mock(), | |
| ncbi=Mock(), | |
| openai=Mock(), | |
| logging=Mock(), | |
| security=Mock(), | |
| ) | |
| return settings | |
| def test_data_dir() -> Path: | |
| """Get test data directory.""" | |
| return Path(__file__).parent / "data" | |
| def sample_pmc_response(): | |
| """Sample PMC API response for testing.""" | |
| return { | |
| "esearchresult": { | |
| "count": "2", | |
| "retmax": "2", | |
| "idlist": ["1234567", "7654321"] | |
| } | |
| } | |
| def sample_clinvar_response(): | |
| """Sample ClinVar API response for testing.""" | |
| return { | |
| "result": { | |
| "1234": { | |
| "title": "BRCA1, c.5266dupC (p.Gln1756ProfsTer74)", | |
| "clinical_significance": ["Pathogenic"], | |
| "review_status": "criteria provided, multiple submitters, no conflicts" | |
| } | |
| } | |
| } | |
| def sample_ncbi_datasets_response(): | |
| """Sample NCBI Datasets API response for testing.""" | |
| return { | |
| "genes": [ | |
| { | |
| "gene": { | |
| "gene_id": 672, | |
| "symbol": "BRCA1", | |
| "description": "BRCA1, DNA repair associated", | |
| "type": "protein-coding" | |
| } | |
| } | |
| ] | |
| } | |
| class TestCase: | |
| """Base test case class with common utilities.""" | |
| def assert_valid_uuid(uuid_string: str) -> None: | |
| """Assert that a string is a valid UUID.""" | |
| from uuid import UUID | |
| try: | |
| UUID(uuid_string) | |
| except ValueError: | |
| pytest.fail(f"'{uuid_string}' is not a valid UUID") | |
| def assert_valid_timestamp(timestamp_string: str) -> None: | |
| """Assert that a string is a valid ISO timestamp.""" | |
| from datetime import datetime | |
| try: | |
| datetime.fromisoformat(timestamp_string.replace('Z', '+00:00')) | |
| except ValueError: | |
| pytest.fail(f"'{timestamp_string}' is not a valid ISO timestamp") | |