How to use the py2neo.types.Node function in py2neo

To help you get started, we’ve selected a few py2neo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github technige / py2neo / test / test_merge.py View on Github external
def test_can_merge_node_that_does_not_exist_on_specific_label_and_key(self):
        alice = Node("Person", "Employee", name="Alice", age=33)
        old_order = graph_order(self.graph)
        self.graph.merge(alice, "Person", "name")
        self.assertEqual(alice.graph, self.graph)
        self.assertIsNotNone(alice.identity)
        assert self.graph.exists(alice)
        new_order = graph_order(self.graph)
        assert new_order == old_order + 1
github technige / py2neo / test / test_delete.py View on Github external
def test_can_delete_node(self):
        alice = Node("Person", name="Alice")
        self.graph.create(alice)
        assert self.graph.exists(alice)
        self.graph.delete(alice)
        assert not self.graph.exists(alice)
github technige / py2neo / test / test_merge.py View on Github external
def test_can_merge_node_that_does_not_exist(self):
        alice = Node("Person", name="Alice")
        old_order = graph_order(self.graph)
        self.graph.merge(alice)
        self.assertEqual(alice.graph, self.graph)
        self.assertIsNotNone(alice.identity)
        assert self.graph.exists(alice)
        new_order = graph_order(self.graph)
        assert new_order == old_order + 1
github technige / py2neo / test / test_delete.py View on Github external
def test_can_delete_path(self):
        alice, bob, carol, dave = Node(), Node(), Node(), Node()
        path = Path(alice, "LOVES", bob, Relationship(carol, "HATES", bob), carol, "KNOWS", dave)
        self.graph.create(path)
        assert self.graph.exists(path)
        self.graph.delete(path)
        assert not self.graph.exists(path)
github technige / py2neo / test / test_transaction.py View on Github external
def test_can_delete_relationship(self):
        a = Node()
        b = Node()
        r = Relationship(a, "TO", b)
        self.graph.create(r)
        assert self.graph.exists(r)
        with self.graph.begin() as tx:
            tx.delete(r)
        assert not self.graph.exists(r)
        assert not self.graph.exists(a)
        assert not self.graph.exists(b)
github technige / py2neo / test / test_merge.py View on Github external
def test_can_merge_long_walkable_with_repeats(self):
        a = Node("Person", name="Alice")
        b = Node("Person", name="Bob")
        c = Node("Person", name="Carol")
        d = Node("Person", name="Dave")
        ab = Relationship(a, "KNOWS", b)
        cb = Relationship(c, "KNOWS", b)
        cd = Relationship(c, "KNOWS", d)
        bd = Relationship(b, "KNOWS", d)
        self.graph.create(a)
        old_order = graph_order(self.graph)
        old_size = graph_size(self.graph)
        self.graph.merge(ab + cb + cb + bd + cd)
        new_order = graph_order(self.graph)
        new_size = graph_size(self.graph)
        assert new_order == old_order + 3
        assert new_size == old_size + 4
github technige / py2neo / test / test_merge.py View on Github external
def test_can_merge_three_nodes_where_none_exist(self):
        alice = Node("Person", name="Alice")
        bob = Node("Person", name="Bob")
        carol = Node("Person", name="Carol")
        old_order = graph_order(self.graph)
        subgraph = alice | bob | carol
        self.graph.merge(subgraph)
        for node in subgraph.nodes:
            self.assertEqual(node.graph, self.graph)
            self.assertIsNotNone(node.identity)
            assert self.graph.exists(node)
        new_order = graph_order(self.graph)
        assert new_order == old_order + 3
github technige / py2neo / test / test_node.py View on Github external
def test_node_is_never_equal_to_none(self):
        alice = Node(name="Alice", age=34)
        assert alice is not None
github technige / py2neo / test / unit / test_types.py View on Github external
def test_can_cast_3_tuple_with_unbound_rel(self):
        a = Node()
        b = Node()
        casted = Relationship.cast((a, ("KNOWS", {"since": 1999}), b))
        self.assertIsInstance(casted, Relationship)
        self.assertIsNone(casted.graph)
        self.assertIsNone(casted.identity)
        assert casted.start_node == a
        assert casted.type == "KNOWS"
        assert casted.end_node == b
        assert casted["since"] == 1999
github technige / py2neo / py2neo / types.py View on Github external
def __init__(self, *entities):
        entities = list(entities)
        for i, entity in enumerate(entities):
            if isinstance(entity, Entity):
                continue
            elif entity is None:
                entities[i] = Node()
            elif isinstance(entity, dict):
                entities[i] = Node(**entity)
        for i, entity in enumerate(entities):
            try:
                start_node = entities[i - 1].end_node
                end_node = entities[i + 1].start_node
            except (IndexError, AttributeError):
                pass
            else:
                if isinstance(entity, string_types):
                    entities[i] = Relationship(start_node, entity, end_node)
                elif isinstance(entity, tuple) and len(entity) == 2:
                    t, properties = entity
                    entities[i] = Relationship(start_node, t, end_node, **properties)
        Walkable.__init__(self, walk(*entities))