Commit 9579ff31 authored by Giuseppe Tropea's avatar Giuseppe Tropea
Browse files

Merge remote-tracking branch 'origin/feature/tcs-count-parameter' into parsespec

parents d9b8479a 6934e88f
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
*** Settings ***
Documentation       If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results.

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

Suite Setup         Setup Initial Entities
Suite Teardown      Delete Initial Entities
Test Template       Check that the total number of matching results is returned if the count parameter is set to true


*** Variables ***
${building_id_prefix}=          urn:ngsi-ld:Building:
${first_entity_filename}=       building-simple-attributes-sample.jsonld
${second_entity_filename}=      building-simple-attributes-second-sample.jsonld
${entity_type}=                 Building
${airQualityLevel}=             airQualityLevel==6


*** Test Cases ***    Q_PARAMETER    EXPECTED_STATUS    EXPECTED_COUNT
019_07_01 Check that the total number of matching results is returned if the count parameter is set to true and only the entity type is provided
    ${EMPTY}    200    2
019_07_02 Check that the total number of matching results is returned if the count parameter is set to true and a q parameter is provided
    ${airQualityLevel}    200    1


*** Keywords ***
Check that the total number of matching results is returned if the count parameter is set to true
    [Documentation]    If the count parameter is set to true the special HTTP header NGSILD-Results-Count is set in the response and it must contain the total number of matching results.
    [Tags]    e-query    5_7_2    6_3_13
    [Arguments]    ${q}    ${expected_status_code}    ${expected_count}
    ${response}=    Query Entities
    ...    entity_types=${entity_type}
    ...    q=${q}
    ...    count=${True}
    ...    context=${ngsild_test_suite_context}

    Check Response Status Code    ${expected_status_code}    ${response.status_code}
    Check Response Headers Containing NGSILD-Results-Count Equals To    ${expected_count}    ${response.headers}

Setup Initial Entities
    ${first_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${first_entity_id}
    ${create_response1}=    Create Entity Selecting Content Type
    ...    ${first_entity_filename}
    ...    ${first_entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${create_response1.status_code}
    ${second_entity_id}=    Generate Random Entity Id    ${building_id_prefix}
    Set Suite Variable    ${second_entity_id}
    ${create_response2}=    Create Entity Selecting Content Type
    ...    ${second_entity_filename}
    ...    ${second_entity_id}
    ...    ${CONTENT_TYPE_LD_JSON}
    Check Response Status Code    201    ${create_response2.status_code}

Delete Initial Entities
    Delete Entity by Id    ${first_entity_id}
    Delete Entity by Id    ${second_entity_id}
+25 −0
Original line number Diff line number Diff line
{
    "id": "urn:ngsi-ld:Building:randomUUID",
    "type": "Building",
    "name": {
        "type": "Property",
        "value": "Pisa Tower"
    },
    "subCategory": {
        "type": "Property",
        "value": "tourism"
    },
    "airQualityLevel": {
        "type": "Property",
        "value": 6,
        "unitCode": "C62",
        "observedAt": "2020-10-10T16:40:00.000Z"
    },
    "almostFull": {
        "type": "Property",
        "value": true
    },
    "@context": [
        "https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld"
    ]
}
+17 −1
Original line number Diff line number Diff line
@@ -107,7 +107,9 @@ class Checks:
            'Check Response Reason set to':
                Checks.check_response_reason_set_to,
            'Check Response Does Not Contain Body':
                Checks.check_response_does_not_contain_body
                Checks.check_response_does_not_contain_body,
            'Check Response Headers Containing NGSILD-Results-Count Equals To' :
                Checks.check_response_header_contains_ngsild_results_count_equals_to,
        }

        self.args = {
@@ -309,6 +311,11 @@ class Checks:
                'params': ['response'],
                'position': [0]
            }
            ,
            'Check Response Headers Containing NGSILD-Results-Count Equals To': {
                'params': ['expected_result_count' , 'response_headers'],
                'position': [0, 1]
            }
        }

    @staticmethod
@@ -884,6 +891,14 @@ class Checks:
        else:
            raise Exception(f"ERROR, Expected 'expected_value' and 'obtained_value' parameters but received: '{kwargs}'")

    @staticmethod
    def check_response_header_contains_ngsild_results_count_equals_to(kwargs: list) -> str:
        if "ngsild_results_count" in kwargs:
            ngsild_results_count = kwargs['ngsild_results_count']
            return f'Response Header: NGSILD-Results-Count equals to {ngsild_results_count}'
        else:
            raise Exception(f'ERROR, Expected ngsild_results_count but received: {kwargs}')

    def get_checks(self, **kwargs) -> str:
        checking = None

@@ -990,6 +1005,7 @@ if __name__ == "__main__":
                           'Check Created Resources Set To']
                          , status_code=201))
    print()
    print(data.get_checks(checks='Check Response Headers Containing NGSILD-Results-Count Equals To'))

    # Check exceptions
    try:
+6 −4
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ class Requests:
                'params': ['entity_ids', 'entity_types', 'accept',
                           'attrs', 'context', 'geoproperty',
                           'options', 'limit', 'entity_id_pattern',
                           'georel', 'coordinates', 'geometry']
                           'georel', 'coordinates', 'geometry', 'count', 'q']
            },
            'Query Entities Via POST': {
                'positions': [],
@@ -1131,7 +1131,7 @@ class Requests:
        expected_parameters = ['entity_ids', 'entity_types', 'accept',
                               'attrs', 'context', 'geoproperty',
                               'options', 'limit', 'entity_id_pattern',
                               'georel', 'coordinates', 'geometry']
                               'georel', 'coordinates', 'geometry', 'count' , 'q']

        result = [x for x in kwargs if x not in expected_parameters]
        response = "Get Entities Request:"
@@ -1160,8 +1160,10 @@ class Requests:
                    response = f"{response} and\n    Query Parameter: georel set to '{value}'"
                case 'coordinates':
                    response = f"{response} and\n    Query Parameter: coordinates set to '{value}'"
                case 'geometry':
                    response = f"{response} and\n    Query Parameter: geometry set to '{value}'"
                case 'count':
                    response = f"{response} and\n    Query Parameter: count set to '{value}'"
                case 'q':
                    response = f"{response} and\n    Query Parameter: q set to '{value}'"
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")
+7 −0
Original line number Diff line number Diff line
@@ -224,6 +224,13 @@ class TestCIConsumptions(TestCase):

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_019_07(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/QueryEntities/019_07.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/019_07.json'
        difference_file = f'{self.folder_test_suites}/doc/results/out_019_07.json'

        self.common_function(robot_file=robot_file, expected_value=expected_value, difference_file=difference_file)

    def test_018_01_01(self):
        robot_file = f'{self.folder_test_suites}/TP/NGSI-LD/ContextInformation/Consumption/Entity/RetrieveEntity/018_01_01.robot'
        expected_value = f'{self.folder_test_suites}/doc/files/ContextInformation/Consumption/018_01_01.json'
Loading