|
15 | 15 |
|
16 | 16 | from hotdata import ApiClient, Configuration |
17 | 17 | from hotdata.api.connections_api import ConnectionsApi |
| 18 | +from hotdata.api.databases_api import DatabasesApi |
18 | 19 | from hotdata.api.datasets_api import DatasetsApi |
19 | 20 | from hotdata.api.indexes_api import IndexesApi |
20 | 21 | from hotdata.api.saved_queries_api import SavedQueriesApi |
21 | 22 | from hotdata.api.secrets_api import SecretsApi |
22 | 23 | from hotdata.api.workspaces_api import WorkspacesApi |
| 24 | +from hotdata.models.create_database_request import CreateDatabaseRequest |
23 | 25 |
|
24 | 26 |
|
25 | 27 | REQUIRED_ENV = ("HOTDATA_SDK_TEST_API_KEY", "HOTDATA_SDK_TEST_WORKSPACE_ID") |
26 | 28 | DEFAULT_API_URL = "https://api.hotdata.dev" |
27 | 29 |
|
| 30 | +# Queries are scoped to a database via the X-Database-Id header. Databases no |
| 31 | +# longer auto-expire, so rather than create one per run (which would leak), |
| 32 | +# tests find-or-create a single stable database by name and reuse it — same |
| 33 | +# pattern as the e2e suite. Name is not unique server-side; we key off it. |
| 34 | +SHARED_DATABASE_NAME = "sdkci-shared" |
| 35 | + |
28 | 36 |
|
29 | 37 | @dataclass(frozen=True) |
30 | 38 | class TestEnv: |
@@ -79,6 +87,23 @@ def connection_id(env: TestEnv) -> str: |
79 | 87 | return env.connection_id |
80 | 88 |
|
81 | 89 |
|
| 90 | +@pytest.fixture(scope="session") |
| 91 | +def database_id(api_client: ApiClient) -> str: |
| 92 | + """Id of the shared `sdkci-shared` database, creating it if absent. |
| 93 | +
|
| 94 | + Queries require an `X-Database-Id` scope; databases persist (no auto-expiry) |
| 95 | + so we reuse one across runs instead of creating-and-deleting per session. |
| 96 | + """ |
| 97 | + databases_api = DatabasesApi(api_client) |
| 98 | + for db in databases_api.list_databases().databases: |
| 99 | + if db.name == SHARED_DATABASE_NAME: |
| 100 | + return db.id |
| 101 | + created = databases_api.create_database( |
| 102 | + CreateDatabaseRequest(name=SHARED_DATABASE_NAME) |
| 103 | + ) |
| 104 | + return created.id |
| 105 | + |
| 106 | + |
82 | 107 | @pytest.fixture |
83 | 108 | def sdkci_name() -> "callable[[str], str]": |
84 | 109 | """Returns `sdkci-<scenario>-<uuid8>` so orphans are identifiable. |
@@ -109,6 +134,11 @@ def connections_api(api_client: ApiClient) -> ConnectionsApi: |
109 | 134 | return ConnectionsApi(api_client) |
110 | 135 |
|
111 | 136 |
|
| 137 | +@pytest.fixture |
| 138 | +def databases_api(api_client: ApiClient) -> DatabasesApi: |
| 139 | + return DatabasesApi(api_client) |
| 140 | + |
| 141 | + |
112 | 142 | @pytest.fixture |
113 | 143 | def indexes_api(api_client: ApiClient) -> IndexesApi: |
114 | 144 | return IndexesApi(api_client) |
|
0 commit comments