Commit b53a381f authored by lopezaguilar's avatar lopezaguilar
Browse files

Update doc for 044_03, 044_04, 044_05

parent a3a715f9
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ ${subscription_filename}= csourceSubscriptions/subscription-sample.jsonld


*** Test Cases ***
044_04_01_endpoint get /entities/{entityId}
044_04_01 endpoint get /entities/{entityId}
    [Documentation]    Verify throwing 406 HTTP status code (Not Acceptable Media Type) if the "Accept" header does not imply "application/json" nor "application/ld+json" (get /entities/{entityId})
    [Tags]    e-query    6_3_4
    ${entity_id}=    Generate Random Entity Id    ${building_id_prefix}
@@ -29,7 +29,7 @@ ${subscription_filename}= csourceSubscriptions/subscription-sample.jsonld
    Check Response Status Code    ${status_code}    ${response.status_code}
    [Teardown]    Delete Entity by Id Returning Response    ${entity_id}

044_04_02_endpoint get /subscriptions/{subscriptionId}
044_04_02 endpoint get /subscriptions/{subscriptionId}
    [Documentation]    Verify throwing 406 HTTP status code (Not Acceptable Media Type) if the "Accept" header does not imply "application/json" nor "application/ld+json" (get /subscriptions/{subscriptionId})
    [Tags]    sub-retrieve    6_3_4
    ${id}=    Generate Random Entity Id    ${subscription_id_prefix}
@@ -39,19 +39,19 @@ ${subscription_filename}= csourceSubscriptions/subscription-sample.jsonld
    Check Response Status Code    ${status_code}    ${response.status_code}
    [Teardown]    Delete Subscription    ${id}

044_04_03_endpoint get /csourceRegistrations/
044_04_03 endpoint get /csourceRegistrations/
    [Documentation]    Verify throwing 406 HTTP status code (Not Acceptable Media Type) if the "Accept" header does not imply "application/json" nor "application/ld+json" (get /csourceRegistrations/)
    [Tags]    csr-query    6_3_4
    ${response}=    Query Context Source Registrations With Return    type=Building    accept=${accept}
    Check Response Status Code    ${status_code}    ${response.status_code}

044_04_04_endpoint get /csourceSubscriptions/
044_04_04 endpoint get /csourceSubscriptions/
    [Documentation]    Verify throwing 406 HTTP status code (Not Acceptable Media Type) if the "Accept" header does not imply "application/json" nor "application/ld+json" (get /csourceSubscriptions/)
    [Tags]    csrsub-query
    Query Context Source Registration Subscriptions    accept=${accept}
    ${response}=    Query Context Source Registration Subscriptions    accept=${accept}
    Check Response Status Code    ${status_code}    ${response.status_code}

044_04_05_endpoint get /temporal/entities
044_04_05 endpoint get /temporal/entities
    [Documentation]    Verify throwing 406 HTTP status code (Not Acceptable Media Type) if the "Accept" header does not imply "application/json" nor "application/ld+json" (get /temporal/entities)
    [Tags]    te-query    6_3_4
    ${entity_types_to_be_retrieved}=    Catenate    SEPARATOR=,    Vehicle
+6 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@ import re

class GenerateRobotData:
    def __init__(self, robot_file: str, execdir: str):
        self.robot_file = robot_file
        self.execdir = execdir

        self.config_variables = ParseVariablesFile()
        self.robot = ParseRobotFile(filename=robot_file, execdir=execdir, config_file=self.config_variables)
        self.apiutil = ParseApiUtilsFile(filename=self.robot.resource_file)
@@ -46,6 +49,9 @@ class GenerateRobotData:
        self.base_TP_id = str()

    def get_info(self):
        self.test_suite['robotpath'] = (self.robot_file.replace(f'{self.execdir}/TP/NGSI-LD/', '')
                                        .replace(f'/{self.robot.test_suite}.robot', ''))
        self.test_suite['robotfile'] = self.robot.test_suite
        return self.test_suite

    def parse_robot(self):
+84 −38
Original line number Diff line number Diff line
@@ -25,16 +25,16 @@ class Requests:
                'params': ['filename']
            },
            'Query Entity': {
                'positions': [1],
                'params': ['context']
                'positions': [1, 1],
                'params': ['context', 'accept']
            },
            'Retrieve Subscription': {
                'positions': [],
                'params': []
                'positions': [1],
                'params': ['accept']
            },
            'Query Context Source Registrations With Return': {
                'positions': [],
                'params': []
                'positions': [0, 1],
                'params': ["type", "accept"]
            },
            'Query Temporal Representation Of Entities With Return': {
                'positions': [],
@@ -48,9 +48,17 @@ class Requests:
                'positions': [1, 2, 3],
                'params': ['filename', 'content', 'context']

            },
            'Query Context Source Registration Subscriptions': {
                'positions': [0],
                'params': ['accept']
            },
            'Query Temporal Representation Of Entities': {
                'positions': [0, 1, 2, 3],
                'params': ['entity_types', 'timerel', 'timeAt', 'accept']
            }

        }

        self.description = {
            'Create Entity Selecting Content Type':
                Requests.create_entity_selecting_content_type,
@@ -73,8 +81,13 @@ class Requests:
            'Partial Update Entity Attributes':
                Requests.partial_update_entity_attributes,
            'Update Subscription':
                Requests.update_subscription
                Requests.update_subscription,
            'Query Context Source Registration Subscriptions':
                Requests.query_context_source_registration_subscriptions,
            'Query Temporal Representation Of Entities':
                Requests.query_temporal_representation_of_entities
            }

        self.variables = variables
        self.apiutils_variables = apiutils_variables
        self.config_file = config_file
