|
1 | | -pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql", "pytest_databases.docker.oracle"] |
| 1 | +pytest_plugins = ["pytest_databases.docker.postgres", "pytest_databases.docker.mysql", |
| 2 | + "pytest_databases.docker.oracle", "pytest_databases.docker.bigquery"] |
| 3 | + |
| 4 | +from collections.abc import Generator |
| 5 | +from typing import Any |
| 6 | + |
| 7 | +import pytest |
| 8 | +from google.api_core.client_options import ClientOptions |
| 9 | +from google.auth.credentials import AnonymousCredentials |
| 10 | +from pytest_databases.docker.bigquery import BigQueryService |
| 11 | + |
| 12 | +from sqlspec.adapters.bigquery.config import BigQueryConfig |
| 13 | +from sqlspec.adapters.bigquery.driver import BigQueryDriver |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def table_schema_prefix(bigquery_service: "BigQueryService") -> str: |
| 18 | + """Create a table schema prefix.""" |
| 19 | + return f"`{bigquery_service.project}`.`{bigquery_service.dataset}`" |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def bigquery_config(bigquery_service: "BigQueryService", table_schema_prefix: str) -> BigQueryConfig: |
| 24 | + """Create a BigQuery config object.""" |
| 25 | + return BigQueryConfig( |
| 26 | + connection_config={ |
| 27 | + "project": bigquery_service.project, |
| 28 | + "dataset_id": table_schema_prefix, |
| 29 | + "client_options": ClientOptions(api_endpoint=f"http://{bigquery_service.host}:{bigquery_service.port}"), |
| 30 | + "credentials": AnonymousCredentials(), # type: ignore[no-untyped-call] |
| 31 | + } |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +@pytest.fixture |
| 36 | +def bigquery_session(bigquery_config: BigQueryConfig) -> Generator[BigQueryDriver, Any, None]: |
| 37 | + """Create a BigQuery sync session.""" |
| 38 | + |
| 39 | + with bigquery_config.provide_session() as session: |
| 40 | + yield session |
| 41 | + |
0 commit comments