Risk batches: a decision that collides with another of the same batch is a 409
Two decisions of one batch at the same moment (a double click reaching both workers) wrote the same evaluation version and the second surfaced as a server error.
This commit is contained in:
@@ -100,3 +100,17 @@ def test_an_unknown_batch_is_404(client):
|
||||
"""Pins down: a `lote_id` with no evaluations is 404, not a silent no-op. Fails if it answers 200 having changed
|
||||
nothing."""
|
||||
assert client.post("/cacu/riesgos/lotes/987654321/confirmar", json={"reason": "revisado"}).status_code == 404
|
||||
|
||||
|
||||
def test_a_decision_that_collides_with_another_is_409(client, monkeypatch):
|
||||
"""Pins down: two decisions of one batch at the same moment (a double click reaching both workers) give the
|
||||
second a 409 instead of a server error. Fails if the unique version of an evaluation surfaces as a 500."""
|
||||
from persistance import cacu
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
def collide(*args, **kwargs):
|
||||
raise IntegrityError("INSERT", {}, Exception("UNIQUE constraint failed"))
|
||||
|
||||
monkeypatch.setattr(cacu.cohort_repository, "change_state", collide)
|
||||
|
||||
assert client.post("/cacu/riesgos/lotes/1/confirmar", json={"reason": "revisado"}).status_code == 409
|
||||
|
||||
Reference in New Issue
Block a user