Beispiel #1
0
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
Beispiel #2
0
def test_match(conf, query, output):
    e = Engine()
    e.insert_bulk(conf)
    assert list(e.query(query)) == output
Beispiel #3
0
def test_collapse_join(conf, query, result):
    e = Engine()
    e.insert_bulk(CONF1)
    list(e.query(query))
    assert e.dump("indent") == result
Beispiel #4
0
def test_not(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
Beispiel #5
0
def test_match_any_vlan(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
Beispiel #6
0
def test_prepared_query(query):
    e = Engine()
    q = e.compile(query)
    e.query(q)
Beispiel #7
0
def test_match_prefix(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
Beispiel #8
0
def test_match(conf, query, output):
    db = ConfDB()
    db.insert_bulk(conf)
    e = Engine().with_db(db)
    assert list(e.query(query)) == output
Beispiel #9
0
def test_fact(conf, input, query, out_conf, output):
    db = ConfDB()
    db.insert_bulk(CONF1)
    e = Engine().with_db(db)
    assert list(e.query(query, **input)) == output
    assert db.marshall("indent") == out_conf