From 79d4b27b7e1236340e9c379c1f477b8b2d5b9df4 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 3 Feb 2021 17:12:36 +0100 Subject: [PATCH 1/3] feat: add tps for retrieve context source registration subscription --- .../034_01.robot | 34 +++++++++++++++++++ .../034_02.robot | 16 +++++++++ .../034_03.robot | 16 +++++++++ resources/ApiUtils.resource | 6 ++-- resources/AssertionUtils.resource | 16 +++++++-- 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot create mode 100644 TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot create mode 100644 TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot new file mode 100644 index 00000000..065e4771 --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_01.robot @@ -0,0 +1,34 @@ +*** Settings *** +Documentation Check that you can retrieve a context source registration subscription +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +Suite Setup Setup Initial Context Source Registration Subscription +Suite Teardown Delete Created Context Source Registration Subscription + +*** Variable *** +${subscription_id_prefix}= urn:ngsi-ld:Subscription: +${subscription_payload_file_path}= csourceSubscriptions/subscription-sample.jsonld + +*** Test Case *** +Retrieve Context Source Registration Subscription + [Documentation] Check that you can retrieve a context source registration subscription + [Tags] mandatory + + Retrieve Context Source Registration Subscription ${subscription_id} context=${ngsild_test_suite_context} + + Check Response Status Code Set To 200 + Check Response Body Containing Subscription element ${subscription_payload_file_path} ${subscription_id} + +*** Keywords *** +Setup Initial Context Source Registration Subscription + ${subscription_id}= Generate Random Entity Id ${subscription_id_prefix} + ${subscription_payload}= Load Test Sample ${subscription_payload_file_path} ${subscription_id} + + Create Context Source Registration Subscription ${subscription_payload} + + Set Suite Variable ${subscription_id} + +Delete Created Context Source Registration Subscription + Delete Context Source Registration Subscription ${subscription_id} diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot new file mode 100644 index 00000000..f256820e --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_02.robot @@ -0,0 +1,16 @@ +*** Settings *** +Documentation Check that you cannot retrieve a context source registration subscription with an invalid URI, an error of type BadRequestData shall be raised +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Test Case *** +Retrieve Context Source Registration Subscription With An Invalid Id + [Documentation] Check that you cannot retrieve a context source registration subscription with an invalid URI, an error of type BadRequestData shall be raised + [Tags] mandatory + + Retrieve Context Source Registration Subscription invalidUri + + Check Response Status Code Set To 400 + Check Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${ERROR_TYPE_BAD_REQUEST_DATA} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} diff --git a/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot new file mode 100644 index 00000000..d48f640a --- /dev/null +++ b/TP/NGSI-LD/ContextSource/RegistrationSubscription/RetrieveContextSourceRegistrationSubscription/034_03.robot @@ -0,0 +1,16 @@ +*** Settings *** +Documentation Check that you cannot retrieve an unknown context source registration subscription, an error of type ResourceNotFound shall be raised +Resource ${EXECDIR}/resources/ApiUtils.resource +Resource ${EXECDIR}/resources/AssertionUtils.resource +Resource ${EXECDIR}/resources/JsonUtils.resource + +*** Test Case *** +Retrieve Unknown Context Source Registration Subscription + [Documentation] Check that you cannot retrieve an unknown context source registration subscription, an error of type ResourceNotFound shall be raised + [Tags] mandatory + + Retrieve Context Source Registration Subscription urn:ngsi-ld:Subscription:unknowSubscription + + Check Response Status Code Set To 404 + Check Response Body Containing ProblemDetails Element Containing Type Element set to ${response} ${ERROR_TYPE_RESOURCE_NOT_FOUND} + Check Response Body Containing ProblemDetails Element Containing Title Element ${response} diff --git a/resources/ApiUtils.resource b/resources/ApiUtils.resource index ca87fce1..9925f19f 100755 --- a/resources/ApiUtils.resource +++ b/resources/ApiUtils.resource @@ -410,9 +410,11 @@ Update Context Source Registration Subscription Set Test Variable ${response} Retrieve Context Source Registration Subscription - [Arguments] ${subscription_id} + [Arguments] ${subscription_id} ${context}=${EMPTY} - ${response}= GET ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH}/${subscription_id} + &{headers}= Create Dictionary + Run Keyword If '${context}'!='' Set To Dictionary ${headers} Link=<${context}>; rel="http://www.w3.org/ns/json-ld#context";type="application/ld+json" + ${response}= GET ${CONTEXT_SOURCE_REGISTRATION_SUBSCRIPTION_ENDPOINT_PATH}/${subscription_id} headers=${headers} Output request Output response diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 415a2d02..442268ff 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -4,6 +4,7 @@ Library ${EXECDIR}/libraries/assertionUtils.py *** Variable *** ${instance_id_regex_expr}= root\\[.*\\]\\['instanceId'\\] ${notification_timestamps_regex_expr}= root\\['last.*'\\] +${context_regex_expr}= root\\['@context'\\] *** Keywords *** Check Response Status Code @@ -36,13 +37,17 @@ Check Response Body Content ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response_body} ${entity_payload} ${instance_id_regex_expr} Should Be True ${comparaison_result} msg=Entity Comparaison Failed +# Since Http headers names are case-insensitive (from Http specification) +# We check both Location and location headers Check Response Headers Containing URI set to [Arguments] ${expected_path} ${expected_entity_id} ${response} - Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True + + Run Keyword If 'Location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['Location']} ignore_order=True + Run Keyword If 'location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True Check Response Headers ID Not Empty [Arguments] ${response} - ${id}= Fetch From Right ${response['headers']['location']} / + ${id}= Fetch From Right ${response['headers']['Location']} / Should Not Be Empty ${id} [return] ${id} @@ -104,6 +109,13 @@ Check Response Body Containing List Containing EntityTemporal elements ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${temporal_entities_representation_payload} ${instance_id_regex_expr} Should Be True ${comparaison_result} msg=EntityTemporal List Comparaison Failed +Check Response Body Containing Subscription element + [Arguments] ${expectation_filename} ${subscription_id} + ${subscription_payload}= Load Json From File ${EXECDIR}/data/${expectation_filename} + ${subscription}= Update Value To Json ${subscription_payload} $..id ${subscription_id} + ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${subscription} ${context_regex_expr} + Should Be True ${comparaison_result} msg=Subscription Comparaison Failed + Check Response Body Type When Using Session Request [Arguments] ${response} ${type} Should Be Equal ${response['type']} ${type} -- GitLab From 49d68d9f917b6ad075e391fe5c0df1ad69227c43 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 3 Feb 2021 17:32:04 +0100 Subject: [PATCH 2/3] fix: fix check on location header in Check Response Headers ID Not Empty --- resources/AssertionUtils.resource | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index 442268ff..aeb8dd91 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -45,9 +45,13 @@ Check Response Headers Containing URI set to Run Keyword If 'Location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['Location']} ignore_order=True Run Keyword If 'location' in ${response['headers']} Should Be Equal ${expected_path}${expected_entity_id} ${response['headers']['location']} ignore_order=True +# Since Http headers names are case-insensitive (from Http specification) +# We check both Location and location headers Check Response Headers ID Not Empty [Arguments] ${response} - ${id}= Fetch From Right ${response['headers']['Location']} / + + ${location_header}= Set Variable If 'Location' in ${response['headers']} ${response['headers']['Location']} ${response['headers']['location']} + ${id}= Fetch From Right ${location_header} / Should Not Be Empty ${id} [return] ${id} -- GitLab From 67febf152346616238ef10fbc910b165912f2c99 Mon Sep 17 00:00:00 2001 From: Houcem Kacem Date: Wed, 3 Feb 2021 19:24:02 +0100 Subject: [PATCH 3/3] fix: ignore subscription status when checking response body --- libraries/assertionUtils.py | 4 ++-- resources/AssertionUtils.resource | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/assertionUtils.py b/libraries/assertionUtils.py index 87a56863..fb7e614e 100644 --- a/libraries/assertionUtils.py +++ b/libraries/assertionUtils.py @@ -4,8 +4,8 @@ def compare_dictionaries_ignoring_keys(dict1, dict2, exclude_regex_paths): """Function exposed as a keyword to compare two dictionaries :param dict1: actual dictionary :param dict2: expected dictionary - :param exclude_regex_paths: regex path of keys to be ignored + :param exclude_regex_paths: list of regex paths of keys to be ignored """ - res = DeepDiff(dict1, dict2, exclude_regex_paths=[exclude_regex_paths], ignore_order=True) + res = DeepDiff(dict1, dict2, exclude_regex_paths=exclude_regex_paths, ignore_order=True) print(res) return not res diff --git a/resources/AssertionUtils.resource b/resources/AssertionUtils.resource index aeb8dd91..25c5f6fc 100755 --- a/resources/AssertionUtils.resource +++ b/resources/AssertionUtils.resource @@ -5,6 +5,7 @@ Library ${EXECDIR}/libraries/assertionUtils.py ${instance_id_regex_expr}= root\\[.*\\]\\['instanceId'\\] ${notification_timestamps_regex_expr}= root\\['last.*'\\] ${context_regex_expr}= root\\['@context'\\] +${status_regex_expr}= root\\['status'\\] *** Keywords *** Check Response Status Code @@ -117,7 +118,8 @@ Check Response Body Containing Subscription element [Arguments] ${expectation_filename} ${subscription_id} ${subscription_payload}= Load Json From File ${EXECDIR}/data/${expectation_filename} ${subscription}= Update Value To Json ${subscription_payload} $..id ${subscription_id} - ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${subscription} ${context_regex_expr} + ${ignored_keys}= Create List ${status_regex_expr} ${context_regex_expr} + ${comparaison_result}= Compare Dictionaries Ignoring Keys ${response['body']} ${subscription} ${ignored_keys} Should Be True ${comparaison_result} msg=Subscription Comparaison Failed Check Response Body Type When Using Session Request -- GitLab