Skip to content

Commit 2d40419

Browse files
committed
feat: enhance test for refreshing materialized views with execution options tracking
1 parent 7c9bd47 commit 2d40419

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tests/test_cli_commands.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,28 @@ def __exit__(self, exc_type, exc, tb):
6363

6464
def test_refresh_pygeoapi_materialized_views_custom_and_concurrently(monkeypatch):
6565
executed_sql: list[str] = []
66+
execution_options: list[dict[str, object]] = []
67+
68+
class FakeConnection:
69+
def execution_options(self, **kwargs):
70+
execution_options.append(kwargs)
71+
return self
6672

67-
class FakeSession:
6873
def execute(self, stmt):
6974
executed_sql.append(str(stmt))
7075

71-
def commit(self):
72-
return None
73-
74-
class _FakeCtx:
76+
class _FakeConnCtx:
7577
def __enter__(self):
76-
return FakeSession()
78+
return FakeConnection()
7779

7880
def __exit__(self, exc_type, exc, tb):
7981
return False
8082

81-
monkeypatch.setattr("db.engine.session_ctx", lambda: _FakeCtx())
83+
class FakeEngine:
84+
def connect(self):
85+
return _FakeConnCtx()
86+
87+
monkeypatch.setattr("db.engine.engine", FakeEngine())
8288

8389
runner = CliRunner()
8490
result = runner.invoke(
@@ -92,6 +98,7 @@ def __exit__(self, exc_type, exc, tb):
9298
)
9399

94100
assert result.exit_code == 0, result.output
101+
assert execution_options == [{"isolation_level": "AUTOCOMMIT"}]
95102
assert executed_sql == [
96103
"REFRESH MATERIALIZED VIEW CONCURRENTLY ogc_avg_tds_wells",
97104
]
@@ -327,10 +334,12 @@ def test_water_levels_cli_persists_observations(tmp_path, water_well_thing):
327334
"""
328335

329336
def _write_csv(path: Path, *, well_name: str, notes: str):
330-
csv_text = textwrap.dedent(f"""\
337+
csv_text = textwrap.dedent(
338+
f"""\
331339
field_staff,well_name_point_id,field_event_date_time,measurement_date_time,sampler,sample_method,mp_height,level_status,depth_to_water_ft,data_quality,water_level_notes
332340
CLI Tester,{well_name},2025-02-15T08:00:00-07:00,2025-02-15T10:30:00-07:00,Groundwater Team,electric tape,1.5,stable,42.5,approved,{notes}
333-
""")
341+
"""
342+
)
334343
path.write_text(csv_text)
335344

336345
unique_notes = f"pytest-{uuid.uuid4()}"

0 commit comments

Comments
 (0)