Commit 539a6a96 authored by Patricia dos Santos Oliveira's avatar Patricia dos Santos Oliveira
Browse files

Add README, AlreadyExists suite and data-driven example

parent e2b97d8e
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
*OS: Linux*

#### Install Python & PIP   

* Install Python3 by running the following command:   
```$ sudo dnf install python3```
* Confirm its installation with:   
```$ python --version```
* At this point, you can launch Python3 interpreter:    
```$ python```
* Pip should be included by default. To confirm, run:   
```$ command -v pip```   
* In case pip is not installed, [follow the official pip installation guide](https://pip.pypa.io/en/latest/installing/).

#### Install IDE (VSCode)
* Install Visual Studio code (https://code.visualstudio.com/docs/setup/linux)

* Install [Robot Framework Intellisense](https://marketplace.visualstudio.com/items?itemName=TomiTurtiainen.rf-intellisense)

#### Checkout the base project   
```$ git clone https://github.com/easy-global-market/isg-cim-tpdl-demo.git``` 

#### Install the project requirements
Browse the base project root folder and execute the following command:   

```$ sudo python -m pip install -r requirements.txt```    

Further details on each library can be found in [PyPi](https://pypi.org/) and [Robot Framework Standard Libraries](http://robotframework.org/robotframework/#standard-libraries)

#### Execute the tests
```$ robot --outputdir ./results .```   

For more running instructions please consult [scripts/run_tests.sh](https://github.com/easy-global-market/isg-cim-tpdl-demo/blob/rf-demo/scripts/run_tests.sh).

#### Useful links   
* [Robot Framework User Guide](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#output-file)   
+9 −12
Original line number Diff line number Diff line
*** Settings ***
Documentation   TP description.
Variables   ../../../../../resources/variables.py
Documentation   Check that the IUT refuses to create an entity if one exists with the same identifier 
Variables   ../../../../../../resources/variables.py
Library     REST    ${url}
Library     JSONSchemaLibrary   ${CURDIR}/schemas
Library     OperatingSystem
Library     String

#Suite Setup 
Suite Teardown  Delete Entity by Id  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9
#Suite Setup      Create Entity  building-minimal.jsonld
#Suite Teardown   Delete Entity by Id  urn:ngsi-ld:Building:3009ef20-9f62-41f5-bd66-92f041b428b9

*** Variable ***
${endpoint}=    entities

*** Test Case ***
CreateEntity_200_Minimal
    [Documentation]  TP Variation description.
    [Tags]  critical  
AlreadyExists
    [Documentation]  Check that the IUT refuses to create an entity if one exists with the same identifier 
    Create Entity  building-minimal.jsonld
    Check HTTP Status Code Is  201

CreateEntity_409_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  
+54 −0
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
Library     OperatingSystem
Library     String

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

*** Test Case ***
SuccessCases_MinimalEntity
    [Documentation]  Create an entity with a JSON-LD payload containing the minimal information 
    [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
    Check HTTP Status Code Is  201
    Delete Entity by Id  ${id}


*** 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}  
    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}

Check HTTP Response Body Json Schema Is
    [Arguments]  ${input}
    Should Contain  ${response['headers']['Content-Type']}  application/json
    ${schema}=  Catenate  SEPARATOR=  ${input}  .schema.json
    Validate Json  ${schema}  ${response['body']}
    Log  Json Schema Validation OK

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
+44 −0
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
Library     OperatingSystem
Library     String

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
+0 −0

File moved.

Loading