Skip to content
requests.py 51.5 KiB
Newer Older
lopezaguilar's avatar
lopezaguilar committed
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type 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

lopezaguilar's avatar
lopezaguilar committed
    @staticmethod
    def append_entity_attributes(kwargs) -> str:
        expected_parameters = ['id', 'fragment_filename', 'content_type']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Append Entity Attributes'
        for key, value in kwargs.items():
            match key:
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type 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 update_entity_attributes(kwargs) -> str:
        expected_parameters = ['id', 'fragment_filename', 'content_type']

        result = [x for x in kwargs if x not in expected_parameters]
        response = 'Update Entity Attributes'
        for key, value in kwargs.items():
            match key:
                case 'id':
                    response = f"{response} and\n    Query Parameter: id set to '{value}'"
                case 'fragment_filename':
                    response = f"{response} and\n    Query Parameter: fragment_filename set to '{value}'"
                case 'content_type':
                    response = f"{response} and\n    Query Parameter: content_type 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

    def get_value(self, params, param_position, param_key):
        data = [x for x in params if f'{param_key}=' in x]
        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:
        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 ''
        return self.get_value_simple(data=data)

    def get_value_simple(self, data):
            value = self.variables[data]
            return value
        except KeyError:
            try:
                value = self.apiutils_variables[data]
                return value
            except KeyError:
                try:
                    value = self.config_file.get_variable(variable=data)
                    return value
                except KeyError:
lopezaguilar's avatar
lopezaguilar committed
                    try:
                        aux = self.template_params_value[self.name]
                        value = aux[data]
                        return value
                    except KeyError:
                        return data