示例#1
0
def _get_output_from_query_validators(output, query):
    # the function determines the type of query and returns the appropriate result
    ret_dict = {}
    # if it is a valid dq query than apply the query and return the output
    if Dq.query_validator(query):
        output = Dq.str_to_dq_query(output, query)
        ret_dict.update({
            'action_output': output,
            'query_type': 'dq_query',
            'operation': None,
            'expected_value': None
        })
    else:
        # check for the string query
        output = _string_query_validator(output, query)
        action_output = output['right_hand_value']
        operation = output['operation']
        value = output['left_hand_value']
        ret_dict.update({
            'action_output': action_output,
            'query_type': 'non_dq_query',
            'operation': operation,
            'expected_value': value
        })

    return ret_dict
示例#2
0
def apply_dictionary_filter(self, output, filters=None):
    #filtering the action output
    if not filters or \
       not isinstance(output, dict) or \
       not Dq.query_validator(filters):
        return output

    return Dq.str_to_dq_query(output, filters)
示例#3
0
def filter_variable(self, output, filters=None):
    #filtering the action output
    if not filters:
        return output

    if not isinstance(output, dict) or not Dq.query_validator(filters):
        return output

    return Dq.str_to_dq_query(output, filters)
示例#4
0
    def dq_query(self, data, filters):
        ''' Search dictionary using Dq filters

        Examples:

        .. code:: robotframework

            dq query    data=${data}   filters=contains('lc').not_contains('2').get_values('slot/world_wide_name')

        :param data: dictionary with data
        :param filters: Dq filter specification
        :return: dictionary, list, str or int

        '''
        if not isinstance(data, dict):
            raise GenieRobotException('Invalid data, dictionary expected, got %s' % type(data))
        if not Dq.query_validator(filters):
            raise GenieRobotException('Invalid filter')

        return Dq.str_to_dq_query(data, filters)
示例#5
0
def _get_output_from_query_validators(output, query):
    """the function determines the type of query and
       returns the appropriate result"""

    ret_dict = {}
    # if it is a valid dq query than apply the query and return the output
    if Dq.query_validator(query):
        output = Dq.str_to_dq_query(output, query)
        ret_dict.update({
            'action_output': output,
            'query_type': 'dq_query',
            'operation': None,
            'expected_value': None
        })
    # if the query is itself a dictionary
    elif isinstance(query, (dict, list)):
        # output could of of type dict/QDict
        # NOTE: QDict is the type of the parser output
        if isinstance(output, QDict):
            output = dict(output)

        ret_dict.update({
            'action_output': output,
            'query_type': 'non_dq_query',
            'operation': '',
            'expected_value': query
        })
    else:
        # check for the string query
        output = _string_query_validator(output, query)
        action_output = output['right_hand_value']
        operation = output['operation']
        value = output['left_hand_value']
        ret_dict.update({
            'action_output': action_output,
            'query_type': 'non_dq_query',
            'operation': operation,
            'expected_value': value
        })

    return ret_dict