Commit 29f04079 authored by Benoit Orihuela's avatar Benoit Orihuela
Browse files

chore: tidy the Test Cases for a consistent code formatting

parent 139c5ab0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -72,6 +72,18 @@ Optionally, you can generate metrics from the results of tests:

A sample report can be seen at https://robotmetrics.netlify.app/#

## Generate a documentation for the support keywords

```$ python3 -m robot.libdoc resources/ApiUtils.resource api_docs/ApiUtils.html```

## Generate a documentation for the Test Cases

```$ python3 -m robot.testdoc TP/NGSI-LD api_docs/TestCases.html```

## Tidy the Test Cases

```$ python3 -m robot.tidy --recursive TP/NGSI-LD```

# Frameworks and libraries used in the project

* [Robot Framework](https://github.com/robotframework/robotframework)
+53 −69
Original line number Diff line number Diff line
@@ -6,16 +6,12 @@ Resource ${EXECDIR}/resources/JsonUtils.resource

*** Variable ***
${expected_status_code}=    503

${building_id_prefix}=    urn:ngsi-ld:Building:
${building_filename}=    building-unretrievable-context-sample.jsonld

${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_filename}=    subscriptions/subscription-unretrievable-context-sample.jsonld

${tea_id_prefix}=    urn:ngsi-ld:Vehicle:
${tea_filename}=    bus-temporal-representation-unretrievable-context-sample.jsonld

${registration_id_prefix}=    urn:ngsi-ld:Registration:
${registration_filename}=    csourceRegistrations/context-source-registration-unretrievable-context-sample.jsonld

@@ -23,66 +19,54 @@ ${registration_filename}= csourceRegistrations/context-source-registration-unre
043_01 Create entity
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create entity)
    [Tags]    e-create    5_2_2

    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type    ${building_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to    ${response}    ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]    Delete Entity by Id    ${entity_id}

043_02 Create subscription
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create subscription)
    [Tags]    sub-create    5_2_2

    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${response}=    Create Subscription    ${subscription_id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to    ${response}    ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]    Delete Subscription    ${subscription_id}

043_03 Create Temporal Representation of Entities
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create Temporal Representation of Entities)
    [Tags]    te-create    5_2_2

    ${temporal_entity_representation_id}=    Generate Random Entity Id    ${tea_id_prefix}
    ${response}=    Create Or Update Temporal Representation Of Entity Selecting Content Type    ${temporal_entity_representation_id}    ${tea_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    ${expected_status_code}    ${response['status']}
    Check Response Body Containing ProblemDetails Element Containing Type Element set to    ${response}    ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]    Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}

043_04 Batch entity create
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Batch entity create)
    [Tags]    be-create    5_2_2

    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${first_entity}=    Load Entity    ${building_filename}    ${first_entity_id}
    ${second_entity}=    Load Entity    ${building_filename}    ${second_entity_id}
    @{entities_to_be_created}=    Create List    ${first_entity}    ${second_entity}

    Batch Create Entities    @{entities_to_be_created}    content_type=${CONTENT_TYPE_LD_JSON}
    Check Response Status Code Set To    ${expected_status_code}
    Check RL Response Body Containing ProblemDetails Element Containing Type Element set to    ${response}    ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    Check RL Response Body Containing ProblemDetails Element Containing Title Element    ${response}

    [Teardown]    Batch Delete Entities    @{entities_to_be_created}

043_05 Create context source registration
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create context source registration)
    [Tags]    csr-create    5_2_2
    
    ${registration_id}=    Generate Random Entity Id    ${registration_id_prefix}

    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_filename}
    ${updated_payload}=    Update Value To Json    ${payload}    $..id    ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return    ${updated_payload}
    Check Response Status Code    ${expected_status_code}    ${response['status']}
    Check Response Headers Containing URI set to    ${request['path']}/    ${registration_id}    ${response}

    [Teardown]    Delete Context Source Registration    ${registration_id}
+28 −34
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ ${vehicle_id_prefix}= urn:ngsi-ld:Vehicle:
${vehicle_filename}=    vehicle-simple-attributes-sample.jsonld
${vehicle_fragment}=    vehicle-brandname-fragment.json
${attribute_id}=    brandName

