from __future__ import annotations def base_graph(): return { "classes": [{"uid": "customer", "name": "Customer"}], "properties": [ { "uid": "customer-id", "name": "customerId", "class_uid": "customer", "required": True, "cardinality": "1", "data_element_uid": "element-1", } ], "relations": [], "constraints": [], "domain_links": [{"domain_uid": "domain-1", "role": "owner"}], "element_mappings": [{"property_uid": "customer-id", "data_element_uid": "element-1"}], } def test_valid_graph_has_no_errors(): from app.core.data_research.ontology.validation import validate_graph assert validate_graph(base_graph()) == [] def test_validation_reports_stable_codes_for_governance_failures(): from app.core.data_research.ontology.validation import validate_graph graph = base_graph() graph["classes"] += [ {"uid": "duplicate", "name": "Customer", "parent_uid": "missing"}, {"uid": "cycle-a", "name": "CycleA", "parent_uid": "cycle-b"}, {"uid": "cycle-b", "name": "CycleB", "parent_uid": "cycle-a"}, ] graph["properties"][0]["cardinality"] = "many-to-sometimes" graph["properties"][0].pop("data_element_uid") graph["element_mappings"] = [] graph["relations"] = [{"uid": "bad-edge", "from_class_uid": "customer", "to_class_uid": "gone"}] graph["domain_links"] = [{"domain_uid": "domain-1", "role": "consumer"}] codes = {issue.code for issue in validate_graph(graph)} assert codes == { "ONTOLOGY_DUPLICATE_NAME", "ONTOLOGY_DANGLING_EDGE", "ONTOLOGY_INHERITANCE_CYCLE", "ONTOLOGY_INVALID_CARDINALITY", "ONTOLOGY_OWNER_REQUIRED", "ONTOLOGY_REQUIRED_PROPERTY_UNMAPPED", }