|
1 | | -import pytest |
2 | 1 | import os |
| 2 | +from typing import Any, Generator |
| 3 | + |
3 | 4 | import psycopg2 |
4 | 5 | import psycopg2.extensions |
| 6 | +import pytest |
5 | 7 |
|
6 | 8 |
|
7 | | -@pytest.fixture(scope='session') |
8 | | -def raster_endpoint(): |
9 | | - return os.getenv('RASTER_ENDPOINT', "http://127.0.0.1/raster") |
| 9 | +@pytest.fixture(scope="session") |
| 10 | +def raster_endpoint() -> str: |
| 11 | + return os.getenv("RASTER_ENDPOINT", "http://127.0.0.1/raster") |
10 | 12 |
|
11 | 13 |
|
12 | | -@pytest.fixture(scope='session') |
13 | | -def vector_endpoint(): |
14 | | - return os.getenv('VECTOR_ENDPOINT', "http://127.0.0.1/vector") |
| 14 | +@pytest.fixture(scope="session") |
| 15 | +def vector_endpoint() -> str: |
| 16 | + return os.getenv("VECTOR_ENDPOINT", "http://127.0.0.1/vector") |
15 | 17 |
|
16 | 18 |
|
17 | | -@pytest.fixture(scope='session') |
18 | | -def stac_endpoint(): |
19 | | - return os.getenv('STAC_ENDPOINT', "http://127.0.0.1/stac") |
| 19 | +@pytest.fixture(scope="session") |
| 20 | +def stac_endpoint() -> str: |
| 21 | + return os.getenv("STAC_ENDPOINT", "http://127.0.0.1/stac") |
20 | 22 |
|
21 | 23 |
|
22 | | -@pytest.fixture(scope='session') |
23 | | -def db_connection(): |
| 24 | +@pytest.fixture(scope="session") |
| 25 | +def db_connection() -> Generator[Any, None, None]: |
24 | 26 | """Create database connection for testing.""" |
25 | 27 | # Require all database connection parameters to be explicitly set |
26 | | - required_vars = ['PGHOST', 'PGPORT', 'PGDATABASE', 'PGUSER', 'PGPASSWORD'] |
| 28 | + required_vars = ["PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD"] |
27 | 29 | missing_vars = [var for var in required_vars if not os.getenv(var)] |
28 | 30 |
|
29 | 31 | if missing_vars: |
30 | | - pytest.fail(f"Required environment variables not set: {', '.join(missing_vars)}") |
31 | | - |
32 | | - connection_params = { |
33 | | - 'host': os.getenv('PGHOST'), |
34 | | - 'port': int(os.getenv('PGPORT')), |
35 | | - 'database': os.getenv('PGDATABASE'), |
36 | | - 'user': os.getenv('PGUSER'), |
37 | | - 'password': os.getenv('PGPASSWORD') |
38 | | - } |
| 32 | + pytest.fail( |
| 33 | + f"Required environment variables not set: {', '.join(missing_vars)}" |
| 34 | + ) |
39 | 35 |
|
| 36 | + # All required vars are guaranteed to exist due to check above |
40 | 37 | try: |
41 | | - conn = psycopg2.connect(**connection_params) |
| 38 | + conn = psycopg2.connect( |
| 39 | + host=os.environ["PGHOST"], |
| 40 | + port=int(os.environ["PGPORT"]), |
| 41 | + database=os.environ["PGDATABASE"], |
| 42 | + user=os.environ["PGUSER"], |
| 43 | + password=os.environ["PGPASSWORD"], |
| 44 | + ) |
42 | 45 | conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
43 | 46 | yield conn |
44 | 47 | conn.close() |
|
0 commit comments