1d52da79e4
The code systems, value sets and the extensions (cut-offs, report id, interval, quartiles) each wrote the domain by hand. They now derive from webapi.fhir_base, a leaf module so metrics and durations can use it without a cycle. The default is unchanged; the WebApp still reads the same URLs by exact match, so changing the domain goes to both. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
"""Every FHIR URL the API emits hangs from one base, which FHIR_BASE_URL sets (issue 199)."""
|
|
|
|
import importlib
|
|
import sys
|
|
|
|
from webapi import durations, fhir_base, metrics
|
|
from webapi.fhir import common
|
|
|
|
POR_DEFECTO = "https://isssteleon.org/fhir"
|
|
|
|
|
|
def test_todas_las_urls_cuelgan_de_la_misma_base():
|
|
estructuras = [metrics.EVENT_CUTOFF, metrics.KNOWLEDGE_CUTOFF, metrics.HISTORY_ENTRY, metrics.INTERVAL_LOW, metrics.INTERVAL_HIGH]
|
|
assert all(u.startswith(f"{common.STRUCTURE}/") for u in estructuras)
|
|
assert common.STRUCTURE == f"{common.BASE}/StructureDefinition" == fhir_base.STRUCTURE
|
|
assert common.CODE_SYSTEM.startswith(common.BASE) and common.VALUE_SET.startswith(common.BASE)
|
|
|
|
|
|
def test_no_quedan_dominios_escritos_a_mano_fuera_de_la_base():
|
|
import pathlib
|
|
raiz = pathlib.Path(fhir_base.__file__).parent
|
|
escritos = [p.name for p in raiz.rglob("*.py") if "isssteleon.org" in p.read_text() and p.name != "fhir_base.py"]
|
|
assert escritos == []
|
|
|
|
|
|
def test_la_base_se_puede_cambiar_por_ambiente(monkeypatch):
|
|
monkeypatch.setenv("FHIR_BASE_URL", "https://fhir.ejemplo.test/base/")
|
|
try:
|
|
importlib.reload(fhir_base)
|
|
assert fhir_base.BASE == "https://fhir.ejemplo.test/base"
|
|
assert fhir_base.STRUCTURE == "https://fhir.ejemplo.test/base/StructureDefinition"
|
|
finally:
|
|
monkeypatch.delenv("FHIR_BASE_URL")
|
|
importlib.reload(fhir_base)
|
|
assert fhir_base.BASE == POR_DEFECTO
|
|
|
|
|
|
def test_los_q1_y_q3_de_los_tiempos_usan_la_misma_base():
|
|
assert durations.STRUCTURE == metrics.INTERVAL_LOW.rsplit("/", 1)[0]
|