init public release
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
"""Orchestration test for ``multiple_adapters.main``.
|
||||
|
||||
``main`` is thin glue, so we mock every collaborator and assert the wiring:
|
||||
which adapter runs, the schema/script calls, and the sentinel file write.
|
||||
|
||||
LIMITATION: ``adapter_mode`` is a hardcoded local (= 0), so only the FHIR
|
||||
branch is reachable. The mode-1 (XML) and mode--1 (both) tests below are
|
||||
written but skipped — un-skip them once ``main`` accepts ``adapter_mode`` as
|
||||
a parameter or reads it from the environment. They document the intended
|
||||
behaviour and become live the moment the refactor lands.
|
||||
"""
|
||||
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import multiple_adapters
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked(monkeypatch):
|
||||
m = mock.Mock()
|
||||
monkeypatch.setattr(multiple_adapters, "BioCypher", m.BioCypher)
|
||||
monkeypatch.setattr(multiple_adapters, "write_automated_schema", m.write_automated_schema)
|
||||
monkeypatch.setattr(multiple_adapters, "load_multiple_fhir_patients", m.load_fhir)
|
||||
monkeypatch.setattr(multiple_adapters, "generate_neo4j_import_script", m.gen_script)
|
||||
monkeypatch.setattr(multiple_adapters, "xp", m.xp)
|
||||
monkeypatch.setenv("NUMBER_OF_PATIENTS", "5")
|
||||
return m
|
||||
|
||||
|
||||
def test_mode_zero_runs_fhir_loader_and_writes_sentinel(mocked):
|
||||
open_mock = mock.mock_open()
|
||||
with mock.patch("builtins.open", open_mock):
|
||||
multiple_adapters.main()
|
||||
|
||||
mocked.load_fhir.assert_called_once_with(5)
|
||||
mocked.xp.parse_xml_generate_nodes.assert_not_called() # XML branch off
|
||||
mocked.write_automated_schema.assert_called_once()
|
||||
mocked.gen_script.assert_called_once()
|
||||
open_mock.assert_called_once_with("/neo4j_import/shell-scipt-complete", "w")
|
||||
|
||||
|
||||
def test_number_of_patients_unset_raises(mocked, monkeypatch):
|
||||
monkeypatch.delenv("NUMBER_OF_PATIENTS", raising=False)
|
||||
with mock.patch("builtins.open", mock.mock_open()):
|
||||
with pytest.raises(TypeError): # int(None)
|
||||
multiple_adapters.main()
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="adapter_mode is hardcoded to 0; un-skip after making it configurable")
|
||||
def test_mode_one_runs_xml_adapter(mocked):
|
||||
open_mock = mock.mock_open()
|
||||
with mock.patch("builtins.open", open_mock):
|
||||
multiple_adapters.main() # would need adapter_mode == 1
|
||||
mocked.xp.parse_xml_generate_nodes.assert_called_once()
|
||||
mocked.xp.parse_xml_generate_edges.assert_called_once()
|
||||
mocked.load_fhir.assert_not_called()
|
||||
Reference in New Issue
Block a user