Exemplo n.º 1
0
def test_can_bind_rev_to_resource():
    uri = "http://localhost:7474/db/relationship/1"
    rel = Rev()
    rel.bind(uri)
    assert rel.bound
    assert isinstance(rel.resource, Resource)
    assert rel.resource.uri == uri
    rel.unbind()
    assert not rel.bound
    with pytest.raises(BindError):
        r = rel.resource
Exemplo n.º 2
0
def test_unbound_path_is_not_bound():
    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)
    assert not path.bound
Exemplo n.º 3
0
def test_can_push_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)
    graph.create(path)
    if graph.neo4j_version >= (2, 0, 0):
        query = """\
        START ab=rel({ab}), bc=rel({bc}), cd=rel({cd})
        RETURN ab.amount, bc.amount, cd.since
        """
    else:
        query = """\
        START ab=rel({ab}), bc=rel({bc}), cd=rel({cd})
        RETURN ab.amount?, bc.amount?, cd.since?
        """
    params = {"ab": path[0]._id, "bc": path[1]._id, "cd": path[2]._id}
    path[0].properties["amount"] = "lots"
    path[1].properties["amount"] = "some"
    path[2].properties["since"] = 1999
    results = graph.cypher.execute(query, params)
    ab_amount, bc_amount, cd_since = results[0].values
    assert ab_amount is None
    assert bc_amount is None
    assert cd_since is None
    path.push()
    results = graph.cypher.execute(query, params)
    ab_amount, bc_amount, cd_since = results[0].values
    assert ab_amount == "lots"
    assert bc_amount == "some"
    assert cd_since == 1999
Exemplo n.º 4
0
def test_bound_path_is_bound(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)
    graph.create(path)
    assert path.bound
Exemplo n.º 5
0
def test_can_unbind_unbound_path_without_error():
    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)
    path.unbind()
    assert not path.bound
Exemplo n.º 6
0
def test_unbinding_rev_also_unbinds_rel(graph):
    a, b, ab = graph.create({}, {}, (0, Rev("KNOWS"), 1))
    rev = ab.rel
    #assert rev.pair is None
    rel = -rev
    assert rev.pair is rel
    assert rel.pair is rev
    assert rev.bound
    assert rel.bound
    assert rev.resource is rel.resource
    rev.unbind()
    assert not rev.bound
    assert not rel.bound
Exemplo n.º 7
0
def test_can_bind_rev_to_resource():
    uri = "http://localhost:7474/db/relationship/1"
    rel = Rev()
    rel.bind(uri)
    assert rel.bound
    assert isinstance(rel.resource, Resource)
    assert rel.resource.uri == uri
    rel.unbind()
    assert not rel.bound
    with pytest.raises(BindError):
        _ = rel.resource
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def test_can_pull_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)
    graph.create(path)
    assert path[0].properties["amount"] is None
    assert path[1].properties["amount"] is None
    assert path[2].properties["since"] is None
    assert path[0].rel.properties["amount"] is None
    assert path[1].rel.properties["amount"] is None
    assert path[2].rel.properties["since"] is None
    graph.cypher.run("""\
    START ab=rel({ab}), bc=rel({bc}), cd=rel({cd})
    SET ab.amount = "lots", bc.amount = "some", cd.since = 1999
    """, {"ab": path[0]._id, "bc": path[1]._id, "cd": path[2]._id})
    path.pull()
    assert path[0].properties["amount"] == "lots"
    assert path[1].properties["amount"] == "some"
    assert path[2].properties["since"] == 1999
    assert path[0].rel.properties["amount"] == "lots"
    assert path[1].rel.properties["amount"] == "some"
    assert path[2].rel.properties["since"] == 1999
Exemplo n.º 11
0
def test_can_write_simple_path():
    r = Representation()
    r.write(Path({}, "LOVES", {}, Rev("HATES"), {}, "KNOWS", {}))
    written = repr(r)
    assert written == "()-[:LOVES]->()<-[:HATES]-()-[:KNOWS]->()"
Exemplo n.º 12
0
def test_can_write_simple_rev():
    r = Representation()
    r.write(Rev("KNOWS"))
    written = repr(r)
    assert written == "<-[:KNOWS]-"