"""The chain's data files: what links each to the one before, and what is refused.""" import copy import pytest from app.operating_model import chain from app.operating_model.names import CAPABILITIES_FILE, REQUIREMENTS_FILE from tests.support import CAPABILITIES, CATALOGUE, REQUIREMENTS, as_file, upstream check_capabilities = chain.check_capabilities(CATALOGUE) def requirements(*changes) -> list[dict]: entries = copy.deepcopy(REQUIREMENTS) for change in changes: change(entries) return entries def capabilities(*changes) -> list[dict]: entries = copy.deepcopy(CAPABILITIES) for change in changes: change(entries) return entries def test_requirements_traced_to_what_the_customer_stated_are_accepted(): assert ( chain.check_requirements(as_file(REQUIREMENTS_FILE, REQUIREMENTS), upstream()) == [] ) @pytest.mark.parametrize( ("change", "problem"), [ (lambda e: e[0].update(source=[]), "OR-1 has no source"), ( lambda e: e[0].update(source=["OR-99"]), "source OR-99 is not a stated requirement", ), ( lambda e: e[0].update(source=["commercial.exchange_rate"]), "source commercial.exchange_rate is not a stated requirement", ), (lambda e: e[0].update(kind="wish"), "OR-1: kind must be one of"), (lambda e: e[0].update(statement=" "), "OR-1 needs a statement"), (lambda e: e.append(dict(e[0])), "id OR-1 is used more than once"), ( lambda e: e[1].update(source=["sourcing.model"]), "the customer's requirement REQ-01 is carried by no Operational requirement", ), ( lambda e: e.pop(4), "the customer stated sourcing.delivery_countries, and no Operational requirement", ), ], ) def test_a_requirement_that_breaks_the_chain_is_refused(change, problem): faults = chain.check_requirements( as_file(REQUIREMENTS_FILE, requirements(change)), upstream() ) assert any(problem in fault for fault in faults), faults def test_what_was_assumed_can_be_a_source_but_does_not_bind(): # `change_process: decide` leaves it to the agent, so nothing has to name it. scope = upstream()["operating_scope"]["attachments"]["scope.json"] assert "operations.change_process" not in scope.split('"binding"')[1].split("]")[0] def test_an_empty_file_is_refused_and_bad_json_is_named(): assert chain.check_requirements({REQUIREMENTS_FILE: "[]"}, upstream()) == [ "operational-requirements.json: lists no Operational requirements" ] assert ( "not valid JSON" in chain.check_requirements({REQUIREMENTS_FILE: "{"}, None)[0] ) def test_capabilities_from_the_catalogue_that_cover_everything_are_accepted(): assert ( check_capabilities(as_file(CAPABILITIES_FILE, CAPABILITIES), upstream()) == [] ) @pytest.mark.parametrize( ("change", "problem"), [ ( lambda e: e[0].update(catalogue="firefighting"), "'firefighting' is not in the capability catalogue", ), ( lambda e: e[0].update(catalogue="custom"), "C-1 is custom and gives no reason", ), (lambda e: e[0].update(serves=[]), "C-1 serves no Operational requirement"), ( lambda e: e[0].update(serves=["OR-1", "OR-9"]), "C-1 serves OR-9, which is not an Operational requirement", ), ( lambda e: e[0].update(items=["S-1", "S-9"]), "C-1 covers S-9, which is not an Item", ), ( lambda e: [c.update(items=["S-1", "S-2"]) for c in e], "Item S-3 is covered by no Capability", ), (lambda e: e.pop(1), "Operational requirement OR-2 is served by no Capability"), (lambda e: e[0].update(hours="always"), "C-1: hours must be one of"), ( lambda e: e[0].update(hours="business"), "faults are responded to 24x7, and Incident management is staffed only business", ), ( lambda e: e[0].update(effort_hours_per_month=0), "effort_hours_per_month must be a number above zero", ), (lambda e: e[0].update(basis=""), "C-1 needs a basis for its effort"), ], ) def test_a_capability_that_breaks_the_chain_is_refused(change, problem): faults = check_capabilities( as_file(CAPABILITIES_FILE, capabilities(change)), upstream() ) assert any(problem in fault for fault in faults), faults def test_a_custom_capability_with_a_name_and_a_reason_is_accepted(): custom = capabilities( lambda e: e[2].update( catalogue="custom", name="Evidence keeping", reason="No entry fits." ) ) assert check_capabilities(as_file(CAPABILITIES_FILE, custom), upstream()) == []