'Given a user defined definition, compare it with the results given back by our query.'

@staticmethod
def check_def_equal(user_def, result_def, skip_keys=None, debug=False):

    skip = ['metadata', 'status']
    if skip_keys:
        skip.extend(skip_keys)
    for (key, value) in result_def.items():
        if (key in skip):
            continue
        if isinstance(value, list):
            if (key not in user_def):
                if debug:
                    print(('User    data    does    not    have    key    [%s]' % key))
                    print(('User    data:    %s' % user_def))
                return False
            if (not isinstance(user_def[key], list)):
                if debug:
                    print(('user_def[key]    is    not    a    list    key=[%s]    user_def[key]=%s' % (key, user_def[key])))
                return False
            if (len(user_def[key]) != len(value)):
                if debug:
                    print('List    lengths    are    not    equal.')
                    print(('key=[%s]:    user_def[%s]    !=    value[%s]' % (key, len(user_def[key]), len(value))))
                    print(('user_def:    %s' % user_def[key]))
                    print(('value:    %s' % value))
                return False
            for values in zip(user_def[key], value):
                if (isinstance(values[0], dict) and isinstance(values[1], dict)):
                    if debug:
                        print('sending    list    -    list')
                        print(type(values[0]))
                        print(type(values[1]))
                    result = Utils.check_def_equal(values[0], values[1], skip_keys=skip_keys, debug=debug)
                    if (not result):
                        print('list    compare    returned    false')
                        return False
                elif (value != user_def[key]):
                    if debug:
                        print('value    should    be    identical')
                        print(user_def[key])
                        print(value)
                    return False
        elif isinstance(value, dict):
            if (key not in user_def):
                if debug:
                    print(('user_def    does    not    have    key    [%s]' % key))
                return False
            if (not isinstance(user_def[key], dict)):
                if debug:
                    print('dict    returned    false:    not    instance    of    dict')
                return False
            api_values = (set(value.keys()) - set(skip))
            user_values = (set(user_def[key].keys()) - set(skip))
            if (api_values != user_values):
                if debug:
                    print('keys    are    not    equal    in    dict')
                    print(user_values)
                    print(api_values)
                return False
            result = Utils.check_def_equal(user_def[key], value, skip_keys=skip_keys, debug=debug)
            if (not result):
                if debug:
                    print('dict    returned    false')
                    print(result)
                return False
        elif ((key not in user_def) or (value != user_def[key])):
            if debug:
                print('value    not    equal;    user_def    does    not    have    key')
                print(key)
                print(value)
                if (key in user_def):
                    print(user_def[key])
            return False
    if debug:
        print('returning    true')
    return True
