Skip to content

Commit 0e596dc

Browse files
authored
feat: Enforce typing for tests written in python. (#347)
1 parent 1253640 commit 0e596dc

File tree

9 files changed

+331
-174
lines changed

9 files changed

+331
-174
lines changed

.github/workflows/tests/conftest.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
import pytest
21
import os
2+
from typing import Any, Generator
3+
34
import psycopg2
45
import psycopg2.extensions
6+
import pytest
57

68

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")
1012

1113

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")
1517

1618

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")
2022

2123

22-
@pytest.fixture(scope='session')
23-
def db_connection():
24+
@pytest.fixture(scope="session")
25+
def db_connection() -> Generator[Any, None, None]:
2426
"""Create database connection for testing."""
2527
# 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"]
2729
missing_vars = [var for var in required_vars if not os.getenv(var)]
2830

2931
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+
)
3935

36+
# All required vars are guaranteed to exist due to check above
4037
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+
)
4245
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
4346
yield conn
4447
conn.close()

.github/workflows/tests/test_autoscaling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def make_request(url: str, timeout: int = 10) -> bool:
140140
"""Make a single HTTP request and return success status."""
141141
try:
142142
response = requests.get(url, timeout=timeout)
143-
return response.status_code == 200
143+
return bool(response.status_code == 200)
144144
except requests.RequestException:
145145
return False
146146

.github/workflows/tests/test_notifications.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import json
44
import subprocess
55
import time
6+
from typing import Any
67

78
import pytest
89

910

10-
def test_eoapi_notifier_deployment():
11+
def test_eoapi_notifier_deployment() -> None:
1112
"""Test that eoapi-notifier deployment is running."""
1213
# Check if eoapi-notifier deployment exists and is ready
1314
result = subprocess.run(
@@ -38,7 +39,7 @@ def test_eoapi_notifier_deployment():
3839
)
3940

4041

41-
def test_cloudevents_sink_exists():
42+
def test_cloudevents_sink_exists() -> None:
4243
"""Test that Knative CloudEvents sink service exists and is accessible."""
4344
# Check if Knative service exists
4445
result = subprocess.run(
@@ -64,7 +65,7 @@ def test_cloudevents_sink_exists():
6465
)
6566

6667

67-
def test_notification_configuration():
68+
def test_notification_configuration() -> None:
6869
"""Test that eoapi-notifier is configured correctly."""
6970
# Get the configmap for eoapi-notifier
7071
result = subprocess.run(
@@ -94,7 +95,7 @@ def test_notification_configuration():
9495
)
9596

9697

97-
def test_cloudevents_sink_logs_show_startup():
98+
def test_cloudevents_sink_logs_show_startup() -> None:
9899
"""Test that Knative CloudEvents sink started successfully."""
99100
# Get Knative CloudEvents sink pod logs
100101
result = subprocess.run(
@@ -123,7 +124,7 @@ def test_cloudevents_sink_logs_show_startup():
123124
)
124125

125126

126-
def test_eoapi_notifier_logs_show_connection():
127+
def test_eoapi_notifier_logs_show_connection() -> None:
127128
"""Test that eoapi-notifier connects to database successfully."""
128129
# Give some time for the notifier to start
129130
time.sleep(5)
@@ -150,7 +151,7 @@ def test_eoapi_notifier_logs_show_connection():
150151
assert "Authentication failed" not in logs, "Should not have auth errors"
151152

152153

153-
def test_database_notification_triggers_exist(db_connection):
154+
def test_database_notification_triggers_exist(db_connection: Any) -> None:
154155
"""Test that pgstac notification triggers are installed."""
155156
with db_connection.cursor() as cur:
156157
# Check if the notification function exists
@@ -180,7 +181,7 @@ def test_database_notification_triggers_exist(db_connection):
180181
)
181182

182183

183-
def test_end_to_end_notification_flow(db_connection):
184+
def test_end_to_end_notification_flow(db_connection: Any) -> None:
184185
"""Test complete flow: database → eoapi-notifier → Knative CloudEvents sink."""
185186

186187
# Skip if notifications not enabled
@@ -269,7 +270,7 @@ def test_end_to_end_notification_flow(db_connection):
269270
cursor.execute("SELECT pgstac.delete_item(%s);", (test_item_id,))
270271

271272

272-
def test_k_sink_injection():
273+
def test_k_sink_injection() -> None:
273274
"""Test that SinkBinding injects K_SINK into eoapi-notifier deployment."""
274275
# Check if eoapi-notifier deployment exists
275276
result = subprocess.run(

0 commit comments

Comments
 (0)