Commit 01715180 authored by poujol's avatar poujol
Browse files

Merge branch 'chore/integrate-robotidy-tool' into 'develop'

chore: run Robotidy on all TCs and resources files

See merge request !78
parents 8af7b452 80227501
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="Check Format" type="PythonConfigurationType" factoryName="Python">
    <log_file alias="robotidy" path="$PROJECT_DIR$/robotidy" />
    <module name="ngsi-ld-test-suite" />
    <option name="INTERPRETER_OPTIONS" value="" />
    <option name="PARENT_ENVS" value="true" />
    <envs>
      <env name="PYTHONUNBUFFERED" value="1" />
    </envs>
    <option name="SDK_HOME" value="$PROJECT_DIR$/venv/bin/python" />
    <option name="WORKING_DIRECTORY" value="" />
    <option name="IS_MODULE_SDK" value="true" />
    <option name="ADD_CONTENT_ROOTS" value="true" />
    <option name="ADD_SOURCE_ROOTS" value="true" />
    <option name="SCRIPT_NAME" value="robotidy" />
    <option name="PARAMETERS" value="--check $ContentRoot$" />
    <option name="SHOW_COMMAND_LINE" value="false" />
    <option name="EMULATE_TERMINAL" value="true" />
    <option name="MODULE_MODE" value="true" />
    <option name="REDIRECT_INPUT" value="false" />
    <option name="INPUT_FILE" value="" />
    <method v="2" />
  </configuration>
</component>
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="Format Files" type="PythonConfigurationType" factoryName="Python">
    <module name="ngsi-ld-test-suite" />
    <option name="INTERPRETER_OPTIONS" value="" />
    <option name="PARENT_ENVS" value="true" />
    <envs>
      <env name="PYTHONUNBUFFERED" value="1" />
    </envs>
    <option name="SDK_HOME" value="" />
    <option name="WORKING_DIRECTORY" value="" />
    <option name="IS_MODULE_SDK" value="true" />
    <option name="ADD_CONTENT_ROOTS" value="true" />
    <option name="ADD_SOURCE_ROOTS" value="true" />
    <option name="SCRIPT_NAME" value="robotidy" />
    <option name="PARAMETERS" value="$ContentRoot$" />
    <option name="SHOW_COMMAND_LINE" value="false" />
    <option name="EMULATE_TERMINAL" value="true" />
    <option name="MODULE_MODE" value="true" />
    <option name="REDIRECT_INPUT" value="false" />
    <option name="INPUT_FILE" value="" />
    <method v="2" />
  </configuration>
</component>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
repos:
  - repo: https://github.com/MarketSquare/robotframework-tidy
    id: robotidy
    rev: 4.2.1
    hooks:
      - id: robotidy
+33 −4
Original line number Diff line number Diff line
@@ -65,6 +65,38 @@ Browse the base project root folder and execute the following command:

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

## Run configurations (PyCharm)

Two sample configurations have been created:

- one to check if there are syntax or format changes to be done according to Robotidy (`Check Format`)
- one to make the syntax and format changes according to Robotidy (`Format Files`)

To launch a run configuration, choose one of the two configurations from the Run menu and click on it to run it.

## Pre commit

Before each commit, a formatting according to the rules of [Robotidy](https://github.com/MarketSquare/robotframework-tidy)
 is done for files with the `.robot` or `.resource` extension. If nothing has been modified, the commit is done normally.
 Otherwise, the commit displays an error message with all the modifications made by Robotidy to format the file. Modified
 files can then be added to the commit.

To use it, install `pre-commit` with the following commands (using pip):

```$ pip install pre-commit```

Then install the Git hook scripts:

```$ pre-commit install```

Now, it will run automatically on every commit.

To manually launch the tool, the following command can be used:

```$ ./venv/bin/python -m robotidy .```

Further details can be found on the [pre-commit](https://pre-commit.com) site.

## Execute the tests

Configure the context broker URL in the resources/variables.py file
@@ -91,10 +123,6 @@ A sample report can be seen at https://robotmetrics.netlify.app/#

```$ 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)
@@ -103,6 +131,7 @@ A sample report can be seen at https://robotmetrics.netlify.app/#
* [JSON Library](https://github.com/robotframework-thailand/robotframework-jsonlibrary)
* [Requests Library](https://github.com/MarketSquare/robotframework-requests)
* [Deep Diff](https://github.com/seperman/deepdiff)
* [Robotidy Library ](https://github.com/MarketSquare/robotframework-tidy)

# Useful links   

+44 −27
Original line number Diff line number Diff line
*** Settings ***
Documentation     Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved
Documentation       Verify throwing 503 – LdContextNotAvailable error if remote JSON-LD @context cannot be retrieved

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

*** Variable ***

*** Variables ***
${expected_status_code}=        503
${building_id_prefix}=          urn:ngsi-ld:Building:
${building_filename}=           building-unretrievable-context-sample.jsonld
@@ -15,39 +17,52 @@ ${tea_filename}= bus-temporal-representation-unretrievable-context-sample.jso
${registration_id_prefix}=      urn:ngsi-ld:Registration:
${registration_filename}=       csourceRegistrations/context-source-registration-unretrievable-context-sample.jsonld


*** Test Cases ***
043_01 Create entity
    [Documentation]    Verify throwing 503 – LDContextNotAvaliable error if remote JSON-LD @context cannot be retrieved (Create entity)
    [Documentation]    Verify throwing 503 – LdContextNotAvailable 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}
    ${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 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)
    [Documentation]    Verify throwing 503 – LdContextNotAvailable 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 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)
    [Documentation]    Verify throwing 503 – LdContextNotAvailable 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}
    ${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 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)
    [Documentation]    Verify throwing 503 – LdContextNotAvailable 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}
@@ -56,16 +71,18 @@ ${registration_filename}= csourceRegistrations/context-source-registration-un
    @{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 Response Body Containing ProblemDetails Element Containing Type Element set to    ${response}    ${ERROR_TYPE_LD_CONTEXT_NOT_AVAILABLE}
    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]    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)
    [Documentation]    Verify throwing 503 – LdContextNotAvailable 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}
    ${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}
Loading