コード例 #1
0
def test_cannot_create_unique_node(graph):
    node = Node(name="Alice")
    statement = CreateStatement(graph)
    try:
        statement.create_unique(node)
    except TypeError:
        assert True
    else:
        assert False
コード例 #2
0
def test_cannot_create_unique_node(graph):
    node = Node(name="Alice")
    statement = CreateStatement(graph)
    try:
        statement.create_unique(node)
    except TypeError:
        assert True
    else:
        assert False
コード例 #3
0
def test_cannot_create_unique_zero_length_path(graph):
    path = Path(Node())
    statement = CreateStatement(graph)
    try:
        statement.create_unique(path)
    except ValueError:
        assert True
    else:
        assert False
コード例 #4
0
def test_cannot_create_unique_zero_length_path(graph):
    path = Path(Node())
    statement = CreateStatement(graph)
    try:
        statement.create_unique(path)
    except ValueError:
        assert True
    else:
        assert False
コード例 #5
0
def test_a_unique_relationship_is_really_unique(graph):
    results = graph.cypher.stream("CREATE (a)-[ab:KNOWS]->(b) RETURN a, ab, b")
    alice, alice_knows_bob, bob = next(results).values
    assert alice.degree == 1
    assert bob.degree == 1
    statement = CreateStatement(graph)
    statement.create_unique(Relationship(alice, "KNOWS", bob))
    statement.execute()
    assert alice.degree == 1
    assert bob.degree == 1
コード例 #6
0
def test_a_unique_relationship_is_really_unique(graph):
    results = graph.cypher.stream("CREATE (a)-[ab:KNOWS]->(b) RETURN a, ab, b")
    alice, alice_knows_bob, bob = next(results).values
    assert alice.degree == 1
    assert bob.degree == 1
    statement = CreateStatement(graph)
    statement.create_unique(Relationship(alice, "KNOWS", bob))
    statement.execute()
    assert alice.degree == 1
    assert bob.degree == 1
コード例 #7
0
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
コード例 #8
0
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
コード例 #9
0
def test_unique_path_not_unique_exception(graph):
    results = graph.cypher.stream("CREATE (a)-[ab:KNOWS]->(b), (a)-[:KNOWS]->(b) RETURN a, ab, b")
    alice, alice_knows_bob, bob = next(results).values
    assert alice.degree == 2
    assert bob.degree == 2
    statement = CreateStatement(graph)
    statement.create_unique(Relationship(alice, "KNOWS", bob))
    try:
        statement.execute()
    except CypherError as error:
        assert error.exception == "UniquePathNotUniqueException"
        assert error.fullname in [None, "org.neo4j.cypher.UniquePathNotUniqueException"]
        assert error.statement == ("START _0n0=node({_0n0}),_0n1=node({_0n1})\n"
                                   "CREATE UNIQUE (_0n0)-[_0r0:KNOWS]->(_0n1)\n"
                                   "RETURN _0n0,_0n1,_0r0")
    else:
        assert False
コード例 #10
0
def test_unique_path_not_unique_exception(graph):
    results = graph.cypher.stream(
        "CREATE (a)-[ab:KNOWS]->(b), (a)-[:KNOWS]->(b) RETURN a, ab, b")
    alice, alice_knows_bob, bob = next(results).values
    assert alice.degree == 2
    assert bob.degree == 2
    statement = CreateStatement(graph)
    statement.create_unique(Relationship(alice, "KNOWS", bob))
    try:
        statement.execute()
    except CypherError as error:
        assert error.exception == "UniquePathNotUniqueException"
        assert error.fullname in [
            None, "org.neo4j.cypher.UniquePathNotUniqueException"
        ]
        assert error.statement == (
            "START _0n0=node({_0n0}),_0n1=node({_0n1})\n"
            "CREATE UNIQUE (_0n0)-[_0r0:KNOWS]->(_0n1)\n"
            "RETURN _0n0,_0n1,_0r0")
    else:
        assert False