def check_query(query: str, args: Dict[str, Any], expected: List[Dict[str, Any]]) -> bool: """ ConfDB Query result order is undefined, so we need additional helper to check if all results matched :param query: :param args: :param expected: :return: """ e = Engine() left: Dict[int, Dict[str, Any]] = {dict_hash_int(ctx): ctx for ctx in expected} not_found: Set[Dict[str, Any]] = set() for ctx in e.query(query, **args): ctx_hash = dict_hash_int(ctx) if ctx_hash in left: del left[ctx_hash] else: not_found.add(ctx) for ctx_hash in not_found: print("Unexpected return result: %s" % not_found[ctx_hash]) for ctx in left: print("Missed result: %s" % ctx) return not left and not not_found
def event_hash(event: ActiveEvent) -> int: e_vars = { v.name: event.vars.get(v.name, "") or "" for v in event.event_class.vars if v.match_suppress } var_hash = dict_hash_int(event.vars) if e_vars else 0 return hash_int( f"{event.managed_object.id}:{event.event_class.id}:{var_hash}")
def event_hash(event: ActiveEvent) -> int: var_hash = dict_hash_int(event.vars) if event.vars else 0 return hash_int( f"{event.managed_object.id}:{event.event_class.id}:{var_hash}")
def test_dict_hash_int(value, expected): assert dict_hash_int(value) == expected