Ejemplo n.º 1
0
def test_binding_node_if_labels_not_supported_casts_to_legacy_node():
    with patch("py2neo.Graph.supports_node_labels") as mocked:
        mocked.__get__ = Mock(return_value=False)
        alice = Node(name="Alice Smith")
        assert isinstance(alice, Node)
        alice.bind("http://localhost:7474/db/data/node/1")
        assert isinstance(alice, LegacyNode)
Ejemplo n.º 2
0
def test_bound_node_equality():
    alice_1 = Node(name="Alice")
    alice_1.bind("http://localhost:7474/db/data/node/1")
    Node.cache.clear()
    alice_2 = Node(name="Alice")
    alice_2.bind(alice_1.uri)
    assert alice_1 == alice_2
Ejemplo n.º 3
0
def test_bound_node_equality():
    alice_1 = Node(name="Alice")
    alice_1.bind("http://localhost:7474/db/data/node/1")
    Node.cache.clear()
    alice_2 = Node(name="Alice")
    alice_2.bind(alice_1.uri)
    assert alice_1 == alice_2
Ejemplo n.º 4
0
def test_binding_node_if_labels_not_supported_casts_to_legacy_node():
    with patch("py2neo.Graph.supports_node_labels") as mocked:
        mocked.__get__ = Mock(return_value=False)
        alice = Node(name="Alice Smith")
        assert isinstance(alice, Node)
        alice.bind("http://localhost:7474/db/data/node/1")
        assert isinstance(alice, LegacyNode)
Ejemplo n.º 5
0
def test_can_pull_node(graph):
    uri = graph.cypher.execute_one("CREATE (a {name:'Alice'}) RETURN a").uri
    alice = Node()
    alice.bind(uri)
    assert alice.properties["name"] is None
    batch = PullBatch(graph)
    batch.append(alice)
    batch.pull()
    assert alice.properties["name"] == "Alice"
Ejemplo n.º 6
0
def test_rel_and_rev_hashes(graph):
    assert hash(Rel("KNOWS")) == hash(Rel("KNOWS"))
    assert hash(Rel("KNOWS")) == -hash(Rev("KNOWS"))
    assert hash(Rel("KNOWS", well=True, since=1999)) == hash(Rel("KNOWS", since=1999, well=True))
    rel_1 = Node("KNOWS", since=1999)
    graph.create(rel_1)
    rel_2 = Node("KNOWS", since=1999)
    rel_2.bind(rel_1.uri)
    assert rel_1 is not rel_2
    assert hash(rel_1) == hash(rel_2)
Ejemplo n.º 7
0
def test_rel_and_rev_hashes(graph):
    assert hash(Rel("KNOWS")) == hash(Rel("KNOWS"))
    assert hash(Rel("KNOWS")) == -hash(Rev("KNOWS"))
    assert hash(Rel("KNOWS", well=True,
                    since=1999)) == hash(Rel("KNOWS", since=1999, well=True))
    rel_1 = Node("KNOWS", since=1999)
    graph.create(rel_1)
    rel_2 = Node("KNOWS", since=1999)
    rel_2.bind(rel_1.uri)
    assert rel_1 is not rel_2
    assert hash(rel_1) == hash(rel_2)
Ejemplo n.º 8
0
def test_node_hashes(graph):
    assert hash(Node()) == hash(Node())
    assert hash(Node(name="Alice")) == hash(Node(name="Alice"))
    assert hash(Node(name="Alice", age=33)) == hash(Node(age=33, name="Alice"))
    assert hash(Node("Person", name="Alice", age=33)) == hash(Node("Person", age=33, name="Alice"))
    node_1 = Node("Person", name="Alice")
    graph.create(node_1)
    node_2 = Node("Person", name="Alice")
    node_2.bind(node_1.uri)
    assert node_1 is not node_2
    assert hash(node_1) == hash(node_2)
