|
| 1 | +"""Pytest configuration and fixtures for aieng_platform_onboard tests.""" |
| 2 | + |
| 3 | +from datetime import datetime, timezone |
| 4 | +from typing import Any |
| 5 | +from unittest.mock import Mock |
| 6 | + |
| 7 | +import pytest |
| 8 | +from google.cloud import firestore |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def mock_firestore_client() -> Mock: |
| 13 | + """ |
| 14 | + Create a mock Firestore client for testing. |
| 15 | +
|
| 16 | + Returns |
| 17 | + ------- |
| 18 | + Mock |
| 19 | + Mock Firestore client instance. |
| 20 | + """ |
| 21 | + return Mock(spec=firestore.Client) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def mock_firestore_document() -> Mock: |
| 26 | + """ |
| 27 | + Create a mock Firestore document for testing. |
| 28 | +
|
| 29 | + Returns |
| 30 | + ------- |
| 31 | + Mock |
| 32 | + Mock Firestore document instance. |
| 33 | + """ |
| 34 | + mock_doc = Mock() |
| 35 | + mock_doc.exists = True |
| 36 | + mock_doc.id = "test-handle" |
| 37 | + mock_doc.to_dict.return_value = { |
| 38 | + "github_handle": "test-handle", |
| 39 | + "team_name": "test-team", |
| 40 | + "onboarded": False, |
| 41 | + |
| 42 | + } |
| 43 | + return mock_doc |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture |
| 47 | +def sample_participant_data() -> dict[str, Any]: |
| 48 | + """ |
| 49 | + Sample participant data for testing. |
| 50 | +
|
| 51 | + Returns |
| 52 | + ------- |
| 53 | + dict[str, Any] |
| 54 | + Sample participant data dictionary. |
| 55 | + """ |
| 56 | + return { |
| 57 | + "github_handle": "test-user", |
| 58 | + "team_name": "test-team", |
| 59 | + "onboarded": False, |
| 60 | + |
| 61 | + "created_at": datetime.now(timezone.utc), |
| 62 | + } |
| 63 | + |
| 64 | + |
| 65 | +@pytest.fixture |
| 66 | +def sample_team_data() -> dict[str, Any]: |
| 67 | + """ |
| 68 | + Sample team data for testing. |
| 69 | +
|
| 70 | + Returns |
| 71 | + ------- |
| 72 | + dict[str, Any] |
| 73 | + Sample team data dictionary. |
| 74 | + """ |
| 75 | + return { |
| 76 | + "team_name": "test-team", |
| 77 | + "openai_api_key": "test-openai-key", |
| 78 | + "langfuse_secret_key": "test-langfuse-secret", |
| 79 | + "langfuse_public_key": "test-langfuse-public", |
| 80 | + "langfuse_url": "https://test-langfuse.example.com", |
| 81 | + "web_search_api_key": "test-search-key", |
| 82 | + "participants": ["test-user", "test-user-2"], |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | +@pytest.fixture |
| 87 | +def sample_global_keys() -> dict[str, Any]: |
| 88 | + """ |
| 89 | + Sample global keys for testing. |
| 90 | +
|
| 91 | + Returns |
| 92 | + ------- |
| 93 | + dict[str, Any] |
| 94 | + Sample global keys dictionary. |
| 95 | + """ |
| 96 | + return { |
| 97 | + "EMBEDDING_BASE_URL": "https://embedding.example.com", |
| 98 | + "EMBEDDING_API_KEY": "test-embedding-key", |
| 99 | + "WEAVIATE_HTTP_HOST": "weaviate.example.com", |
| 100 | + "WEAVIATE_GRPC_HOST": "weaviate-grpc.example.com", |
| 101 | + "WEAVIATE_API_KEY": "test-weaviate-key", |
| 102 | + "WEAVIATE_HTTP_PORT": "443", |
| 103 | + "WEAVIATE_GRPC_PORT": "50051", |
| 104 | + "WEAVIATE_HTTP_SECURE": "true", |
| 105 | + "WEAVIATE_GRPC_SECURE": "true", |
| 106 | + } |
| 107 | + |
| 108 | + |
| 109 | +@pytest.fixture |
| 110 | +def mock_requests_post(monkeypatch: pytest.MonkeyPatch) -> Mock: |
| 111 | + """ |
| 112 | + Mock requests.post for testing HTTP requests. |
| 113 | +
|
| 114 | + Parameters |
| 115 | + ---------- |
| 116 | + monkeypatch : pytest.MonkeyPatch |
| 117 | + Pytest monkeypatch fixture. |
| 118 | +
|
| 119 | + Returns |
| 120 | + ------- |
| 121 | + Mock |
| 122 | + Mock requests.post function. |
| 123 | + """ |
| 124 | + mock_response = Mock() |
| 125 | + mock_response.status_code = 200 |
| 126 | + mock_response.json.return_value = {"token": "test-token"} |
| 127 | + |
| 128 | + mock_post = Mock(return_value=mock_response) |
| 129 | + monkeypatch.setattr("requests.post", mock_post) |
| 130 | + return mock_post |
| 131 | + |
| 132 | + |
| 133 | +@pytest.fixture |
| 134 | +def mock_google_auth(monkeypatch: pytest.MonkeyPatch) -> tuple[Mock, str]: |
| 135 | + """ |
| 136 | + Mock google.auth.default for testing authentication. |
| 137 | +
|
| 138 | + Parameters |
| 139 | + ---------- |
| 140 | + monkeypatch : pytest.MonkeyPatch |
| 141 | + Pytest monkeypatch fixture. |
| 142 | +
|
| 143 | + Returns |
| 144 | + ------- |
| 145 | + tuple[Mock, str] |
| 146 | + Tuple of (mock_credentials, project_id). |
| 147 | + """ |
| 148 | + mock_credentials = Mock() |
| 149 | + mock_credentials. service_account_email = "[email protected]" |
| 150 | + mock_credentials.signer = Mock() |
| 151 | + |
| 152 | + def mock_default() -> tuple[Mock, str]: |
| 153 | + return mock_credentials, "test-project" |
| 154 | + |
| 155 | + monkeypatch.setattr("google.auth.default", mock_default) |
| 156 | + return mock_credentials, "test-project" |
| 157 | + |
| 158 | + |
| 159 | +@pytest.fixture |
| 160 | +def mock_subprocess_run(monkeypatch: pytest.MonkeyPatch) -> Mock: |
| 161 | + """ |
| 162 | + Mock subprocess.run for testing command execution. |
| 163 | +
|
| 164 | + Parameters |
| 165 | + ---------- |
| 166 | + monkeypatch : pytest.MonkeyPatch |
| 167 | + Pytest monkeypatch fixture. |
| 168 | +
|
| 169 | + Returns |
| 170 | + ------- |
| 171 | + Mock |
| 172 | + Mock subprocess.run function. |
| 173 | + """ |
| 174 | + mock_result = Mock() |
| 175 | + mock_result.returncode = 0 |
| 176 | + mock_result.stdout = "test output" |
| 177 | + mock_result.stderr = "" |
| 178 | + |
| 179 | + mock_run = Mock(return_value=mock_result) |
| 180 | + monkeypatch.setattr("subprocess.run", mock_run) |
| 181 | + return mock_run |
| 182 | + |
| 183 | + |
| 184 | +@pytest.fixture |
| 185 | +def mock_console(monkeypatch: pytest.MonkeyPatch) -> Mock: |
| 186 | + """ |
| 187 | + Mock Rich console for testing output. |
| 188 | +
|
| 189 | + Parameters |
| 190 | + ---------- |
| 191 | + monkeypatch : pytest.MonkeyPatch |
| 192 | + Pytest monkeypatch fixture. |
| 193 | +
|
| 194 | + Returns |
| 195 | + ------- |
| 196 | + Mock |
| 197 | + Mock console instance. |
| 198 | + """ |
| 199 | + mock_console_instance = Mock() |
| 200 | + monkeypatch.setattr("aieng_platform_onboard.utils.console", mock_console_instance) |
| 201 | + monkeypatch.setattr("aieng_platform_onboard.cli.console", mock_console_instance) |
| 202 | + return mock_console_instance |
0 commit comments