Commit 8be64a33 authored by lopezaguilar's avatar lopezaguilar
Browse files

Resolution of the problematic with 'Query Temporal Representation Of Entities'

parent 2b04742c
Loading
Loading
Loading
Loading
+71 −20
Original line number Diff line number Diff line
@@ -54,8 +54,12 @@ class Requests:
                'params': ['accept']
            },
            'Query Temporal Representation Of Entities': {
                'positions': [0, 1, 2, 3],
                'params': ['entity_types', 'timerel', 'timeAt', 'accept']
                'positions': [],
                'params': ['context', 'entity_types', 'entity_ids', 'entity_id_pattern',
                           'ngsild_query', 'csf', 'georel', 'geometry',
                           'coordinates', 'geoproperty', 'timerel', 'timeAt',
                           'attrs', 'limit', 'lastN', 'accept']

            },
            'Retrieve Attribute': {
                'positions': [0],
@@ -175,6 +179,12 @@ class Requests:

    def find_attributes_in_the_same_line(self, request_name, params):
        param = dict()
        if len(self.op[request_name]['positions']) == 0:
            # We do not know the position of the different parameters and the order in which they are received,
            # therefore in these cases all the parameters have identified the corresponding name
            param = {x.split('=')[0]: self.get_value_simple(x.split('=')[1]) for x in params}

        else:
            for i in range(0, len(self.op[request_name]['positions'])):
                param_position = self.op[request_name]['positions'][i]
                param_key = self.op[request_name]['params'][i]
@@ -309,20 +319,58 @@ class Requests:

    @staticmethod
    def query_temporal_representation_of_entities(kwargs) -> str:
        expected_parameters = ['entity_types', 'timerel', 'timeAt', 'accept']
        result = [x for x in expected_parameters if x not in kwargs]

        if len(result) == 0:
            response = ("Response containing:\n"
                        f"    * Entity-Type is equal to '{kwargs['entity_types']}'\n"
                        f"    * timeRel is equal to '{kwargs['timerel']}'\n"
                        f"    * timeAt is equal to '{kwargs['timeAt']}'\n"
                        f"    * Accept is equal to '{kwargs['accept']}'")
            return response
        else:
        # This function is a little bit special because we have a number of parameters not always defined and not always
        # in the same position, so we make a different analysis to extract the values
        expected_parameters = ['context', 'entity_types', 'entity_ids', 'entity_id_pattern',
                               'ngsild_query', 'csf', 'georel', 'geometry',
                               'coordinates', 'geoproperty', 'timerel', 'timeAt',
                               'attrs', 'limit', 'lastN', 'accept']

        result = [x for x in kwargs if x not in expected_parameters]
        response = ""
        for key, value in kwargs.items():
            match key:
                case 'context':
                    response = f"{response} and\n    Query Parameter: context set to '{value}'"
                case 'entity_types':
                    response = f"{response} and\n    Query Parameter: entity_types set to '{value}'"
                case 'entity_ids':
                    response = f"{response} and\n    Query Parameter: entity_ids set to '{value}'"
                case 'entity_id_pattern':
                    response = f"{response} and\n    Query Parameter: entity_id_pattern set to '{value}'"
                case 'ngsild_query':
                    response = f"{response} and\n    Query Parameter: ngsild_query set to '{value}'"
                case 'csf':
                    response = f"{response} and\n    Query Parameter: csf set to '{value}'"
                case 'georel':
                    response = f"{response} and\n    Query Parameter: georel set to '{value}'"
                case 'geometry':
                    response = f"{response} and\n    Query Parameter: geometry set to '{value}'"
                case 'coordinates':
                    response = f"{response} and\n    Query Parameter: coordinates set to '{value}'"
                case 'geoproperty':
                    response = f"{response} and\n    Query Parameter: geoproperty set to '{value}'"
                case 'timerel':
                    response = f"{response} and\n    Query Parameter: timerel set to '{value}'"
                case 'timeAt':
                    response = f"{response} and\n    Query Parameter: timeAt set to '{value}'"
                case 'attrs':
                    response = f"{response} and\n    Query Parameter: attrs set to '{value}'"
                case 'limit':
                    response = f"{response} and\n    Query Parameter: limit set to '{value}'"
                case 'lastN':
                    value = re.search(pattern=r'\d+', string=value).group()
                    response = f"{response} and\n    Query Parameter: lastN set to '{value}'"
                case 'accept':
                    response = f"{response} and\n    Query Parameter: accept set to '{value}'"

            # If an exact match is not confirmed, this last case will be used if provided
                case _:
                    raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                                    f"'{expected_parameters}', but received: {kwargs}")

        return response

    @staticmethod
    def retrieve_attribute(kwargs) -> str:
        if 'attribute_name' in kwargs:
