feat: honor temporal read context
This commit is contained in:
@@ -13,6 +13,11 @@ from govoplan_core.core.institutional import (
|
||||
MandateResolutionRequest,
|
||||
TemporalRevision,
|
||||
)
|
||||
from govoplan_core.core.temporal import (
|
||||
TemporalDataContext,
|
||||
bind_temporal_data_context,
|
||||
reset_temporal_data_context,
|
||||
)
|
||||
from govoplan_mandates.backend.db.models import MandateRevision
|
||||
from govoplan_mandates.backend.service import (
|
||||
MandateStoreError,
|
||||
@@ -124,6 +129,31 @@ class MandateTests(unittest.TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
def test_read_context_can_reconstruct_recorded_state(self) -> None:
|
||||
record_mandate(self.session, self.principal, definition=definition())
|
||||
record_mandate(
|
||||
self.session,
|
||||
self.principal,
|
||||
definition=definition(revision="2", status="suspended"),
|
||||
expected_revision="1",
|
||||
)
|
||||
token = bind_temporal_data_context(
|
||||
TemporalDataContext(
|
||||
validity_mode="at",
|
||||
valid_at=NOW + timedelta(hours=1),
|
||||
recorded_at=NOW + timedelta(seconds=30),
|
||||
)
|
||||
)
|
||||
try:
|
||||
result = get_mandate(
|
||||
self.session,
|
||||
self.principal,
|
||||
mandate_id="committee-permit",
|
||||
)
|
||||
self.assertEqual("1", result.temporal.revision if result else None)
|
||||
finally:
|
||||
reset_temporal_data_context(token)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user