lawsynth/python/lawsynth-server/tests/test_idempotency.py
2026-08-16 22:04:11 +03:00

17 lines
564 B
Python

import pytest
from lawsynth_server.errors import IdempotencyConflict
from lawsynth_server.idempotency import IdempotencyStore
def test_replay_and_payload_conflict():
store, calls = IdempotencyStore(), []
def handler():
calls.append(1)
return 201, {"id": str(len(calls))}
assert store.execute("org", "key", {"a": 1}, handler)[2] is False
assert store.execute("org", "key", {"a": 1}, handler)[2] is True
assert len(calls) == 1
with pytest.raises(IdempotencyConflict):
store.execute("org", "key", {"a": 2}, handler)