File size: 2,968 Bytes
31f0e50 | 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 | """
Pytest Configuration and Fixtures.
Provides shared fixtures for all test modules.
"""
import pytest
from typing import Generator, Dict, Any
@pytest.fixture(scope="session")
def client():
"""
Create a test client for the FastAPI application.
Yields:
TestClient instance
"""
from fastapi.testclient import TestClient
from app.main import app
# Create TestClient - compatible with newer httpx versions
test_client = TestClient(app)
yield test_client
@pytest.fixture
def sample_scam_message() -> str:
"""
Provide a sample scam message for testing.
Returns:
Sample scam message string
"""
return "Congratulations! You have won 10 lakh rupees. Share your OTP to claim the prize immediately."
@pytest.fixture
def sample_hindi_scam_message() -> str:
"""
Provide a sample Hindi scam message for testing.
Returns:
Sample Hindi scam message string
"""
return "आप जीत गए हैं 10 लाख रुपये! अपना OTP शेयर करें।"
@pytest.fixture
def sample_legitimate_message() -> str:
"""
Provide a sample legitimate message for testing.
Returns:
Sample legitimate message string
"""
return "Hi, how are you doing today? Hope you are well."
@pytest.fixture
def sample_engage_request() -> Dict[str, Any]:
"""
Provide a sample engage request payload.
Returns:
Request payload dictionary
"""
return {
"message": "You won 10 lakh! Send OTP now!",
"language": "auto",
}
@pytest.fixture
def sample_session_state() -> Dict[str, Any]:
"""
Provide a sample session state for testing.
Returns:
Session state dictionary
"""
return {
"messages": [],
"scam_confidence": 0.0,
"turn_count": 0,
"extracted_intel": {},
"strategy": "build_trust",
"language": "en",
"persona": "elderly",
}
@pytest.fixture
def sample_extracted_intelligence() -> Dict[str, Any]:
"""
Provide sample extracted intelligence for testing.
Returns:
Intelligence dictionary
"""
return {
"upi_ids": ["scammer@paytm", "fraud@ybl"],
"bank_accounts": ["1234567890123"],
"ifsc_codes": ["SBIN0001234"],
"phone_numbers": ["+919876543210"],
"phishing_links": ["http://fake-bank.com/verify"],
}
@pytest.fixture
def mock_environment_variables(monkeypatch):
"""
Set up mock environment variables for testing.
Args:
monkeypatch: Pytest monkeypatch fixture
"""
monkeypatch.setenv("ENVIRONMENT", "testing")
monkeypatch.setenv("DEBUG", "true")
monkeypatch.setenv("LOG_LEVEL", "DEBUG")
monkeypatch.setenv("GROQ_API_KEY", "test_key")
|