@@ -136,25 +149,6 @@ class Requests:

            params = self.find_attributes_in_the_same_line(request_name=request, params=params)

        # return request, params
        # Previous version
        # index = None
        # for k in keys:
        #     index = string.find(k)
        #     if index != -1:
        #         break
        #
        # pattern = f"^.*{k}.*\n"
        # lines_starting_with_request = re.findall(pattern, string, re.MULTILINE)
        # for line in lines_starting_with_request:
        #     data = line.strip().split("    ")
        #     if len(data) == 2:
        #         # We are in multiline definition
        #         params = self.find_attributes_next_line(string=string, position=index, request_name=k)
        #     else:
        #         # The definition of the request is in the same line
        #         params = self.find_attributes_in_the_same_line(request_name=k, params=data[1:])

        description = self.description[request](params)
        return description

@@ -218,18 +212,38 @@ class Requests:

    @staticmethod
    def query_entity(kwargs) -> str:
        if 'context' in kwargs:
        result = ''
        if 'context' in kwargs and kwargs['context'] != '':
            result = f"Request Header['Link'] contain the context {kwargs['context']}"
            return result
        else:

        if 'accept' in kwargs:
            result = f"{result}\nHeader['Accept'] set to {kwargs['accept']}"

        if 'context' not in kwargs and 'accept' not in kwargs:
            raise Exception(f"ERROR, expected context attribute, but received {kwargs}")

        return result

    @staticmethod
    def retrieve_subscription(kwargs) -> str:
        if 'accept' in kwargs:
            return f"Request a subscription\nHeader['Accept'] set to '{kwargs['accept']}'"
        else:
            return "Request a subscription"

    def query_context_source_registrations_with_return(kwargs) -> str:
        return "Request a Context Source Registration with Return"
        if 'type' in kwargs and 'accept' in kwargs:
            result = "Request a Context Source Registration with Return"

            if kwargs['type'] != '':
                result = f"{result}\nEntity Type set to '{kwargs['type']}'"

            if kwargs['accept'] != '':
                result = f"{result}\nHeader['Accept'] set to '{kwargs['accept']}'"
        else:
            result = "Request a Context Source Registration with Return"

        return result

    def query_temporal_representation_of_entities_with_return(kwargs) -> str:
        return "Request a Temporal Representation of Entities with Return"
@@ -264,19 +278,51 @@ class Requests:
        else:
            raise Exception(f"ERROR, expected context attribute, but received {kwargs}")

    @staticmethod
    def query_context_source_registration_subscriptions(kwargs) -> str:
        if 'accept' in kwargs:
            return (f"Request Context Source Registration Subscriptions\n"
                    f"Header['Accept'] set to '{kwargs['accept']}'")
        else:
            raise Exception(f"ERROR, expected accept attribute, but received {kwargs}")

    @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:
            raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
                            f"'{expected_parameters}', but received: {kwargs}")

    def get_value(self, params, param_position, param_key):
        try:
            data = params[param_position]
        except IndexError:
            return ''
        data = [x for x in params if f'{param_key}=' in x]

        if '=' in data:
        if len(data) == 1:
            # The name of the attribute is passed to the function in the form attribute=value
            data = data[0]
            data = data.split('=')
            if data[0] != param_key:
                raise Exception(f"ERROR, uncontrolled param_key: {params} {param_key}")
                return ''

            data = data[1]
        elif len(data) == 0:
            # There is no attribute=something therefore we have to apply the position
            try:
                data = params[param_position]

                # Workaround
                if 'accept' in data and param_key != 'accept':
                    data = ''
            except IndexError:
                return ''

        try:
            value = self.variables[data]
+3 −1
Original line number Diff line number Diff line
@@ -94,5 +94,7 @@
    "endpoint",
    "when",
    "then"
  ]
  ],
  "robotpath": "CommonBehaviours",
  "robotfile": "043"
}
 No newline at end of file
+5 −3
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@
      "teardown": "Delete Entity by Id",
      "template": null,
      "then": "then {\n    the SUT sends a valid Response containing:\n        Response Status Code set to 204\n}",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entities/{entityId}/attrs/{attributeId}'\n        method set to 'PATCH'\n        Request Update Entity Attributes and \nHeader['Link'] contain the context 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld' and \nHeader['Content-Type'] set to 'application/merge-patch+json' and\nPayload defined in file 'vehicle-brandname-fragment.json'",
      "when": "when {\n    the SUT receives a Request from the client containing:\n        URL set to '/ngsi-ld/v1/entities/{entityId}/attrs/{attributeId}'\n        method set to 'PATCH'\n        Request Partial Update Entity Attributes and \nHeader['Link'] contain the context 'https://forge.etsi.org/rep/cim/ngsi-ld-test-suite/-/raw/develop/resources/jsonld-contexts/ngsi-ld-test-suite-compound.jsonld' and \nHeader['Content-Type'] set to 'application/merge-patch+json' and\nPayload defined in file 'vehicle-brandname-fragment.json'",
      "http_verb": "PATCH",
      "endpoint": "entities/{entityId}/attrs/{attributeId}"
    },
@@ -45,5 +45,7 @@
  "permutations": [
    "when",
    "endpoint"
  ]
  ],
  "robotpath": "CommonBehaviours",
  "robotfile": "044_01"
}
 No newline at end of file
Loading