${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_filename}=    subscriptions/subscription-sample.jsonld
${subscription_fragment}=    subscriptions/fragments/subscription-update-sample.json
@@ -21,10 +20,8 @@ ${subscription_fragment}= subscriptions/fragments/subscription-update-sample.js
    ${entity_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type    ${vehicle_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${response}=    Partial Update Entity Attributes    ${entity_id}    ${attribute_id}    ${vehicle_fragment}    ${CONTENT_TYPE_MERGE_PATCH_JSON}    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response['status']}

    [Teardown]    Delete Entity by Id    ${entity_id}

044_01_02_endpoint /subscriptions/{subscriptionId}
@@ -33,9 +30,6 @@ ${subscription_fragment}= subscriptions/fragments/subscription-update-sample.js
    ${subscription_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${response}=    Create Subscription    ${subscription_id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${response}=    Update Subscription    ${subscription_id}    ${subscription_fragment}    ${CONTENT_TYPE_MERGE_PATCH_JSON}    context=${ngsild_test_suite_context}
    Check Response Status Code    204    ${response['status']}

    [Teardown]    Delete Subscription    ${subscription_id}
+63 −78
Original line number Diff line number Diff line
@@ -9,21 +9,17 @@ ${building_id_prefix}= urn:ngsi-ld:Building:
${building_filename}=    building-simple-attributes-sample.jsonld
${building_expectation}=    building-simple-attributes-sample-expectation.json
${entity_type}=    https://ngsi-ld-test-suite/context#Building

${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_filename}=    subscriptions/subscription-sample.jsonld
${subscription_expectation}=    subscription-sample-expectation.json

${registration_id_prefix}=    urn:ngsi-ld:Registration:
${registration_filename}=    csourceRegistrations/context-source-registration-with-expiration-sample.jsonld
${registration_expectation}=    context-source-registration-with-expiration-expectation.json
${registration_type}=    Vehicle

${tea_id_prefix}=    urn:ngsi-ld:Vehicle:
${tea_filename}=    vehicle-temporal-representation-sample.jsonld
${tea_expectation}=    vehicles-temporal-representation-044-02-04-expectation.json
${teatype}=       Vehicle

${content_type}=    application/json

*** Test Cases ***
@@ -33,62 +29,51 @@ ${content_type}= application/json
    ${id}=    Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type    ${building_filename}    ${id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${request}    ${response}=    Query Entity    ${id}    context=${ngsild_test_suite_context}    accept=*/*
    Check Response Status Code    200    ${response['status']}
    Check Response Body Containing Entity element    ${building_expectation}    ${id}    ${response['body']}
    Check Response Headers Containing Content-Type set to    ${response}    ${content_type}
    Check Response Headers Link Not Empty    ${response}

    [Teardown]    Delete Entity by Id Returning Response    ${id}

044_02_02_endpoint /subscriptions/{subscriptionId}
    [Documentation]    Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/subscriptions/{subscriptionId})
    [Tags]    sub-retrieve    6_3_4

    ${id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${response}=    Create Subscription    ${id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${request}    ${response}=    Retrieve Subscription    ${id}    accept=*/*
    Check Response Status Code    200    ${response['status']}
    Check Response Body Containing One Subscription element    ${subscription_expectation}    ${response['body']}
    Check Response Headers Containing Content-Type set to    ${response}    ${content_type}
    Check Response Headers Link Not Empty    ${response}

    [Teardown]    Delete Subscription    ${id}

044_02_03_endpoint /csourceRegistrations/
    [Documentation]    Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/csourceRegistrations/)
    [Tags]    csr-query    6_3_4

    ${registration_id}=    Generate Random Entity Id    ${registration_id_prefix}
    ${payload}=    Load Json From File    ${EXECDIR}/data/${registration_filename}
    ${updated_payload}=    Update Value To Json    ${payload}    $..id    ${registration_id}
    ${request}    ${response}=    Create Context Source Registration With Return    ${updated_payload}
    Check Response Status Code    201    ${response['status']}

    ${request}    ${response}=    Query Context Source Registrations With Return    id=${registration_id}    type=${registration_type}    context=${ngsild_test_suite_context}    accept=*/*
    Check Response Status Code    200    ${response['status']}
    Check Response Body Containing One Registration element    ${registration_expectation}    ${response['body']}
    Check Response Headers Containing Content-Type set to    ${response}    ${content_type}
    Check Response Headers Link Not Empty    ${response}

    [Teardown]    Delete Context Source Registration    ${registration_id}

044_02_04_endpoint /temporal/entities
    [Documentation]    Verify that on a GET HTTP request if nothing is specified on the Accept header, "application/json" is assumed (/temporal/entities)
    [Tags]    te-query    6_3_4
    
    ${temporal_entity_representation_id}=    Generate Random Entity Id    ${tea_id_prefix}
    Create Temporal Representation Of Entity    ${tea_filename}    ${temporal_entity_representation_id}
    Check Response Status Code    201    ${response['status']}

    ${request}    ${response}=    Query Temporal Representation Of Entities With Return    entity_types=${teatype}    timerel=after    timeAt=2020-08-01T12:05:00Z    context=${ngsild_test_suite_context}    accept=*/*
    Check Response Status Code    200    ${response['status']}
    Set Test Variable    ${response}
    Check Response Body Containing EntityTemporal element    ${tea_expectation}    ${temporal_entity_representation_id}
    Check Response Headers Containing Content-Type set to    ${response}    ${content_type}
    Check Response Headers Link Not Empty    ${response}

    [Teardown]    Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}
+60 −80
Original line number Diff line number Diff line
@@ -9,89 +9,69 @@ ${vehicle_id_prefix}= urn:ngsi-ld:Vehicle:
${vehicle_filename}=    vehicle-simple-attributes-sample.jsonld
${vehicle_attribute}=    speed
${vehicle_fragment}=    vehicle-brandname-fragment.jsonld

${subscription_id_prefix}=    urn:ngsi-ld:Subscription:
${subscription_filename}=    csourceSubscriptions/subscription-sample.jsonld
${subscription_fragment}=    csourceSubscriptions/fragments/subscription-update-sample.jsonld

${tea_id_prefix}=    urn:ngsi-ld:Vehicle:
${tea_filename}=    vehicle-temporal-representation-sample.jsonld

${building_id_prefix}=    urn:ngsi-ld:Building:
${building_filename}=    building-simple-attributes-sample.jsonld

${content_type}=    application/xml

*** Test Cases ***
044_03_01_endpoint patch /entities/{entityId}/attrs/{attrId}
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (patch /entities/{entityId}/attrs/{attrId})
    [Tags]    ea-partial-update    6_3_4

    ${entity_id}=    Generate Random Entity Id    ${vehicle_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type    ${vehicle_filename}    ${entity_id}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${response}=    Partial Update Entity Attributes    ${entity_id}    ${vehicle_attribute}    ${vehicle_fragment}    ${content_type}
    Check Response Status Code    415    ${response['status']}

    [Teardown]    Delete Entity by Id Returning Response    ${entity_id}

044_03_02_endpoint patch /subscriptions/{subscriptionId}
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (patch /subscriptions/{subscriptionId})
    [Tags]    sub-update    6_3_4

    ${id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${response}=    Create Subscription    ${id}    ${subscription_filename}    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${response['status']}

    ${response}=    Update Subscription    ${id}    ${subscription_fragment}    ${content_type}
    Check Response Status Code    415    ${response['status']}

    [Teardown]    Delete Subscription    ${id}

044_03_03_endpoint post /entities/
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (post /entities/)
    [Tags]    e-create    6_3_4

    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${request}    ${response}=    Create Entity Selecting Content Type    ${building_filename}    ${entity_id}    ${content_type}
    Check Response Status Code    415    ${response['status']}

    [Teardown]    Delete Entity by Id    ${entity_id}

044_03_04_endpoint post /subscriptions/
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (post /subscriptions/)
    [Tags]    sub-create    6_3_4

    ${subscriptions_id}=    Generate Random Entity Id    ${subscription_id_prefix}
    ${response}=    Create Subscription    ${subscriptions_id}    ${subscription_filename}    ${content_type}
    Check Response Status Code    415    ${response['status']}

    [Teardown]    Delete Subscription    ${subscriptions_id}

044_03_05_endpoint post /entityOperations/create
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (post /entityOperations/create)
    [Tags]    be-create    6_3_4

    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    ${first_entity}=    Load Entity    ${building_filename}    ${first_entity_id}
    ${second_entity}=    Load Entity    ${building_filename}    ${second_entity_id}
    @{entities_to_be_created}=    Create List    ${first_entity}    ${second_entity}

    Batch Create Entities    @{entities_to_be_created}    content_type=${content_type}

    @{expected_entities_ids}=    Create List    ${first_entity_id}    ${second_entity_id}
    Check Response Status Code Set To    415

    [Teardown]    Batch Delete Entities    @{expected_entities_ids}

044_03_06_endpoint post /temporal/entities/
    [Documentation]    Verify throwing 415 HTTP status code (Unsupported Media Type) if "Content-Type" header is not "application/json" or "application/ld+json" (post /temporal/entities/)
    [Tags]    te-create    6_3_4
    
    ${temporal_entity_representation_id}=    Generate Random Entity Id    ${tea_id_prefix}
    ${response}=    Create Or Update Temporal Representation Of Entity Selecting Content Type    ${temporal_entity_representation_id}    ${tea_filename}    ${content_type}
    Check Response Status Code    415    ${response['status']}

    [Teardown]    Delete Temporal Representation Of Entity    ${temporal_entity_representation_id}
Loading