File size: 3,184 Bytes
36b34ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
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"


@pytest.fixture(scope="session")
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()


@pytest.fixture
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


@pytest.fixture
def test_data_dir() -> Path:
    """Get test data directory."""
    return Path(__file__).parent / "data"


@pytest.fixture
def sample_pmc_response():
    """Sample PMC API response for testing."""
    return {
        "esearchresult": {
            "count": "2",
            "retmax": "2",
            "idlist": ["1234567", "7654321"]
        }
    }


@pytest.fixture
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"
            }
        }
    }


@pytest.fixture
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."""
    
    @staticmethod
    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")
    
    @staticmethod
    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")