Commit 0f8ce423 authored by Houcem Kacem's avatar Houcem Kacem
Browse files

feat: add minimal test for create a batch of entities

parent 621fb83e
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the IUT accepts the creation of an entity 
Documentation   Check that you can create a batch of entities
Variables   ../../../../../../resources/variables.py
#Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/ApiUtils.resource
Library     REST    ${url}
Library     JSONSchemaLibrary   ${EXECDIR}/schemas
Library     BuiltIn
Library     OperatingSystem


*** Variable ***
${endpoint}=    entities
${id}=  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9
${endpoint}=    entityOperations/create

*** Test Case ***
SuccessCases_MinimalEntity
    [Documentation]  Create an entity with a JSON-LD payload containing the minimal information 
AlreadyExists
    [Documentation]  Check that you can create a batch of entities
    [Tags]  critical
    Create Entity  building-minimal.jsonld
    Check HTTP Status Code Is  201
    Delete Entity by Id  ${id}

SuccessCases_EntityWithSimpleProperties
    [Documentation]  Create an entity with a JSON-LD payload containing only simple properties
    Create Entity  building-simple-attributes.jsonld
    Batch Create Entities   filename=building-minimal.jsonld    filename_2=building-minimal-2.jsonld
    Check HTTP Status Code Is  201
    Delete Entity by Id  ${id}

    # it will be replaced by on call Batch Delete Entities
    Delete Entity by Id  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9
    Delete Entity by Id  urn:ngsi-ld:Building:56hy789-eft6-9987-be54-adr45nf567ddz

*** Keywords ***
Create Entity  
    [Arguments]  ${filename}    
    &{headers}=  Create Dictionary  Content-Type=application/ld+json    authorization=Bearer ${token}
    ${response}=  POST  ${endpoint}  body=${CURDIR}/data/${filename}  headers=${headers}  
Batch Create Entities
    [Arguments]  ${filename}    ${filename_2}
    &{headers}=  Create Dictionary  Content-Type=application/ld+json
    ${file_content}=    Get File    ${EXECDIR}/data/${filename}
    ${file_content_2}=    Get File    ${EXECDIR}/data/${filename_2}
    ${body}=  Create List   ${file_content}     ${file_content_2}
    log  ${body}
    ${response}=  POST  ${endpoint}  body=${body}  headers=${headers}
    Output  request
    Output  response
    Set Test Variable  ${response}
@@ -39,7 +41,6 @@ Check HTTP Status Code Is

Delete Entity by Id
    [Arguments]  ${id}
    &{headers}=  Create Dictionary  authorization=Bearer ${token}
    ${response}=  DELETE  ${endpoint}/${id}  headers=${headers}  
    ${response}=  DELETE  ${endpoint}/${id}
    Output  request
    Output  response
+6 −8
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the IUT refuses to create an entity if one exists with the same identifier 
Variables   ../../../../../../resources/variables.py
#Resource    ../../../../../../resources/ApiUtils.resource
Resource    ../../../../../../resources/ApiUtils.resource
Library     REST    ${url}
Library     JSONSchemaLibrary   ${CURDIR}/schemas
Library     JSONSchemaLibrary   ${EXECDIR}/schemas
Library     BuiltIn

#Suite Setup      Create Entity  building-minimal.jsonld
@@ -20,13 +20,12 @@ AlreadyExists
    Create Entity  building-minimal.jsonld
    Check HTTP Status Code Is  409
    Check HTTP Response Body Json Schema Is  error_response
    Delete Entity by Id  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9

*** Keywords ***
Create Entity  
    [Arguments]  ${filename}    
    &{headers}=  Create Dictionary  Content-Type=application/ld+json    authorization=Bearer ${token}
    ${response}=  POST  ${endpoint}  body=${CURDIR}/data/${filename}  headers=${headers}  
    &{headers}=  Create Dictionary  Content-Type=application/ld+json
    ${response}=  POST  ${endpoint}  body=${EXECDIR}/data/${filename}  headers=${headers}  
    Output  request
    Output  response
    Set Test Variable  ${response}
@@ -45,7 +44,6 @@ Check HTTP Response Body Json Schema Is

Delete Entity by Id
    [Arguments]  ${id}    
    &{headers}=  Create Dictionary  authorization=Bearer ${token}
    ${response}=  DELETE  ${endpoint}/${id}  headers=${headers}  
    ${response}=  DELETE  ${endpoint}/${id}
    Output  request
    Output  response
+0 −42
Original line number Diff line number Diff line
*** Settings ***
Documentation   Check that the IUT accepts the creation of an entity 
Variables   ../../../../../../resources/variables.py
Library     REST    ${url}
Library     JSONSchemaLibrary   ${CURDIR}/schemas

Test Template  Create Entity Scenarios  

*** Variable ***
${endpoint}=    entities
${id}=  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9

*** Test Cases ***                        FILENAME
SuccessCases_MinimalEntity                building-minimal.jsonld
SuccessCases_EntityWithSimpleProperties   building-simple-attributes.jsonld

*** Keywords ***
Create Entity Scenarios
     [Arguments]  ${filename}
     Create Entity  ${filename}
     Check HTTP Status Code Is  201
     Delete Entity by Id  ${id}

Create Entity  
    [Arguments]  ${filename}    
    &{headers}=  Create Dictionary  Content-Type=application/ld+json    authorization=Bearer ${token}
    ${response}=  POST  ${endpoint}  body=${CURDIR}/data/${filename}  headers=${headers}  
    Output  request
    Output  response
    Set Test Variable  ${response}

Check HTTP Status Code Is 
    [Arguments]  ${status}
    ${response_status}=  convert to string  ${response['status']}
    Should Be Equal  ${response_status}  ${status}

Delete Entity by Id
    [Arguments]  ${id}    
    &{headers}=  Create Dictionary  authorization=Bearer ${token}
    ${response}=  DELETE  ${endpoint}/${id}  headers=${headers}  
    Output  request
    Output  response
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:56hy789-eft6-9987-be54-adr45nf567ddz",
    "type": "Building",
    "@context": [
        "https://fiware.github.io/data-models/context.jsonld",
        "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
    ]
}
 No newline at end of file
Loading