示例#1
0
def test_ancestor_of() -> None:
    nid1 = "child_parent_region_account_cloud_gcp_1_europe_1_0"
    acc1 = "account_cloud_gcp_1"
    acc2 = "account_cloud_gcp_2"
    g = multi_cloud_graph("account")

    graph = GraphAccess(g)
    assert graph.ancestor_of(nid1, EdgeType.default, "root") is not None
    assert graph.ancestor_of(nid1, EdgeType.delete, "root") is None
    assert graph.ancestor_of(nid1, EdgeType.default, "foo") is None
    assert graph.ancestor_of(nid1, EdgeType.default, "foo") is None
    assert graph.ancestor_of(nid1, EdgeType.default, "account")["id"] == acc1  # type: ignore

    # add another "shorter" edge from acc2 -> nid1, so it is shorter that from acc1 -> nid1
    key = GraphAccess.edge_key(acc2, nid1, EdgeType.default)
    g.add_edge(acc2, nid1, key, edge_type=EdgeType.default)
    assert graph.ancestor_of(nid1, EdgeType.default, "account")["id"] == acc2  # type: ignore
示例#2
0
 def add_edge(from_node: str,
              to_node: str,
              edge_type: str = EdgeType.default) -> None:
     key = GraphAccess.edge_key(from_node, to_node, edge_type)
     graph.add_edge(from_node, to_node, key, edge_type=edge_type)
示例#3
0
 def add_edge(from_node: str, to_node: str, edge_type: str) -> None:
     key = GraphAccess.edge_key(from_node, to_node, edge_type)
     g.add_edge(from_node, to_node, key, edge_type=edge_type)