From c9708ae6446b8f76d0876216c28a6b1da72b8284 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sun, 20 Apr 2025 12:32:08 +0200 Subject: [PATCH] fix: expected responses in invalid batch operations - also remove duplicate "Check RL Response Body Containing ProblemDetails Element Containing..." checks --- .../VerifyLdContextNotAvailable/043_01.robot | 8 +++--- .../CreateBatchOfEntities/003_03.robot | 4 +-- .../CreateBatchOfEntities/003_06.robot | 5 ++-- .../CreateBatchOfEntities/003_08.robot | 5 ++-- .../DeleteBatchOfEntities/006_03.robot | 4 +-- .../MergeBatchOfEntities/057_03.robot | 26 +++++++++++------- .../UpdateBatchOfEntities/005_04.robot | 26 +++++++++++------- .../UpsertBatchOfEntities/004_06.robot | 26 +++++++++++------- .../Entities/CreateEntity/001_02.robot | 4 +-- .../CreateSubscription/028_02.robot | 4 +-- doc/analysis/checks.py | 27 ------------------- resources/AssertionUtils.resource | 11 -------- 12 files changed, 70 insertions(+), 80 deletions(-) diff --git a/TP/NGSI-LD/CommonBehaviours/CommonResponses/VerifyLdContextNotAvailable/043_01.robot b/TP/NGSI-LD/CommonBehaviours/CommonResponses/VerifyLdContextNotAvailable/043_01.robot index 440a06171..c31238d5d 100644 --- a/TP/NGSI-LD/CommonBehaviours/CommonResponses/VerifyLdContextNotAvailable/043_01.robot +++ b/TP/NGSI-LD/CommonBehaviours/CommonResponses/VerifyLdContextNotAvailable/043_01.robot @@ -74,15 +74,17 @@ ${registration_filename}= csourceRegistrations/context-source-registration @{entities_to_be_created}= Create List ${first_entity} ${second_entity} @{entities_ids_to_be_created}= Create List ${first_entity_id} ${second_entity_id} ${response}= Batch Create Entities @{entities_to_be_created} content_type=${CONTENT_TYPE_LD_JSON} - Check Response Status Code ${expected_status_code} ${response.status_code} + Check Response Status Code 207 ${response.status_code} Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()['errors'][0]['error']} ... ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE} Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()['errors'][1]['error']} ... ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE} - Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()['errors'][0]['error']} - Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()['errors'][1]['error']} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][1]['error']} [Teardown] Batch Delete Entities entities_ids_to_be_deleted=@{entities_ids_to_be_created} 043_01_05 Create context source registration diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot index 749cfeecc..f1f5d8777 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_03.robot @@ -22,7 +22,7 @@ Create Batch Entity With Invalid Request Scenarios [Arguments] ${filename} ${problem_type} ${response}= Batch Request Entities From File create filename=${filename} Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to + Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()} ... ${problem_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot index b8d7724e9..01f9b6b20 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_06.robot @@ -20,8 +20,9 @@ ${building_id_prefix}= urn:ngsi-ld:Building: ${response}= Batch Create Entities @{entities_to_be_created} content_type=${CONTENT_TYPE_JSON} - Check Response Status Code 400 ${response.status_code} + Check Response Status Code 207 ${response.status_code} Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()['errors'][0]['error']} ... ${ERROR_TYPE_BAD_REQUEST_DATA} - Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()['errors'][0]['error']} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot index 096001921..dd61c8733 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/CreateBatchOfEntities/003_08.robot @@ -20,8 +20,9 @@ ${building_id_prefix}= urn:ngsi-ld:Building: ${response}= Batch Create Entities @{entities_to_be_created} content_type=${CONTENT_TYPE_LD_JSON} - Check Response Status Code 400 ${response.status_code} + Check Response Status Code 207 ${response.status_code} Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()['errors'][0]['error']} ... ${ERROR_TYPE_BAD_REQUEST_DATA} - Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()['errors'][0]['error']} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot index ff22f729a..19119f069 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/DeleteBatchOfEntities/006_03.robot @@ -22,7 +22,7 @@ Batch Delete Entity With Invalid Request Scenarios [Arguments] ${filename} ${problem_type} ${response}= Batch Request Entities From File delete filename=${filename} Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to + Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()} ... ${problem_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/MergeBatchOfEntities/057_03.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/MergeBatchOfEntities/057_03.robot index cc968040e..c710de27c 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/MergeBatchOfEntities/057_03.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/MergeBatchOfEntities/057_03.robot @@ -7,20 +7,28 @@ Resource ${EXECDIR}/resources/AssertionUtils.resource Test Template Batch Merge Entity With Invalid Request Scenarios -*** Test Cases *** FILENAME PROBLEM_TYPE +*** Test Cases *** FILENAME PROBLEM_TYPE EXPECTED_STATUS_CODE 057_03_01 InvalidJson [Tags] be-merge 5_6_17 since_v1.6.1 - batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} + batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} 400 057_03_02 InvalidJsonLd [Tags] be-merge 5_6_17 since_v1.6.1 - batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} + batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} 207 *** Keywords *** Batch Merge Entity With Invalid Request Scenarios [Documentation] Check that you cannot merge a batch of entities with an invalid request - [Arguments] ${filename} ${problem_type} + [Arguments] ${filename} ${problem_type} ${expected_status_code} ${response}= Batch Request Entities From File merge filename=${filename} - Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to - ... ${response.json()} - ... ${problem_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Status Code ${expected_status_code} ${response.status_code} + IF '${expected_status_code}'=='400' + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + ELSE + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()['errors'][0]['error']} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} + END diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot index dda91ad56..d37bed155 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpdateBatchOfEntities/005_04.robot @@ -7,22 +7,30 @@ Resource ${EXECDIR}/resources/AssertionUtils.resource Test Template Batch Update Entity With Invalid Request Scenarios -*** Test Cases *** FILENAME PROBLEM_TYPE +*** Test Cases *** FILENAME PROBLEM_TYPE EXPECTED_STATUS_CODE 005_04_01 InvalidJson [Tags] be-update 5_6_9 - batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} + batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} 400 005_04_02 InvalidJsonLd [Tags] be-update 5_6_9 - batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} + batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} 207 *** Keywords *** Batch Update Entity With Invalid Request Scenarios [Documentation] Check that one cannot update a batch of entities with an invalid request - [Arguments] ${filename} ${problem_type} + [Arguments] ${filename} ${problem_type} ${expected_status_code} ${response}= Batch Request Entities From File update filename=${filename} - Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to - ... ${response.json()} - ... ${problem_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Status Code ${expected_status_code} ${response.status_code} + IF '${expected_status_code}'=='400' + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + ELSE + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()['errors'][0]['error']} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} + END diff --git a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot index 62116acbd..19603ad2c 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/BatchEntities/UpsertBatchOfEntities/004_06.robot @@ -7,22 +7,30 @@ Resource ${EXECDIR}/resources/AssertionUtils.resource Test Template Batch Upsert Entity With Invalid Request Scenarios -*** Test Cases *** FILENAME PROBLEM_TYPE +*** Test Cases *** FILENAME PROBLEM_TYPE EXPECTED_STATUS_CODE 004_06_01 InvalidJson [Tags] be-upsert 5_6_8 - batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} + batch/invalid-json.jsonld ${ERROR_TYPE_INVALID_REQUEST} 400 004_06_02 InvalidJsonLd [Tags] be-upsert 5_6_8 - batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} + batch/invalid-json-ld.jsonld ${ERROR_TYPE_BAD_REQUEST_DATA} 207 *** Keywords *** Batch Upsert Entity With Invalid Request Scenarios [Documentation] Check that one cannot upsert a batch of entities with an invalid request - [Arguments] ${filename} ${problem_type} + [Arguments] ${filename} ${problem_type} ${expected_status_code} ${response}= Batch Request Entities From File upsert filename=${filename} - Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to - ... ${response.json()['errors'][0]['error']} - ... ${problem_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()['errors'][0]['error']} + Check Response Status Code ${expected_status_code} ${response.status_code} + IF '${expected_status_code}'=='400' + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + ELSE + Check Response Body Containing ProblemDetails Element Containing Type Element set to + ... ${response.json()['errors'][0]['error']} + ... ${problem_type} + Check Response Body Containing ProblemDetails Element Containing Title Element + ... ${response.json()['errors'][0]['error']} + END diff --git a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_02.robot b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_02.robot index 2878b9a11..5602f3749 100644 --- a/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_02.robot +++ b/TP/NGSI-LD/ContextInformation/Provision/Entities/CreateEntity/001_02.robot @@ -25,7 +25,7 @@ Create Entity With Invalid Request Scenarios [Arguments] ${filename} ${error_type} ${response}= Create Entity From File ${filename} Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to + Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()} ... ${error_type} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_02.robot b/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_02.robot index f4dc443ed..57c3865fe 100644 --- a/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_02.robot +++ b/TP/NGSI-LD/ContextInformation/Subscription/CreateSubscription/028_02.robot @@ -21,7 +21,7 @@ Create Subscription With Invalid Request [Arguments] ${filename} ${expected_status} ${response}= Create Subscription From File ${filename} Check Response Status Code 400 ${response.status_code} - Check RL Response Body Containing ProblemDetails Element Containing Type Element set to + Check Response Body Containing ProblemDetails Element Containing Type Element set to ... ${response.json()} ... ${expected_status} - Check RL Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response.json()} diff --git a/doc/analysis/checks.py b/doc/analysis/checks.py index e91aa77e8..e197cbc6a 100644 --- a/doc/analysis/checks.py +++ b/doc/analysis/checks.py @@ -70,10 +70,6 @@ class Checks: Checks.check_response_body_might_contain_optional_fields, 'Check Response Body Containing ProblemDetails Element': Checks.check_response_body_containing_problemdetails_element, - 'Check RL Response Body Containing ProblemDetails Element Containing Type Element set to': - Checks.check_rl_response_body_containing_problemdetails_element_containing_type_element_set_to, - 'Check RL Response Body Containing ProblemDetails Element Containing Title Element': - Checks.check_rl_response_body_containing_problemdetails_element_containing_title_element, 'Check JSON Value In Response Body': Checks.check_json_value_in_response_body, 'Check Pagination Prev And Next Headers': @@ -235,10 +231,6 @@ class Checks: 'params': ['filename', 'entity_ids'], 'position': [0, 1] }, - 'Check RL Response Body Containing ProblemDetails Element Containing Title Element': { - 'params': ['response_body'], - 'position': [0] - }, 'Check Response Body Containing a Boolean Attribute set to': { 'params': ['expected_attribute_name', 'response_body', 'expected_attribute_value'], 'position': [0, 1, 2] @@ -279,10 +271,6 @@ class Checks: 'params': ['expected_resources', 'response_body', 'ignored_keys'], 'position': [] }, - 'Check RL Response Body Containing ProblemDetails Element Containing Type Element set to': { - 'params': ['type'], - 'position': [1] - }, 'Check JSON Value In Response Body': { 'params': ['key', 'value'], 'position': [0, 1] @@ -936,18 +924,6 @@ class Checks: def check_response_body_containing_problemdetails_element_containing_title_element(kwargs: list) -> str: return "Response body containing 'title' element" - @staticmethod - def check_rl_response_body_containing_problemdetails_element_containing_type_element_set_to(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_rl_response_body_containing_problemdetails_element_containing_title_element(kwargs: list) -> str: - return "Response body containing 'title' element" - @staticmethod def check_json_value_in_response_body(kwargs: list) -> str: if 'key' in kwargs and 'value' in kwargs: @@ -1274,9 +1250,6 @@ if __name__ == "__main__": 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 RL 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 RL Response Body Containing ProblemDetails Element Containing Title Element')) print(data.get_checks(checks='Check JSON Value In Response Body', key="['information']['entities'][0]['type']", value="Building")) diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 70b84d919..c58e70722 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -404,17 +404,6 @@ Check Response Kind set to [Arguments] ${response} ${kind} Should Be Equal ${response['kind']} ${kind} -Check RL Response Body Containing ProblemDetails Element Containing Type Element set to - [Arguments] ${response_body} ${type} - ${json_response_body}= Set Variable ${response_body} - - Should Be Equal ${json_response_body['type']} ${type} - -Check RL Response Body Containing ProblemDetails Element Containing Title Element - [Arguments] ${response_body} - ${json_response_body}= Set Variable ${response_body} - Should Not Be Empty ${json_response_body['title']} - Check JSON Value In Response Body [Arguments] ${json_path_expr} ${value_to_check} ${response_body} Should Be Equal As Strings ${response_body${json_path_expr}} ${value_to_check} -- GitLab