108 lines
3.3 KiB
Python
108 lines
3.3 KiB
Python
"""The capability catalogue and its register of frameworks."""
|
|
|
|
import shutil
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from app.operating_model import catalogue as capability_catalogue
|
|
from app.operating_model.catalogue import CatalogueError
|
|
from app.operating_model.workflow import ROOT
|
|
from tests.support import CATALOGUE, scope_data
|
|
|
|
SKILL = ROOT / "skills" / capability_catalogue.SKILL
|
|
|
|
|
|
def test_every_entry_cites_a_framework_that_is_in_the_register():
|
|
for entry in CATALOGUE.entries.values():
|
|
assert entry.sources, entry.id
|
|
assert all(s["framework"] in CATALOGUE.frameworks for s in entry.sources)
|
|
assert entry.purpose and entry.typical_checks, entry.id
|
|
|
|
|
|
def test_the_register_says_its_references_have_not_been_checked():
|
|
assert CATALOGUE.verified is False
|
|
|
|
|
|
def test_the_two_things_called_dora_are_kept_apart():
|
|
names = {key: value["name"] for key, value in CATALOGUE.frameworks.items()}
|
|
|
|
assert "Regulation (EU) 2022/2554" in names["eu-dora"]
|
|
assert "DevOps Research and Assessment" in names["dora-metrics"]
|
|
|
|
|
|
@pytest.fixture
|
|
def skill(tmp_path):
|
|
shutil.copytree(SKILL, tmp_path / "skill")
|
|
return tmp_path / "skill"
|
|
|
|
|
|
def edit(skill, name, change):
|
|
path = skill / "assets" / name
|
|
data = yaml.safe_load(path.read_text())
|
|
change(data)
|
|
path.write_text(yaml.safe_dump(data))
|
|
|
|
|
|
def test_an_entry_that_cites_nothing_is_refused(skill):
|
|
edit(skill, "catalogue.yaml", lambda d: d["capabilities"][0].update(sources=[]))
|
|
|
|
with pytest.raises(CatalogueError, match="incident-management cites no source"):
|
|
capability_catalogue.load(skill)
|
|
|
|
|
|
def test_an_entry_that_cites_an_unregistered_framework_is_refused(skill):
|
|
edit(
|
|
skill,
|
|
"catalogue.yaml",
|
|
lambda d: d["capabilities"][0]["sources"].append(
|
|
{"framework": "folklore", "reference": "What we always did"}
|
|
),
|
|
)
|
|
|
|
with pytest.raises(
|
|
CatalogueError, match="cites 'folklore', which is not in the register"
|
|
):
|
|
capability_catalogue.load(skill)
|
|
|
|
|
|
def test_a_framework_registered_without_its_licence_is_refused(skill):
|
|
edit(skill, "sources.yaml", lambda d: d["frameworks"]["itil-4"].pop("licence"))
|
|
|
|
with pytest.raises(CatalogueError, match="itil-4 needs licence"):
|
|
capability_catalogue.load(skill)
|
|
|
|
|
|
def test_entries_are_proposed_from_what_the_spec_says():
|
|
proposed = CATALOGUE.applicable(scope_data())
|
|
|
|
# Always; for an Item of a kind; for a framework named; for a sourcing model.
|
|
assert "incident-management" in proposed
|
|
assert "backup-and-recovery" in proposed # the audit log store is storage
|
|
assert "regulatory-evidence" in proposed # DORA
|
|
assert "supplier-management" in proposed # shared
|
|
|
|
|
|
def test_an_entry_is_not_proposed_when_nothing_calls_for_it():
|
|
bare = {
|
|
"stated": {
|
|
"solution": {"items": [{"id": "S-1", "name": "Hub", "kind": "network"}]}
|
|
}
|
|
}
|
|
|
|
proposed = CATALOGUE.applicable(bare)
|
|
|
|
assert "incident-management" in proposed
|
|
assert not {
|
|
"backup-and-recovery",
|
|
"regulatory-evidence",
|
|
"supplier-management",
|
|
} & set(proposed)
|
|
|
|
|
|
def test_sources_are_cited_by_framework_and_part_never_quoted():
|
|
lines = capability_catalogue.cited(CATALOGUE, ["incident-management"])
|
|
|
|
assert "ITIL 4: Incident management practice" in lines
|
|
assert any(line.startswith("Regulation (EU) 2022/2554") for line in lines)
|