diff --git a/pyegeria/models/__init__.py b/pyegeria/models/__init__.py index 322cdcb5..3c685623 100644 --- a/pyegeria/models/__init__.py +++ b/pyegeria/models/__init__.py @@ -76,6 +76,9 @@ DesignPatternProperties, AuthoredReferenceableProperties, SolutionBlueprintProperties, + StatementOfApplicabilityProperties, + ControlApplicabilityProperties, + ControlImplementationStatus, NestedDesignPatternProperties, SpecializedDesignPatternProperties, RelatedDesignPatternProperties, @@ -170,6 +173,9 @@ "DesignPatternProperties", "AuthoredReferenceableProperties", "SolutionBlueprintProperties", + "StatementOfApplicabilityProperties", + "ControlApplicabilityProperties", + "ControlImplementationStatus", "NestedDesignPatternProperties", "SpecializedDesignPatternProperties", "RelatedDesignPatternProperties", diff --git a/pyegeria/models/models.py b/pyegeria/models/models.py index d7ca9bd0..38cc8678 100644 --- a/pyegeria/models/models.py +++ b/pyegeria/models/models.py @@ -53,6 +53,15 @@ class DeleteMethod(StrEnum): PURGE = "PURGE" +class ControlImplementationStatus(StrEnum): + """How far a control assessed in a statement of applicability has been implemented.""" + NOT_STARTED = "NOT_STARTED" + PLANNED = "PLANNED" + PARTIALLY_IMPLEMENTED = "PARTIALLY_IMPLEMENTED" + IMPLEMENTED = "IMPLEMENTED" + OTHER = "OTHER" + + # Define the camelCase conversion function def to_camel_case(snake_str: str) -> str: @@ -208,6 +217,27 @@ class SolutionBlueprintProperties(AuthoredReferenceableProperties): class_: Annotated[Literal["SolutionBlueprintProperties"], Field(alias="class")] +class StatementOfApplicabilityProperties(AuthoredReferenceableProperties): + class_: Annotated[Literal["StatementOfApplicabilityProperties"], Field(alias="class")] + scope: str | None = None + review_date: datetime | None = None + + +class ControlApplicabilityProperties(PyegeriaModel): + class_: Annotated[Literal["ControlApplicabilityProperties"], Field(alias="class")] + # Egeria treats a control as applicable unless this is false. + is_applicable: bool | None = None + justification: str | None = None + inclusion_reasons: list[str] | None = None + implementation_status: ControlImplementationStatus | None = None + implementation_description: str | None = None + review_date: datetime | None = None + label: str | None = None + description: str | None = None + effective_from: datetime | None = None + effective_to: datetime | None = None + + class NestedDesignPatternProperties(PyegeriaModel): class_: Annotated[Literal["NestedDesignPatternProperties"], Field(alias="class")] label: str | None = None diff --git a/pyegeria/omvs/data_discovery.py b/pyegeria/omvs/data_discovery.py index 13c4005d..ceda2e54 100644 --- a/pyegeria/omvs/data_discovery.py +++ b/pyegeria/omvs/data_discovery.py @@ -809,7 +809,7 @@ def detach_annotation_match( @dynamic_catch async def _async_delete_annotation( - self, annotation_guid: str, body: dict | DeleteElementRequestBody + self, annotation_guid: str, body: Optional[dict | DeleteElementRequestBody] = None ) -> None: """Delete an annotation. Async version. @@ -817,7 +817,7 @@ async def _async_delete_annotation( ---------- annotation_guid : str The unique identifier of the annotation. - body : dict | DeleteElementRequestBody + body : dict | DeleteElementRequestBody, optional The request body for the delete operation. Returns @@ -842,14 +842,14 @@ async def _async_delete_annotation( url = f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/data-discovery/annotations/{annotation_guid}/delete" await self._async_delete_element_request(url, body) - def delete_annotation(self, annotation_guid: str, body: dict | DeleteElementRequestBody) -> None: + def delete_annotation(self, annotation_guid: str, body: Optional[dict | DeleteElementRequestBody] = None) -> None: """Delete an annotation. Parameters ---------- annotation_guid : str The unique identifier of the annotation. - body : dict | DeleteElementRequestBody + body : dict | DeleteElementRequestBody, optional The request body for the delete operation. Returns diff --git a/pyegeria/omvs/security_officer.py b/pyegeria/omvs/security_officer.py index 80d8c847..441d5180 100644 --- a/pyegeria/omvs/security_officer.py +++ b/pyegeria/omvs/security_officer.py @@ -15,6 +15,12 @@ from pyegeria.core._exceptions import PyegeriaNotFoundException from pyegeria.models import ( UserAccountRequestBody, + NewElementRequestBody, + TemplateRequestBody, + UpdateElementRequestBody, + DeleteElementRequestBody, + FilterRequestBody, + GetRequestBody, NewRelationshipRequestBody, DeleteRelationshipRequestBody, NewClassificationRequestBody, @@ -781,3 +787,381 @@ def clear_zone_membership_profile(self, governance_zone_guid: str, loop = asyncio.get_event_loop() loop.run_until_complete(self._async_clear_zone_membership_profile(governance_zone_guid, body)) + # + # Statements of applicability - which controls from a standard (such as the + # Annex A controls of ISO/IEC 27001) apply to the organization, why, and how + # far each is implemented. Added in Egeria 6.3. + # + + @dynamic_catch + async def _async_create_statement_of_applicability(self, body: Optional[dict | NewElementRequestBody] = None) -> str: + """Create a statement of applicability. Async version. + + Parameters + ---------- + body : dict | NewElementRequestBody + Request body whose properties class is StatementOfApplicabilityProperties. + + Returns + ------- + str + The GUID of the new statement of applicability. + """ + url = f"{self.security_officer_base_url}/statements-of-applicability" + return await self._async_create_element_body_request(url, ["StatementOfApplicabilityProperties"], body) + + @dynamic_catch + def create_statement_of_applicability(self, body: Optional[dict | NewElementRequestBody] = None) -> str: + """Create a statement of applicability. + + Parameters + ---------- + body : dict | NewElementRequestBody + Request body whose properties class is StatementOfApplicabilityProperties. + + Returns + ------- + str + The GUID of the new statement of applicability. + """ + loop = asyncio.get_event_loop() + return loop.run_until_complete(self._async_create_statement_of_applicability(body)) + + @dynamic_catch + async def _async_create_statement_of_applicability_from_template(self, body: dict | TemplateRequestBody) -> str: + """Create a statement of applicability using an existing one as a template. Async version.""" + url = f"{self.security_officer_base_url}/statements-of-applicability/from-template" + return await self._async_create_element_from_template(url, body) + + @dynamic_catch + def create_statement_of_applicability_from_template(self, body: dict | TemplateRequestBody) -> str: + """Create a statement of applicability using an existing one as a template.""" + loop = asyncio.get_event_loop() + return loop.run_until_complete(self._async_create_statement_of_applicability_from_template(body)) + + @dynamic_catch + async def _async_update_statement_of_applicability(self, soa_guid: str, + body: dict | UpdateElementRequestBody) -> None: + """Update the properties of a statement of applicability - for example, to approve it. Async version.""" + url = f"{self.security_officer_base_url}/statements-of-applicability/{soa_guid}/update" + await self._async_update_element_body_request(url, ["StatementOfApplicabilityProperties"], body) + + @dynamic_catch + def update_statement_of_applicability(self, soa_guid: str, body: dict | UpdateElementRequestBody) -> None: + """Update the properties of a statement of applicability - for example, to approve it.""" + loop = asyncio.get_event_loop() + loop.run_until_complete(self._async_update_statement_of_applicability(soa_guid, body)) + + @dynamic_catch + async def _async_delete_statement_of_applicability(self, soa_guid: str, + body: Optional[dict | DeleteElementRequestBody] = None, + cascade: bool = False) -> None: + """Delete a statement of applicability. Async version.""" + url = f"{self.security_officer_base_url}/statements-of-applicability/{soa_guid}/delete" + await self._async_delete_element_request(url, body, cascade) + + @dynamic_catch + def delete_statement_of_applicability(self, soa_guid: str, body: Optional[dict | DeleteElementRequestBody] = None, + cascade: bool = False) -> None: + """Delete a statement of applicability.""" + loop = asyncio.get_event_loop() + loop.run_until_complete(self._async_delete_statement_of_applicability(soa_guid, body, cascade)) + + def _generate_statement_of_applicability_output( + self, + elements: dict | list[dict], + search_string: Optional[str] = None, + element_type_name: Optional[str] = None, + output_format: str = "JSON", + report_spec: dict | str | None = None, + **kwargs + ) -> Any: + return self._generate_formatted_output( + elements=elements, + query_string=search_string, + entity_type=element_type_name or "StatementOfApplicability", + output_format=output_format, + extract_properties_func=self._extract_referenceable_properties, + report_spec=report_spec, + **kwargs + ) + + @dynamic_catch + async def _async_get_statements_of_applicability_by_name( + self, + filter_string: str | None = None, + metadata_element_subtypes: list[str] | None = None, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + start_from: int = 0, + page_size: int = 0, + output_format: str = "JSON", + report_spec: str | dict | None = None, + body: Optional[dict | FilterRequestBody] = None, + **kwargs, + ) -> list | str: + """Return the statements of applicability with a particular name. Async version.""" + url = f"{self.security_officer_base_url}/statements-of-applicability/by-name" + return await self._async_get_name_request( + url, + _type="StatementOfApplicability", + _gen_output=self._generate_statement_of_applicability_output, + filter_string=filter_string, + metadata_element_subtypes=metadata_element_subtypes, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + start_from=start_from, + page_size=page_size, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + + @dynamic_catch + def get_statements_of_applicability_by_name( + self, + filter_string: str | None = None, + metadata_element_subtypes: list[str] | None = None, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + start_from: int = 0, + page_size: int = 0, + output_format: str = "JSON", + report_spec: str | dict | None = None, + body: Optional[dict | FilterRequestBody] = None, + **kwargs, + ) -> list | str: + """Return the statements of applicability with a particular name.""" + loop = asyncio.get_event_loop() + return loop.run_until_complete( + self._async_get_statements_of_applicability_by_name( + filter_string=filter_string, + metadata_element_subtypes=metadata_element_subtypes, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + start_from=start_from, + page_size=page_size, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + ) + + @dynamic_catch + async def _async_find_statements_of_applicability( + self, + search_string: str = "*", + starts_with: bool = True, + ends_with: bool = False, + ignore_case: bool = True, + metadata_element_type_name: str | None = None, + metadata_element_subtypes: list[str] | None = None, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + as_of_time: Optional[str] = None, + start_from: int = 0, + page_size: int = 100, + sequencing_order: Optional[str] = None, + sequencing_property: Optional[str] = None, + output_format: str = "JSON", + report_spec: Optional[str | dict] = None, + body: Optional[dict | SearchStringRequestBody] = None, + **kwargs, + ) -> list | str: + """Return the statements of applicability that contain the search string. Async version.""" + url = f"{self.security_officer_base_url}/statements-of-applicability/by-search-string" + return await self._async_find_request( + url, + _type="StatementOfApplicability", + _gen_output=self._generate_statement_of_applicability_output, + search_string=search_string, + starts_with=starts_with, + ends_with=ends_with, + ignore_case=ignore_case, + metadata_element_type=metadata_element_type_name, + metadata_element_subtypes=metadata_element_subtypes, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + as_of_time=as_of_time, + start_from=start_from, + page_size=page_size, + sequencing_order=sequencing_order, + sequencing_property=sequencing_property, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + + @dynamic_catch + def find_statements_of_applicability( + self, + search_string: str = "*", + starts_with: bool = True, + ends_with: bool = False, + ignore_case: bool = True, + metadata_element_type_name: str | None = None, + metadata_element_subtypes: list[str] | None = None, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + as_of_time: Optional[str] = None, + start_from: int = 0, + page_size: int = 100, + sequencing_order: Optional[str] = None, + sequencing_property: Optional[str] = None, + output_format: str = "JSON", + report_spec: Optional[str | dict] = None, + body: Optional[dict | SearchStringRequestBody] = None, + **kwargs, + ) -> list | str: + """Return the statements of applicability that contain the search string.""" + loop = asyncio.get_event_loop() + return loop.run_until_complete( + self._async_find_statements_of_applicability( + search_string=search_string, + starts_with=starts_with, + ends_with=ends_with, + ignore_case=ignore_case, + metadata_element_type_name=metadata_element_type_name, + metadata_element_subtypes=metadata_element_subtypes, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + as_of_time=as_of_time, + start_from=start_from, + page_size=page_size, + sequencing_order=sequencing_order, + sequencing_property=sequencing_property, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + ) + + @dynamic_catch + async def _async_get_statement_of_applicability_by_guid( + self, + soa_guid: str, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + output_format: str = "JSON", + report_spec: str | dict | None = None, + body: Optional[dict | GetRequestBody] = None, + **kwargs, + ) -> dict | str: + """Return a statement of applicability. Async version. + + Each linked control, with its ControlApplicability relationship properties, is returned in the + element's otherRelatedElements list. + """ + url = f"{self.security_officer_base_url}/statements-of-applicability/{soa_guid}/retrieve" + return await self._async_get_guid_request( + url, + _type="StatementOfApplicability", + _gen_output=self._generate_statement_of_applicability_output, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + + @dynamic_catch + def get_statement_of_applicability_by_guid( + self, + soa_guid: str, + include_only_relationships: list[str] | None = None, + skip_relationships: list[str] | None = None, + graph_query_depth: int = 3, + output_format: str = "JSON", + report_spec: str | dict | None = None, + body: Optional[dict | GetRequestBody] = None, + **kwargs, + ) -> dict | str: + """Return a statement of applicability. + + Each linked control, with its ControlApplicability relationship properties, is returned in the + element's otherRelatedElements list. + """ + loop = asyncio.get_event_loop() + return loop.run_until_complete( + self._async_get_statement_of_applicability_by_guid( + soa_guid=soa_guid, + include_only_relationships=include_only_relationships, + skip_relationships=skip_relationships, + graph_query_depth=graph_query_depth, + output_format=output_format, + report_spec=report_spec, + body=body, + **kwargs, + ) + ) + + @dynamic_catch + async def _async_link_control_applicability(self, soa_guid: str, control_guid: str, + body: Optional[dict | NewRelationshipRequestBody] = None) -> None: + """Link a control to a statement of applicability (ControlApplicability relationship). Async version. + + ControlApplicability is not multi-link: linking a control that is already linked updates the + properties of the existing relationship, so this is also how a control's applicability is updated. + + Parameters + ---------- + soa_guid : str + The statement of applicability. + control_guid : str + The governance definition (typically a GovernanceControl) being assessed. + body : dict | NewRelationshipRequestBody, optional + Request body whose properties class is ControlApplicabilityProperties. + """ + url = (f"{self.security_officer_base_url}/statements-of-applicability/{soa_guid}" + f"/control-applicability/{control_guid}/attach") + await self._async_new_relationship_request(url, ["ControlApplicabilityProperties"], body) + + @dynamic_catch + def link_control_applicability(self, soa_guid: str, control_guid: str, + body: Optional[dict | NewRelationshipRequestBody] = None) -> None: + """Link a control to a statement of applicability (ControlApplicability relationship). + + ControlApplicability is not multi-link: linking a control that is already linked updates the + properties of the existing relationship, so this is also how a control's applicability is updated. + + Parameters + ---------- + soa_guid : str + The statement of applicability. + control_guid : str + The governance definition (typically a GovernanceControl) being assessed. + body : dict | NewRelationshipRequestBody, optional + Request body whose properties class is ControlApplicabilityProperties. + """ + loop = asyncio.get_event_loop() + loop.run_until_complete(self._async_link_control_applicability(soa_guid, control_guid, body)) + + @dynamic_catch + async def _async_detach_control_applicability(self, soa_guid: str, control_guid: str, + body: Optional[dict | DeleteRelationshipRequestBody] = None) -> None: + """Remove a control from a statement of applicability. Async version.""" + url = (f"{self.security_officer_base_url}/statements-of-applicability/{soa_guid}" + f"/control-applicability/{control_guid}/detach") + await self._async_delete_relationship_request(url, body) + + @dynamic_catch + def detach_control_applicability(self, soa_guid: str, control_guid: str, + body: Optional[dict | DeleteRelationshipRequestBody] = None) -> None: + """Remove a control from a statement of applicability.""" + loop = asyncio.get_event_loop() + loop.run_until_complete(self._async_detach_control_applicability(soa_guid, control_guid, body)) diff --git a/tests/micro-tests/test_security_officer_soa.py b/tests/micro-tests/test_security_officer_soa.py new file mode 100644 index 00000000..b1fc34ba --- /dev/null +++ b/tests/micro-tests/test_security_officer_soa.py @@ -0,0 +1,218 @@ +""" +Statement of applicability methods on SecurityOfficer (Egeria 6.3), and the +delete_annotation body default on DataDiscovery. +No live server: the HTTP call is captured and the verb, URL and body asserted +against Egeria-api-security-officer.http and SecurityOfficerResource.java. +""" +import json + +import pytest +from pydantic import ValidationError + +from pyegeria.models import ControlApplicabilityProperties, ControlImplementationStatus +from pyegeria.omvs.data_discovery import DataDiscovery +from pyegeria.omvs.security_officer import SecurityOfficer + + +class _Response: + def __init__(self, payload): + self._payload = payload + + def json(self): + return self._payload + + +def _capture(client, calls: list, payload: dict | None = None): + async def fake_make_request(method, url, payload_body=None, *args, **kwargs): + calls.append({"method": method, "url": url, + "body": json.loads(payload_body) if isinstance(payload_body, str) else payload_body}) + return _Response(payload or {"class": "VoidResponse", "relatedHTTPCode": 200}) + + client._async_make_request = fake_make_request + return client + + +def _security_officer(calls, monkeypatch, payload=None): + monkeypatch.setattr(SecurityOfficer, "check_connection", lambda self: "test") + return _capture(SecurityOfficer("view-server", "https://localhost:1", "user", "pwd"), calls, payload) + + +ROOT = "/servers/view-server/api/open-metadata/security-officer/statements-of-applicability" + +SOA_PROPS = { + "class": "StatementOfApplicabilityProperties", + "qualifiedName": "StatementOfApplicability::Coco Pharmaceuticals ISMS", + "displayName": "Coco Pharmaceuticals ISMS", + "versionIdentifier": "1.0", + "scope": "Coco Pharmaceuticals ISMS", + "reviewDate": "2026-10-26T00:00:00Z", + "authors": ["Simon Burr"], + "contentStatus": "DRAFT", +} + +CA_PROPS = { + "class": "ControlApplicabilityProperties", + "isApplicable": True, + "justification": "Ransomware disruption to manufacturing", + "inclusionReasons": ["Risk Treatment"], + "implementationStatus": "PARTIALLY_IMPLEMENTED", + "implementationDescription": "Network segmentation in progress", + "reviewDate": "2026-10-26T00:00:00Z", + "label": "8.20", + "description": "Network security", +} + + +@pytest.mark.asyncio +async def test_create_statement_of_applicability(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch, {"class": "GUIDResponse", "guid": "soa-guid"}) + + guid = await client._async_create_statement_of_applicability( + {"class": "NewElementRequestBody", "isOwnAnchor": True, "properties": SOA_PROPS}) + + assert guid == "soa-guid" + assert calls[0]["method"] == "POST" + assert calls[0]["url"].endswith(ROOT) + assert calls[0]["body"]["class"] == "NewElementRequestBody" + # scope and reviewDate are new to this type: neither may be dropped on the way out + assert calls[0]["body"]["properties"] == SOA_PROPS + + +@pytest.mark.asyncio +async def test_create_statement_of_applicability_from_template(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch, {"class": "GUIDResponse", "guid": "soa-guid"}) + + guid = await client._async_create_statement_of_applicability_from_template( + {"class": "TemplateRequestBody", "templateGUID": "template-guid"}) + + assert guid == "soa-guid" + assert calls[0]["url"].endswith(f"{ROOT}/from-template") + assert calls[0]["body"]["class"] == "TemplateRequestBody" + assert calls[0]["body"]["templateGUID"] == "template-guid" + + +@pytest.mark.asyncio +async def test_update_statement_of_applicability(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch) + props = {"class": "StatementOfApplicabilityProperties", "contentStatus": "APPROVED", + "reviewDate": "2026-11-01T00:00:00Z"} + + await client._async_update_statement_of_applicability( + "soa-guid", {"class": "UpdateElementRequestBody", "mergeUpdate": True, "properties": props}) + + assert calls[0]["url"].endswith(f"{ROOT}/soa-guid/update") + assert calls[0]["body"]["class"] == "UpdateElementRequestBody" + assert calls[0]["body"]["properties"] == props + + +@pytest.mark.asyncio +async def test_delete_statement_of_applicability_without_body(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch) + + await client._async_delete_statement_of_applicability("soa-guid") + + assert calls[0]["method"] == "POST" + assert calls[0]["url"].endswith(f"{ROOT}/soa-guid/delete") + + +@pytest.mark.asyncio +async def test_get_statements_of_applicability_by_name(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch, {"class": "OpenMetadataRootElementsResponse", "elements": []}) + + await client._async_get_statements_of_applicability_by_name("Coco Pharmaceuticals ISMS") + + assert calls[0]["url"].endswith(f"{ROOT}/by-name") + assert calls[0]["body"]["class"] == "FilterRequestBody" + assert calls[0]["body"]["filter"] == "Coco Pharmaceuticals ISMS" + + +@pytest.mark.asyncio +async def test_find_statements_of_applicability(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch, {"class": "OpenMetadataRootElementsResponse", "elements": []}) + + await client._async_find_statements_of_applicability("ISMS") + + assert calls[0]["url"].endswith(f"{ROOT}/by-search-string") + assert calls[0]["body"]["class"] == "SearchStringRequestBody" + assert calls[0]["body"]["searchString"] == "ISMS" + + +@pytest.mark.asyncio +async def test_get_statement_of_applicability_by_guid(monkeypatch): + calls: list = [] + element = {"elementHeader": {"guid": "soa-guid", "type": {"typeName": "StatementOfApplicability"}}, + "properties": SOA_PROPS} + client = _security_officer(calls, monkeypatch, {"class": "OpenMetadataRootElementResponse", "element": element}) + + result = await client._async_get_statement_of_applicability_by_guid("soa-guid") + + assert calls[0]["url"].endswith(f"{ROOT}/soa-guid/retrieve") + assert calls[0]["body"]["class"] == "GetRequestBody" + assert result["properties"]["scope"] == SOA_PROPS["scope"] + + +@pytest.mark.asyncio +async def test_link_control_applicability(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch) + + await client._async_link_control_applicability( + "soa-guid", "control-guid", {"class": "NewRelationshipRequestBody", "properties": CA_PROPS}) + + assert calls[0]["method"] == "POST" + assert calls[0]["url"].endswith(f"{ROOT}/soa-guid/control-applicability/control-guid/attach") + assert calls[0]["body"]["class"] == "NewRelationshipRequestBody" + assert calls[0]["body"]["properties"] == CA_PROPS + + +@pytest.mark.asyncio +async def test_link_control_applicability_without_body_sends_properties_class(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch) + + await client._async_link_control_applicability("soa-guid", "control-guid") + + assert calls[0]["body"]["properties"]["class"] == "ControlApplicabilityProperties" + + +@pytest.mark.asyncio +async def test_detach_control_applicability(monkeypatch): + calls: list = [] + client = _security_officer(calls, monkeypatch) + + await client._async_detach_control_applicability( + "soa-guid", "control-guid", {"class": "DeleteRelationshipRequestBody", "externalSourceGUID": "src"}) + + assert calls[0]["url"].endswith(f"{ROOT}/soa-guid/control-applicability/control-guid/detach") + assert calls[0]["body"]["class"] == "DeleteRelationshipRequestBody" + + +def test_control_applicability_model_serializes_egeria_field_names(): + props = ControlApplicabilityProperties(**CA_PROPS) + + assert props.implementation_status == ControlImplementationStatus.PARTIALLY_IMPLEMENTED + dumped = json.loads(props.model_dump_json(by_alias=True, exclude_none=True)) + assert dumped == CA_PROPS + + +def test_control_applicability_model_rejects_unknown_implementation_status(): + with pytest.raises(ValidationError): + ControlApplicabilityProperties(**{**CA_PROPS, "implementationStatus": "DONE"}) + + +@pytest.mark.asyncio +async def test_delete_annotation_body_is_optional(monkeypatch): + calls: list = [] + monkeypatch.setattr(DataDiscovery, "check_connection", lambda self: "test") + client = _capture(DataDiscovery("view-server", "https://localhost:1", "user", "pwd"), calls) + + await client._async_delete_annotation("annotation-guid") + + assert calls[0]["method"] == "POST" + assert calls[0]["url"].endswith("/data-discovery/annotations/annotation-guid/delete")