diff --git a/tests/test_metrics_on_request.py b/tests/test_metrics_on_request.py index ee03ccc..2b7ba59 100644 --- a/tests/test_metrics_on_request.py +++ b/tests/test_metrics_on_request.py @@ -158,6 +158,19 @@ def test_eu7_puts_each_patient_in_her_last_valid_result_as_the_kit_did(base, eu7 assert without(composition_cells(result), STATUS) == expected["published"], period_id +def test_every_stratum_value_written_is_in_the_catalog(base, eu13, eu7): + """Pins down: the strata an answer writes satisfy their foreign key to `cat_estrato_valor`, which SQLite doesn't + enforce unless asked and SQL Server always does. Fails if `MeasureHistoryRepository.record` stops adding the + stratum values the catalog lacks.""" + for d in (eu13, eu7): + ask(base, d, "2025-S1") + with base.motor.connect() as connection: + written = connection.execute(text("select count(*) from measure_report_unidad_estrato")).scalar() + broken = connection.execute(text("pragma foreign_key_check('measure_report_unidad_estrato')")).all() + assert written > 0 + assert broken == [] + + def test_a_stored_answer_reads_back_the_same(base, definition, eu13, eu7): """Pins down: asking again reads the stored answer from its units' counts, with no view, and it's the same answer, strata included. Fails if `MeasureHistoryRepository.counts` and the computation stop agreeing."""