From bef60190b38157f74844ecd84a4898201e45b39b Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 11 Oct 2025 13:13:26 +0200 Subject: [PATCH] chore: cleanup checks methods - remove unused checks - remove some duplicated checks --- .../AppendEntityAttributes/010_05.robot | 6 +- .../UpdateEntityAttributes/011_04.robot | 6 +- .../007_02.robot | 6 +- .../AddAttributes/014_04.robot | 6 +- .../RegisterContextSource/033_02.robot | 6 +- .../034_04.robot | 6 +- doc/analysis/checks.py | 84 ------------------- resources/AssertionUtils.resource | 68 --------------- 8 files changed, 24 insertions(+), 164 deletions(-) diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_05.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_05.robot index 4458ef81..342aaad8 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_05.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/AppendEntityAttributes/010_05.robot @@ -26,8 +26,10 @@ ${invalid_fragment_filename}= invalid-fragment.jsonld ... ${invalid_fragment_filename} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code ${status_code} ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_INVALID_REQUEST} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_INVALID_REQUEST} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} *** Keywords *** diff --git a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/UpdateEntityAttributes/011_04.robot b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/UpdateEntityAttributes/011_04.robot index e304b66c..a51ab1ba 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/UpdateEntityAttributes/011_04.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/EntityAttributes/UpdateEntityAttributes/011_04.robot @@ -29,8 +29,10 @@ Update entity attributes with invalid entity fragments ... ${fragment_filename} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 400 ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_INVALID_REQUEST} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_INVALID_REQUEST} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} [Teardown] Delete Entity by Id ${entity_id} Initialize Environment diff --git a/TP/NGSI-LD/ContextInformation/Provision/TemporalEntity/CreateTemporalRepresentationOfEntity/007_02.robot b/TP/NGSI-LD/ContextInformation/Provision/TemporalEntity/CreateTemporalRepresentationOfEntity/007_02.robot index 11ba17fe..d41580d9 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/TemporalEntity/CreateTemporalRepresentationOfEntity/007_02.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/TemporalEntity/CreateTemporalRepresentationOfEntity/007_02.robot @@ -28,5 +28,7 @@ Create Temporal Entity From File ... ${filename} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code 400 ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_INVALID_REQUEST} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_INVALID_REQUEST} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextInformation/Provision/TemporalEntityAttributes/AddAttributes/014_04.robot b/TP/NGSI-LD/ContextInformation/Provision/TemporalEntityAttributes/AddAttributes/014_04.robot index 7374e109..64d8b8d2 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/TemporalEntityAttributes/AddAttributes/014_04.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/TemporalEntityAttributes/AddAttributes/014_04.robot @@ -34,8 +34,10 @@ Add an Attribute To a Temporal Entity From File ... ${update_filename} ... ${CONTENT_TYPE_LD_JSON} Check Response Status Code ${status_code} ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_INVALID_REQUEST} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_INVALID_REQUEST} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} Initialize Test Case ${temporal_entity_representation_id}= Generate Random Vehicle Entity Id diff --git a/TP/NGSI-LD/ContextSource/Registration/RegisterContextSource/033_02.robot b/TP/NGSI-LD/ContextSource/Registration/RegisterContextSource/033_02.robot index 717262af..4220ee5b 100644 --- a/TP/NGSI-LD/ContextSource/Registration/RegisterContextSource/033_02.robot +++ b/TP/NGSI-LD/ContextSource/Registration/RegisterContextSource/033_02.robot @@ -19,5 +19,7 @@ ${registration_payload_file_path}= csourceRegistrations/context-source-regi ${response}= Create Context Source Registration ... ${csr_payload} Check Response Status Code 400 ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_BAD_REQUEST_DATA} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_BAD_REQUEST_DATA} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/034_04.robot b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/034_04.robot index aa847364..b6c4be8f 100644 --- a/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/034_04.robot +++ b/TP/NGSI-LD/ContextSource/Registration/UpdateContextSourceRegistration/034_04.robot @@ -23,8 +23,10 @@ ${registration_payload_file_path}= context-source-registration-invalid-json ... ${registration_id} ... ${registration_payload_file_path} Check Response Status Code 400 ${response.status_code} - Check Response Body Type When Using Session Request ${response.json()} ${ERROR_TYPE_BAD_REQUEST_DATA} - Check Response Body Title When Using Session Request ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${ERROR_TYPE_BAD_REQUEST_DATA} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} *** Keywords *** diff --git a/doc/analysis/checks.py b/doc/analysis/checks.py index bc2682e5..241b3afc 100644 --- a/doc/analysis/checks.py +++ b/doc/analysis/checks.py @@ -52,12 +52,8 @@ class Checks: Checks.check_response_body_containing_attribute_element, 'Check Response Body Containing List Containing Context Source Registrations elements': Checks.check_response_body_containing_list_containing_context_source_registrations_elements, - 'Check Response Body Type When Using Session Request': - Checks.check_response_body_type_when_using_session_request, 'Check Response Body Containing ProblemDetails Element Containing Type Element set to': Checks.check_response_body_containing_problemdetails_element_containing_type_element_set_to, - 'Check Response Body Title When Using Session Request': - Checks.check_response_body_title_when_using_session_request, 'Check Response Body Containing a Boolean Attribute set to': Checks.check_response_body_containing_a_boolean_attribute_set_to, 'Check Response Body Contains DateTime Value': @@ -106,8 +102,6 @@ class Checks: Checks.should_be_true, 'Check Response Body Content': Checks.check_response_body_content, - 'Check Retrieving Context Source Registration': - Checks.check_retrieving_context_source_registration, 'Check JSON Value Not In Response Body': Checks.check_json_value_not_in_response_body, 'Check Response Reason set to': @@ -116,8 +110,6 @@ class Checks: Checks.check_response_does_not_contain_body, 'Check Context Response Body Containing a list of identifiers': Checks.check_context_response_body_containing_a_list_of_identifiers, - 'Check Context Response Body Containing a JSONObject with details of the @contexts': - Checks.check_context_response_body_containing_a_jsonobject_with_details_of_the_contexts, 'Check Context Response Body Content': Checks.check_context_response_body_content, 'Check Context Response Body Containing Detailed Information': @@ -130,8 +122,6 @@ class Checks: Checks.check_response_kind_set_to, 'Check Cached @Contexts': Checks.check_cached_contexts, - 'Check Response Header is Empty': - Checks.check_response_header_is_empty, 'Check Response Headers Link set to': Checks.check_response_headers_link_set_to, 'Check Response Headers Containing NGSILD-Results-Count Equals To' : @@ -197,10 +187,6 @@ class Checks: 'params': ['expected_entity_id', 'response_headers'], 'position': [0, 1] }, - 'Check Response Body Title When Using Session Request': { - 'params': ['response_body'], - 'position': [0] - }, 'Check Response Body Containing EntityTypeInfo element': { 'params': ['expectation_filename', 'response_body'], 'position': [0, 1] @@ -261,10 +247,6 @@ class Checks: 'params': ['filename', 'response'], 'position': [0, 1] }, - 'Check Response Body Type When Using Session Request': { - 'params': ['type'], - 'position': [1] - }, 'Check Created Resource Set To': { 'params': ['created_resource', 'response_body', 'ignored_keys'], 'position': [] @@ -347,10 +329,6 @@ class Checks: 'params': ['expression'], 'position': [0] }, - 'Check Retrieving Context Source Registration': { - 'params': ['registration_id', 'context', 'accept', 'registration_payload'], - 'position': [0, 1, 2, 3] - }, 'Check JSON Value Not In Response Body': { 'params': ['json_path_expr'], 'position': [0] @@ -367,10 +345,6 @@ class Checks: 'params': ['response_body', 'expected_length', 'list_contexts', 'kind'], 'position': [] }, - 'Check Context Response Body Containing a JSONObject with details of the @contexts': { - 'params': ['response', 'expected_length', 'list_contexts'], - 'position': [0, 1, 2] - }, 'Check Context Response Body Content': { 'params': ['expectation_filename', 'response_body'], 'position': [0, 1] @@ -395,10 +369,6 @@ class Checks: 'params': ['context'], 'position': [0] }, - 'Check Response Header is Empty': { - 'params': ['response_headers'], - 'position': [0] - }, 'Check Response Headers Link set to': { 'params': ['response_headers', 'expected_link_header'], 'position': [0, 1] @@ -493,10 +463,6 @@ class Checks: return response - @staticmethod - def check_response_header_is_empty(kwargs: list) -> str: - return "The response header contains an empty dictionary" - @staticmethod def check_response_headers_link_set_to(kwargs: list) -> str: return f"The response headers Link is set to '{kwargs['expected_link_header']}'" @@ -672,17 +638,6 @@ class Checks: return response - @staticmethod - def check_context_response_body_containing_a_jsonobject_with_details_of_the_contexts(kwargs: list) -> str: - if 'response' in kwargs and 'expected_length' in kwargs and 'list_contexts' in kwargs: - return (f"Response Body containing a Context element containing JSONObject with details of the contexts:\n" - f" * the expected length of contexts set to '{kwargs['expected_length']}'\n" - f" * the list of contexts URI set to '{kwargs['list_contexts']}'\n" - f" * response body to be checked set to '{kwargs['response']}'") - else: - raise Exception(f"ERROR, expected 'filename', 'temporal_entity_representation_id', and 'response_body' " - f"attributes, received: '{kwargs}'") - @staticmethod def check_context_detailed_information_keys(kwargs: list) -> str: return (f"Check that the only allowed keys in the response body of a @context are 'URL', 'localId', 'kind', " @@ -759,30 +714,6 @@ class Checks: return response - @staticmethod - def check_retrieving_context_source_registration(kwargs: list) -> str: - expected_parameters = ['registration_id', 'context', 'accept', 'registration_payload'] - - result = [x for x in kwargs if x not in expected_parameters] - response = "Check Retrieving Context Source Registration" - for key, value in kwargs.items(): - match key: - case 'registration_id': - response = f"{response} and\n Query Parameter: registration_id set to '{value}'" - case 'context': - response = f"{response} and\n Query Parameter: context set to '{value}'" - case 'accept': - response = f"{response} and\n Query Parameter: accept set to '{value}'" - case 'registration_payload': - response = f"{response} and\n Query Parameter: registration_payload set to '{value}'" - case 'checks': - pass - case _: - raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are " - f"'{expected_parameters}', but received: {kwargs}") - - return response - @staticmethod def check_response_body_containing_entitytemporal_element(kwargs: list) -> str: if 'filename' in kwargs and 'temporal_entity_representation_id' in kwargs and 'response_body' in kwargs: @@ -895,14 +826,6 @@ class Checks: def check_response_body_containing_list_containing_context_source_registrations_elements(kwargs: list) -> str: return 'Response body set to list of all matching Context Source Registrations resolved against the default JSON-LD context' - @staticmethod - def check_response_body_type_when_using_session_request(kwargs: list) -> str: - if 'type' in kwargs: - type = kwargs['type'] - return f"Response Body containing the type '{type}'" - else: - raise Exception(f"ERROR, expected type attribute, but received: {kwargs}") - @staticmethod def check_response_body_containing_problemdetails_element_containing_type_element_set_to(kwargs: list) -> str: if 'type' in kwargs: @@ -922,10 +845,6 @@ class Checks: else: raise Exception(f"ERROR, expected type attribute, but received: {kwargs}") - @staticmethod - def check_response_body_title_when_using_session_request(kwargs: list) -> str: - return "Response body containing 'title' element" - @staticmethod def check_response_body_containing_problemdetails_element_containing_title_element(kwargs: list) -> str: return "Response body containing 'title' element" @@ -1257,11 +1176,8 @@ if __name__ == "__main__": print(data.get_checks(checks='Check Response Body Containing AttributeList element')) print(data.get_checks(checks='Check Response Body Containing Attribute element')) print(data.get_checks(checks='Check Response Body Containing List Containing Context Source Registrations elements')) - print(data.get_checks(checks='Check Response Body Type When Using Session Request', - type='https://uri.etsi.org/ngsi-ld/errors/BadRequestData')) print(data.get_checks(checks='Check Response Body Containing ProblemDetails Element Containing Type Element set to', type='https://uri.etsi.org/ngsi-ld/errors/BadRequestData')) - print(data.get_checks(checks='Check Response Body Title When Using Session Request')) print(data.get_checks(checks='Check Response Body Containing ProblemDetails Element Containing Title Element')) print(data.get_checks(checks='Check JSON Value In Response Body', key="['information']['entities'][0]['type']", diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 7f791b38..b5fcb012 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -5,7 +5,6 @@ Library RequestsLibrary Library Collections Library JSONLibrary Library String -Resource ${EXECDIR}/resources/ApiUtils/ContextSourceDiscovery.resource Resource ${EXECDIR}/resources/ApiUtils/jsonldContext.resource @@ -69,10 +68,6 @@ Check Response Headers Containing Content-Type set to [Arguments] ${expected_content_type_content} ${response_headers} Should Be Equal ${response_headers['Content-Type']} ${expected_content_type_content} -Check Response Header is Empty - [Arguments] ${response_headers} - Dictionaries Should Be Equal ${response_headers} {} - Check Response Headers Link Not Empty [Arguments] ${response_headers} Should Not Be Empty ${response_headers['Link']} @@ -404,18 +399,10 @@ Check Response Body Containing List Containing Context Source Registrations elem ... group_by=id Should Be Empty ${comparison_result} msg=${comparison_result.pretty()} -Check Response Body Type When Using Session Request - [Arguments] ${response_body} ${type} - Should Be Equal ${response_body['type']} ${type} - Check Response Body Containing ProblemDetails Element Containing Type Element set to [Arguments] ${response_body} ${type} Should Be Equal ${response_body['type']} ${type} -Check Response Body Title When Using Session Request - [Arguments] ${response_body} - Should Not Be Empty ${response_body['title']} - Check Response Body Containing ProblemDetails Element Containing Title Element [Arguments] ${response_body} Should Not Be Empty ${response_body['title']} @@ -530,15 +517,6 @@ Check SUT Not Containing Resources [Arguments] ${response_body} Should Be Empty ${response_body} -Check Retrieving Context Source Registration - [Arguments] ${registration_id} ${context} ${accept} ${registration_payload} - ${response}= Retrieve Context Source Registration - ... context_source_registration_id=${registration_id} - ... context=${context} - ... accept=${accept} - ${ignored_attributes}= Create List ${status_regex_expr} @context - Check Updated Resource Set To ${registration_payload} ${response.json()} ${ignored_attributes} - Check Response Body Might Contain Additional Members of the NotificationParams # Check the Additional Members 5.2.14.2 in the NotificationParams data structure [Arguments] ${dictionary} ${key} @@ -719,23 +697,6 @@ Check Context Response Body Containing a list of identifiers Should Be True ${found} END -Check Context Response Body Containing a list with several URLs - [Arguments] ${response_body} ${expected_length} ${list_contexts} - - Length Should Be - ... ${response_body} - ... ${expected_length} - ... msg=The length of the strings array of @contexts is not ${expected_length} - - Should Be Equal ${response_body[0]} ${core_context} - - FOR ${index} ${uri_context} IN ENUMERATE @{list_contexts} - Log URI: ${uri_context} index: ${index} - ${index}= Evaluate ${index} + 1 - - Should Be Equal ${response_body[${index}]} ${uri_context} - END - Check Cached @Contexts [Arguments] ${filename} @@ -773,35 +734,6 @@ Check Context Detailed Information Keys ... ${actual_keys} ... msg=The @context detailed information contains keys not expected: ${actual_keys} -Check Context Response Body Containing a JSONObject with details of the @contexts - [Arguments] ${response} ${expected_length} ${list_contexts} - - ${obtained_length}= Get Length ${response} - Length Should Be - ... ${response} - ... ${expected_length} - ... msg=The expected number of @contexts was ${expected_length} but we have obtained ${obtained_length} - - FOR ${index} ${item} IN ENUMERATE @{response} - ${URL}= Get From Dictionary ${item} URL - IF '${URL}'=='${core_context}' - ${context_kind}= Set Variable Cached - ELSE - ${context_kind}= Set Variable Hosted - END - - # Check mandatory keys in the response (URL, localId, kind, timestamp) and their possible values - Check Context Response Body Containing Detailed Information ${item} ${context_kind} - - # Check optional keys in the response (lastUsage, numberOfHits, extraInfo) and their possible values - Check Response Body Might Contain Optional Fields ${response}[0] lastUsage - Check Response Body Might Contain Optional Fields ${response}[0] numberOfHits - Check Response Body Might Contain Optional Fields ${response}[0] extraInfo - - # Check that there is no other keys - Check Context Detailed Information Keys ${item} - END - Check Context Response Body Containing a JSONObject with details of a ImplicitlyCreated @contexts [Arguments] ${response} ${expected_length} -- GitLab