Use shared access for synthetic breast follow-up
This commit is contained in:
@@ -97,7 +97,7 @@ def test_rejects_unknown_and_suppressed_selections_and_denies_access(client):
|
||||
assert client.get('/cama/seguimiento' + selection.replace('BIRADS_5', 'BIRADS_4A')).status_code == 403
|
||||
assert client.get('/cama/seguimiento' + selection.replace('cama_birads_v1', 'otra')).status_code == 400
|
||||
assert client.get('/cama/seguimiento' + selection.replace(selection[-64:], '0' * 64)).status_code == 409
|
||||
client.application.config['CAMA_COHORT_ACCESS'] = None
|
||||
client.application.config['CAMA_COHORT_ACCESS'] = lambda req: False
|
||||
assert client.get('/cama/seguimiento' + selection).status_code == 403
|
||||
assert client.get('/cama/seguimiento/exportacion' + selection).status_code == 403
|
||||
assert client.get('/cama/pacientes/some-id' + selection).status_code == 403
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
"""Exercise persistent cohort setup and its optional patient access boundary."""
|
||||
"""Verify default persistent cohort setup with retained legacy configuration."""
|
||||
|
||||
from flask import Flask, request
|
||||
from flask import Flask
|
||||
|
||||
from webapi.cama_runtime import configure_cama_cohort
|
||||
|
||||
|
||||
def test_missing_or_invalid_token_does_not_prevent_startup(monkeypatch):
|
||||
"""A malformed optional credential leaves the reader registered and access denied."""
|
||||
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 'short')
|
||||
def test_default_reader_uses_shared_persistence(monkeypatch):
|
||||
"""The reader is registered without special cohort environment variables."""
|
||||
for key in ('CAMA_COHORT_SYNTHETIC', 'CAMA_COHORT_SECRET', 'CAMA_COHORT_ACCESS_TOKEN'):
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
app = Flask(__name__)
|
||||
configure_cama_cohort(app)
|
||||
assert callable(app.config['CAMA_COHORT_READER'])
|
||||
with app.test_request_context(headers={'X-Cama-Cohort-Token': 'short'}):
|
||||
assert not app.config['CAMA_COHORT_ACCESS'](request)
|
||||
|
||||
|
||||
def test_access_token_is_checked_on_the_server(monkeypatch):
|
||||
"""The retained proxy credential gates patient routes until a shared boundary is available."""
|
||||
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 't' * 32)
|
||||
app = Flask(__name__)
|
||||
configure_cama_cohort(app)
|
||||
with app.test_request_context(headers={'X-Cama-Cohort-Token': 't' * 32}):
|
||||
assert app.config['CAMA_COHORT_ACCESS'](request)
|
||||
with app.test_request_context(headers={'X-Cama-Cohort-Token': 'incorrect'}):
|
||||
assert not app.config['CAMA_COHORT_ACCESS'](request)
|
||||
assert 'CAMA_COHORT_ACCESS' not in app.config
|
||||
|
||||
|
||||
def test_application_starts_with_retained_obsolete_configuration(monkeypatch):
|
||||
"""Old synthetic settings or a bad token cannot prevent the health endpoint starting."""
|
||||
"""Retained synthetic settings cannot prevent the health endpoint starting."""
|
||||
monkeypatch.setenv('CAMA_COHORT_SYNTHETIC', '1')
|
||||
monkeypatch.delenv('CAMA_COHORT_SECRET', raising=False)
|
||||
monkeypatch.setenv('CAMA_COHORT_ACCESS_TOKEN', 'invalid')
|
||||
from webapi import create_app
|
||||
|
||||
client = create_app().test_client()
|
||||
assert client.get('/health').get_json() == {'status': 'ok'}
|
||||
assert client.get('/cama/seguimiento').status_code == 403
|
||||
assert create_app().test_client().get('/health').get_json() == {'status': 'ok'}
|
||||
|
||||
@@ -72,6 +72,17 @@ def test_a_scored_member_has_the_contracts_shape(client, seeded):
|
||||
assert [(h["horizonte_anios"], h["probabilidad"], h["estado"]) for h in horizons] == [(1.0, 0.1, "final"), (3.0, 0.3, "final")]
|
||||
|
||||
|
||||
def test_follow_up_identity_resolves_scored_patient(client, seeded):
|
||||
"""The patient selected from follow-up resolves to that patient's seeded risk."""
|
||||
listing = client.get('/cacu/seguimiento?corte=2025-12-31&meses=12&page_size=200').get_json()
|
||||
row = next(item for item in listing['items'] if item['pac_id'] == str(seeded[0]))
|
||||
assert row['id_seudonimo'] == row['pac_id']
|
||||
response = client.get(f"/cacu/pacientes/{row['pac_id']}/riesgo")
|
||||
assert response.status_code == 200
|
||||
assert response.get_json()['cohorte']['pap_0'] == 'ASC-US'
|
||||
assert response.get_json()['riesgo']['horizontes'][0]['probabilidad'] == 0.1
|
||||
|
||||
|
||||
def test_a_member_without_a_confirmed_batch_and_a_non_member(client, seeded):
|
||||
"""Pins down: a member nobody scored has `cohorte` and `riesgo: null`; a patient outside the latest build has both
|
||||
null. Fails if either case errors or invents a risk."""
|
||||
|
||||
Reference in New Issue
Block a user