Ejemplo n.º 9
0
def test_node_hashes(graph):
    assert hash(Node()) == hash(Node())
    assert hash(Node(name="Alice")) == hash(Node(name="Alice"))
    assert hash(Node(name="Alice", age=33)) == hash(Node(age=33, name="Alice"))
    assert hash(Node("Person", name="Alice",
                     age=33)) == hash(Node("Person", age=33, name="Alice"))
    node_1 = Node("Person", name="Alice")
    graph.create(node_1)
    node_2 = Node("Person", name="Alice")
    node_2.bind(node_1.uri)
    assert node_1 is not node_2
    assert hash(node_1) == hash(node_2)
Ejemplo n.º 10
0
def test_node_exists_will_raise_non_404_errors():
    with patch.object(_Resource, "get") as mocked:
        error = GraphError("bad stuff happened")
        error.response = DodgyClientError()
        mocked.side_effect = error
        alice = Node(name="Alice Smith")
        alice.bind("http://localhost:7474/db/data/node/1")
        try:
            _ = alice.exists
        except GraphError:
            assert True
        else:
            assert False
Ejemplo n.º 11
0
def test_can_pull_node_with_label(graph):
    if not graph.supports_node_labels:
        return
    uri = graph.cypher.execute_one("CREATE (a:Person {name:'Alice'}) RETURN a").uri
    alice = Node()
    alice.bind(uri)
    assert "Person" not in alice.labels
    assert alice.properties["name"] is None
    batch = PullBatch(graph)
    batch.append(alice)
    batch.pull()
    assert "Person" in alice.labels
    assert alice.properties["name"] == "Alice"
Ejemplo n.º 12
0
def test_node_exists_will_raise_non_404_errors():
    with patch.object(_Resource, "get") as mocked:
        error = GraphError("bad stuff happened")
        error.response = DodgyClientError()
        mocked.side_effect = error
        alice = Node(name="Alice Smith")
        alice.bind("http://localhost:7474/db/data/node/1")
        try:
            _ = alice.exists
        except GraphError:
            assert True
        else:
            assert False
Ejemplo n.º 13
0
def test_can_join_similar_bound_nodes():
    alice.bind("http://localhost:7474/db/data/node/1")
    Node.cache.clear()
    alice_2 = Node(name="Alice")
    alice_2.bind(alice.uri)
    assert Node.join(alice, alice_2) == alice
Ejemplo n.º 14
0
from __future__ import print_function
from py2neo import Graph, Node, Relationship

graph_db = Graph()

person = Node("Person", name="JUHASZ Lilla Linda")

for record in graph_db.cypher.execute("Match (n) return n"):
    print(record)

new_person = Node("Person", name="JUHASZ Peter", born=1930)
print("exists: " + str(list(graph_db.find("Person", property_key="name", property_value="JUHASZ Peter"))))

new_person.bind(graph_db.uri)
print("exists: " + str(new_person.exists))

father = graph_db.find_one("Person", property_key='name', property_value="JUHASZ Peter")

child = graph_db.find_one("Person", property_key='name', property_value="JUHASZ Lilla Linda")
child_of_rel = "CHILD_OF"
father_daughter_relationship = Relationship(child, child_of_rel, father)
graph_db.create(father_daughter_relationship)

Ejemplo n.º 15
0
def test_bound_node_equals_unbound_node_with_same_properties():
    alice_1 = Node(name="Alice")
    alice_1.bind("http://localhost:7474/db/data/node/1")
    alice_2 = Node(name="Alice")
    assert alice_1 == alice_2
Ejemplo n.º 16
0
def test_bound_node_equals_unbound_node_with_same_properties():
    alice_1 = Node(name="Alice")
    alice_1.bind("http://localhost:7474/db/data/node/1")
    alice_2 = Node(name="Alice")
    assert alice_1 == alice_2
Ejemplo n.º 17
0
def test_can_join_similar_bound_nodes():
    alice.bind("http://localhost:7474/db/data/node/1")
    Node.cache.clear()
    alice_2 = Node(name="Alice")
    alice_2.bind(alice.uri)
    assert Node.join(alice, alice_2) == alice