Commit 00c4367c authored by Ranim Naimi's avatar Ranim Naimi
Browse files

feat: add new tcs for replace attribute endpoint

parent e18e7808
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -373,7 +373,7 @@ In these cases, it is needed to provide the corresponding information in the Pyt
- When a new permutation is added in an existing Test Case, run the documentation generation script 
  (`python doc/generateDocumentationData.py {tc_id}`) for the Test Case and copy the generated JSON file in the 
  folder containing all files for the given group and subgroup (`cp doc/results/{tc_id}.json doc/files/{group}/{subgroup}`)
- When a new directory containing Test Cases is created, it has to be declared in `doc/generaterobotdata.py` along with
- When a new directory containing Test Cases is created, it has to be declared in `doc/analysis/generaterobotdata.py` along with
  its acronym

Finally, check that everything is OK by running the unit tests:
+5 −2
Original line number Diff line number Diff line
@@ -27,14 +27,17 @@ ${expectation_filename} building-locatedAt-and-name-normalized.jsonl
    ${response}=    Replace Entity Selecting Content Type
    ...    entity_id=${entity_id}
    ...    entity_fragment=${entity}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${ignored_attributes}=    Create List    @context    createdAt    modifiedAt
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    ${entity_expectation_payload}=    Load Test Sample
    ...    test_sample_file_path=entities/expectations/${expectation_filename}
    ...    test_sample_id=${entity_id}
    Check Updated Resource Set To
    ...    updated_resource=${entity_expectation_payload}
    ...    response_body=${response1.json()}
+2 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ Replace an existing entity with a faulty ID
    ${response}=    Replace Entity Selecting Content Type
    ...    entity_id=${faulty_entity_id}
    ...    entity_fragment=${entity}
    ...    content_type=${CONTENT_TYPE_LD_JSON}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    ${expected_status_code}    ${response.status_code}

Setup Initial Entity
+73 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can replace an existing entity attribute and that its createdAt Temporal Property remains unchanged

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entity
Test Teardown       Delete Initial Entity
Test Template       Replace Entity Attribute


*** Variables ***
${vehicle_id_prefix}    urn:ngsi-ld:Vehicle:
${entity_filename}      vehicle-speed-multi-instances.jsonld


*** Test Cases ***    ATTRIBUTE_FILE_NAME    EXPECTATION_FILE_NAME
055_01_01 Replace entity attribute
    [Tags]    ea-replace    5_6_19    6_7_3_3    since_v1.6.1
    vehicle-isParked-attribute.json    vehicle-replace-isParked-attribute.jsonld
055_01_02 Replace entity attribute giving a new attribute type
    [Tags]    ea-replace    5_6_19    6_7_3_3    since_v1.6.1
    vehicle-isParked-new-type-attribute.json    vehicle-replace-isParked-new-type-attribute.jsonld


*** Keywords ***
Replace Entity Attribute
    [Documentation]    Check that one can replace an existing entity attribute and that its createdAt Temporal Property remains unchanged
    [Arguments]    ${attribute_replacement_filename}    ${expectation_filename}
    ${attribute}=    Load Test Sample
    ...    test_sample_file_path=entities/${attribute_replacement_filename}
    ...    test_sample_id=${entity_id}
    ${response}=    Replace Attribute Selecting Content Type
    ...    entity_id=${entity_id}
    ...    attr_id=isParked
    ...    attribute_fragment=${attribute}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${ignored_attributes}=    Create List    @context    createdAt    modifiedAt
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    Check Updated Resource Set To
    ...    updated_resource=${entity_expectation_payload}
    ...    response_body=${response1.json()}
    ...    ignored_keys=${ignored_attributes}
    Check JSON Value In Response Body
    ...    json_path_expr=['isParked']['createdAt']
    ...    value_to_check=${createdAt}
    ...    response_body=${response1.json()}

Setup Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    ${response}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${createdAt}=    Set Variable    ${response.json()['isParked']['createdAt']}
    Set Test Variable    ${createdAt}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
+73 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       Check that one can replace an existing multi-instance entity attribute and that its createdAt Temporal Property remains unchanged

Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationProvision.resource
Resource            ${EXECDIR}/resources/ApiUtils/ContextInformationConsumption.resource
Resource            ${EXECDIR}/resources/AssertionUtils.resource
Resource            ${EXECDIR}/resources/JsonUtils.resource

Test Setup          Setup Initial Entity
Test Teardown       Delete Initial Entity
Test Template       Replace Multi Instance Entity Attribute


*** Variables ***
${vehicle_id_prefix}    urn:ngsi-ld:Vehicle:
${entity_filename}      vehicle-speed-multi-instances.jsonld


*** Test Cases ***    ATTRIBUTE_FILE_NAME    EXPECTATION_FILE_NAME
055_02_01 Replace entity attribute giving no datasetId
    [Tags]    ea-replace    5_6_19    6_7_3_3    since_v1.6.1
    vehicle-speed-default-instance.json    vehicle-replace-speed-default-instance.jsonld
055_02_02 Replace entity attribute giving a datasetId
    [Tags]    ea-replace    5_6_19    6_7_3_3    since_v1.6.1
    vehicle-speed-datasetid-instance.json    vehicle-replace-speed-datasetid-instance.jsonld


*** Keywords ***
Replace Multi Instance Entity Attribute
    [Documentation]    Check that one can replace an existing multi-instance entity attribute and that its createdAt Temporal Property remains unchanged
    [Arguments]    ${attribute_replacement_filename}    ${expectation_filename}
    ${attribute}=    Load Test Sample
    ...    test_sample_file_path=entities/${attribute_replacement_filename}
    ...    test_sample_id=${entity_id}
    ${response}=    Replace Attribute Selecting Content Type
    ...    entity_id=${entity_id}
    ...    attr_id=speed
    ...    attribute_fragment=${attribute}
    ...    content_type=${CONTENT_TYPE_JSON}
    ...    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response.status_code}
    ${response1}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${ignored_attributes}=    Create List    @context    createdAt    modifiedAt
    ${entity_expectation_payload}=    Load Test Sample    entities/expectations/${expectation_filename}    ${entity_id}
    Check Updated Resource Set To
    ...    updated_resource=${entity_expectation_payload}
    ...    response_body=${response1.json()}
    ...    ignored_keys=${ignored_attributes}
    Check JSON Value In Response Body
    ...    json_path_expr=['speed'][0]['createdAt']
    ...    value_to_check=${createdAt}
    ...    response_body=${response1.json()}

Setup Initial Entity
    ${entity_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    Set Test Variable    ${entity_id}
    ${response}=    Create Entity Selecting Content Type
    ...    ${entity_filename}
    ...    ${entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response.status_code}
    ${response}=    Retrieve Entity by Id
    ...    id=${entity_id}
    ...    context=${ngsild_test_suite_context}
    ...    options=sysAttrs
    ${createdAt}=    Set Variable    ${response.json()['speed'][0]['createdAt']}
    Set Test Variable    ${createdAt}

Delete Initial Entity
    Delete Entity by Id    ${entity_id}
Loading