-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_snapshot.py
More file actions
37 lines (28 loc) · 1.41 KB
/
test_snapshot.py
File metadata and controls
37 lines (28 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Snapshot assertion validation tests for the PostgreSQL dialect.
This module replicates the precise database interactions evaluated in the explicit execution tests,
but enforces the automated snapshotting feature instead. This ensures parity between explicit string
assertions and transparent disk-based snapshot assertions.
"""
import pytest
from sqlalchemy.orm import joinedload
from tests.models import AlarmPanel, Sensor
pytestmark = pytest.mark.xdist_group("e2e_postgres")
def test_insert_and_select_snapshot(postgres_session, postgres_capquery):
"""Validate that PostgreSQL returning inserts and complex select operations emit events which
are accurately captured and automatically evaluated against the disk file by the snapshot
assertion system.
Snapshot Asset: `__capquery_snapshots__/test_snapshot/test_insert_and_select_snapshot.sql`
"""
with postgres_capquery.capture(assert_snapshot=True):
panel = AlarmPanel(mac_address="00:11:22:33:44:55", is_online=True)
sensor = Sensor(name="Front Door", sensor_type="Contact")
panel.sensors.append(sensor)
postgres_session.add(panel)
postgres_session.flush()
queried_panel = (
postgres_session.query(AlarmPanel)
.options(joinedload(AlarmPanel.sensors))
.filter_by(mac_address="00:11:22:33:44:55")
.first()
)
assert queried_panel is not None