def test_can_create_node_with_properties(graph): node = Node(name="Alice") statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node, ) assert node.bound
def test_can_create_naked_node(graph): node = Node() statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node,) assert node.bound
def test_can_create_node_with_properties(graph): node = Node(name="Alice") statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node,) assert node.bound
def test_can_create_naked_node(graph): node = Node() statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node, ) assert node.bound
def test_cannot_create_uncastable_type(graph): statement = CreateStatement(graph) try: statement.create("this is not a valid thing to create") except TypeError: assert True else: assert False
def test_cannot_create_none(graph): statement = CreateStatement(graph) try: statement.create(None) except TypeError: assert True else: assert False
def test_can_create_node_with_label(graph): if not graph.supports_node_labels: return node = Node("Person", name="Alice") statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node, ) assert node.bound
def test_can_create_node_with_label(graph): if not graph.supports_node_labels: return node = Node("Person", name="Alice") statement = CreateStatement(graph) statement.create(node) created = statement.execute() assert created == (node,) assert node.bound
def test_cannot_use_a_pointer_that_is_out_of_range(graph): broken_relationship = Relationship(10, "KNOWS", 11) statement = CreateStatement(graph) try: statement.create(broken_relationship) except IndexError: assert True else: assert False
def test_can_create_a_relationship_to_two_existing_nodes(graph): alice = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a") bob = graph.cypher.execute_one("CREATE (b {name:'Bob'}) RETURN b") alice_knows_bob = Relationship(alice, "KNOWS", bob) statement = CreateStatement(graph) statement.create(alice_knows_bob) created = statement.execute() assert created == (alice_knows_bob,) assert alice_knows_bob.bound assert alice_knows_bob.start_node is alice assert alice_knows_bob.end_node is bob
def test_can_create_a_relationship_to_two_existing_nodes(graph): alice = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a") bob = graph.cypher.execute_one("CREATE (b {name:'Bob'}) RETURN b") alice_knows_bob = Relationship(alice, "KNOWS", bob) statement = CreateStatement(graph) statement.create(alice_knows_bob) created = statement.execute() assert created == (alice_knows_bob, ) assert alice_knows_bob.bound assert alice_knows_bob.start_node is alice assert alice_knows_bob.end_node is bob
def test_can_create_two_nodes_and_a_unique_relationship(graph): alice = Node(name="Alice") bob = Node(name="Bob") alice_knows_bob = Relationship(alice, "KNOWS", bob) statement = CreateStatement(graph) statement.create(alice) statement.create(bob) statement.create_unique(alice_knows_bob) created = statement.execute() assert created == (alice, bob, alice_knows_bob) assert alice.bound assert bob.bound assert alice_knows_bob.bound assert alice_knows_bob.start_node is alice assert alice_knows_bob.end_node is bob
def test_can_create_a_path_with_existing_nodes(graph): alice = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a") bob = Node(name="Bob") carol = graph.cypher.execute_one("CREATE (c {name:'Carol'}) RETURN c") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) statement = CreateStatement(graph) statement.create(path) created = statement.execute() assert created == (path,) assert bob.bound assert dave.bound ab, cb, cd = path.relationships assert ab.start_node is alice assert ab.end_node is bob assert cb.start_node is carol assert cb.end_node is bob assert cd.start_node is carol assert cd.end_node is dave
def test_can_create_a_path_with_existing_nodes(graph): alice = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a") bob = Node(name="Bob") carol = graph.cypher.execute_one("CREATE (c {name:'Carol'}) RETURN c") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) statement = CreateStatement(graph) statement.create(path) created = statement.execute() assert created == (path, ) assert bob.bound assert dave.bound ab, cb, cd = path.relationships assert ab.start_node is alice assert ab.end_node is bob assert cb.start_node is carol assert cb.end_node is bob assert cd.start_node is carol assert cd.end_node is dave
def test_can_create_an_entirely_new_path(graph): alice = Node(name="Alice") bob = Node(name="Bob") carol = Node(name="Carol") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) statement = CreateStatement(graph) statement.create(path) created = statement.execute() assert created == (path,) assert alice.bound assert bob.bound assert carol.bound assert dave.bound ab, cb, cd = path.relationships assert ab.start_node is alice assert ab.end_node is bob assert cb.start_node is carol assert cb.end_node is bob assert cd.start_node is carol assert cd.end_node is dave
def test_can_create_an_entirely_new_path(graph): alice = Node(name="Alice") bob = Node(name="Bob") carol = Node(name="Carol") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) statement = CreateStatement(graph) statement.create(path) created = statement.execute() assert created == (path, ) assert alice.bound assert bob.bound assert carol.bound assert dave.bound ab, cb, cd = path.relationships assert ab.start_node is alice assert ab.end_node is bob assert cb.start_node is carol assert cb.end_node is bob assert cd.start_node is carol assert cd.end_node is dave
def test_cannot_use_a_pointer_that_does_not_refer_to_a_node(graph): alice = Node(name="Alice") bob = Node(name="Bob") alice_knows_bob = Relationship(0, "KNOWS", 1) broken_relationship = Relationship(0, "KNOWS", 2) statement = CreateStatement(graph) statement.create(alice) statement.create(bob) statement.create(alice_knows_bob) try: statement.create(broken_relationship) except ValueError: assert True else: assert False
def test_can_pass_entities_that_already_exist(graph): results = graph.cypher.stream("CREATE (a)-[ab:KNOWS]->(b) RETURN a, ab, b") alice, alice_knows_bob, bob = next(results).values statement = CreateStatement(graph) statement.create(alice) statement.create(bob) statement.create(alice_knows_bob) created = statement.execute() assert created == (alice, bob, alice_knows_bob)
# Relationship(nodes["b"], "RELATIONSHIP", nodes["c"]), # Relationship(nodes["b"], "RELATIONSHIP", nodes["d"]), # Relationship(nodes["b"], "RELATIONSHIP", nodes["e"]), # Relationship(nodes["c"], "RELATIONSHIP", nodes["e"]), # Relationship(nodes["d"], "RELATIONSHIP", nodes["c"]), # Relationship(nodes["d"], "RELATIONSHIP", nodes["f"]), # Relationship(nodes["e"], "RELATIONSHIP", nodes["g"]), # Relationship(nodes["e"], "RELATIONSHIP", nodes["f"]), # Relationship(nodes["f"], "RELATIONSHIP", nodes["g"]), # Relationship(nodes["g"], "RELATIONSHIP", nodes["a"])] builder = CreateStatement(graph) # graph.create(nodeDict.values()) for node in nodes.values(): builder.create(node) for edge in edges: builder.create(edge) builder.execute() def edge_query(source, target): return ( "MATCH (source:NETWORK_NODE {id: '" + source + "'}) " "MATCH (target:NETWORK_NODE {id: '" + target + "'}) " "MERGE (source)-[rel:EDGE]->(target) " 'ON CREATE SET rel._isSetEdge=true, rel.pathways=["hsa02"], rel.try=true ' 'ON MATCH SET rel._isSetEdge=true, rel.pathways= CASE WHEN NOT (HAS (rel.pathways)) THEN ["hsa02"] ELSE rel.pathways + ["hsa02", "hsa03"] END, rel.try=true ' )
# Relationship(nodes["b"], "RELATIONSHIP", nodes["c"]), # Relationship(nodes["b"], "RELATIONSHIP", nodes["d"]), # Relationship(nodes["b"], "RELATIONSHIP", nodes["e"]), # Relationship(nodes["c"], "RELATIONSHIP", nodes["e"]), # Relationship(nodes["d"], "RELATIONSHIP", nodes["c"]), # Relationship(nodes["d"], "RELATIONSHIP", nodes["f"]), # Relationship(nodes["e"], "RELATIONSHIP", nodes["g"]), # Relationship(nodes["e"], "RELATIONSHIP", nodes["f"]), # Relationship(nodes["f"], "RELATIONSHIP", nodes["g"]), # Relationship(nodes["g"], "RELATIONSHIP", nodes["a"])] builder = CreateStatement(graph) # graph.create(nodeDict.values()) for node in nodes.values(): builder.create(node) for edge in edges: builder.create(edge) builder.execute() def edge_query(source, target): return ( "MATCH (source:NETWORK_NODE {id: '" + source + "'}) " "MATCH (target:NETWORK_NODE {id: '" + target + "'}) " "MERGE (source)-[rel:EDGE]->(target) " "ON CREATE SET rel._isSetEdge=true, rel.pathways=[\"hsa02\"], rel.try=true " "ON MATCH SET rel._isSetEdge=true, rel.pathways= CASE WHEN NOT (HAS (rel.pathways)) THEN [\"hsa02\"] ELSE rel.pathways + [\"hsa02\", \"hsa03\"] END, rel.try=true " )
def test_statement_representation_returns_cypher(graph): node = Node() statement = CreateStatement(graph) statement.create(node) rep = repr(statement) assert rep == 'CREATE (_0)\nRETURN _0'