@@ -378,6 +426,9 @@ class Requests:
            except IndexError:
                return ''

        return self.get_value_simple(data=data)

    def get_value_simple(self, data):
        try:
            value = self.variables[data]
            return value
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@
      "teardown": null,
      "template": null,
      "then": "then {\n    the SUT sends a valid Response containing:\n        Response Status Code set to 406\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n        Response containing:\n    * Entity-Type is equal to '${entity_types_to_be_retrieved}'\n    * timeRel is equal to 'after'\n    * timeAt is equal to '2020-08-01T12:05:00Z'\n    * Accept is equal to 'application/xml'\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n         and\n    Query Parameter: entity_types set to '${entity_types_to_be_retrieved}' and\n    Query Parameter: timerel set to 'after' and\n    Query Parameter: timeAt set to '2020-08-01T12:05:00Z' and\n    Query Parameter: accept set to 'application/xml'\n}",
      "http_verb": "GET",
      "endpoint": "temporal/entities"
    }
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
      "teardown": null,
      "template": null,
      "then": "then {\n    the SUT sends a valid Response containing:\n        Response Status Code set to 406\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n        Response containing:\n    * Entity-Type is equal to '${entity_types_to_be_retrieved}'\n    * timeRel is equal to 'after'\n    * timeAt is equal to '2020-08-01T12:05:00Z'\n    * Accept is equal to 'application/geo+json'\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n         and\n    Query Parameter: entity_types set to '${entity_types_to_be_retrieved}' and\n    Query Parameter: timerel set to 'after' and\n    Query Parameter: timeAt set to '2020-08-01T12:05:00Z' and\n    Query Parameter: accept set to 'application/geo+json'\n}",
      "http_verb": "GET",
      "endpoint": "temporal/entities"
    },
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
      "teardown": null,
      "template": null,
      "then": "then {\n    the SUT sends a valid Response containing:\n        Request response body containing a list that contains Entity Temporal Elements\n    compared with file 'vehicles-temporal-representation-021-02-expectation.jsonld'\n    and using the list of entity ids define in '${temporal_entities_representation_ids}' and\n        Response Status Code set to 200\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n        Response containing:\n    * Entity-Type is equal to '${entity_types_to_be_retrieved}'\n    * timeRel is equal to 'after'\n    * timeAt is equal to '2020-07-01T12:05:00Z'\n    * Accept is equal to 'attrs=${temporal_attributes_to_be_retrieved}'\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n         and\n    Query Parameter: entity_types set to '${entity_types_to_be_retrieved}' and\n    Query Parameter: timerel set to 'after' and\n    Query Parameter: timeAt set to '2020-07-01T12:05:00Z' and\n    Query Parameter: attrs set to '${temporal_attributes_to_be_retrieved}' and\n    Query Parameter: context set to 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld'\n}",
      "http_verb": "GET",
      "endpoint": "temporal/entities"
    }
+35 −0
Original line number Diff line number Diff line
{
  "tp_id": "TP/NGSI-LD/CI/Cons/TE/021_03",
  "test_objective": "Check that you can query the temporal evolution of the last N instances of entities attributes",
  "reference": "ETSI GS CIM 009 V1.3.1 [], clause 5.7.4",
  "config_id": "",
  "parent_release": "v1.3.1",
  "pics_selection": "PICS_5_7_4",
  "keywords": [
    "Setup Initial Entities",
    "Delete Initial Entities"
  ],
  "teardown": "Delete Initial Entities",
  "initial_condition": "with {\n    the SUT in the \"initial state\"\n}",
  "test_cases": [
    {
      "name": "021_03_01 Query the temporal evolution of the last N instances of entities attributes",
      "permutation_tp_id": "TP/NGSI-LD/CI/Cons/TE/021_03_01",
      "doc": "Check that you can query the temporal evolution of the last N instances of entities attributes",
      "tags": [
        "5_7_4",
        "te-query"
      ],
      "setup": null,
      "teardown": null,
      "template": null,
      "then": "then {\n    the SUT sends a valid Response containing:\n        Request response body containing a list that contains Entity Temporal Elements\n    compared with file 'vehicles-temporal-representation-021-03-expectation.jsonld'\n    and using the list of entity ids define in '${temporal_entities_representation_ids}' and\n        Response Status Code set to 200\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/temporal/entities'\n        method set to 'GET'\n         and\n    Query Parameter: entity_types set to '${entity_types_to_be_retrieved}' and\n    Query Parameter: timerel set to 'after' and\n    Query Parameter: timeAt set to '2020-07-01T12:05:00Z' and\n    Query Parameter: lastN set to '14' and\n    Query Parameter: context set to 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld'\n}",
      "http_verb": "GET",
      "endpoint": "temporal/entities"
    }
  ],
  "permutations": [],
  "robotpath": "ContextInformation/Consumption/TemporalEntity/QueryTemporalEvolutionOfEntities",
  "robotfile": "021_03"
}
 No newline at end of file
Loading