Example #1
0
 def setUp(self):
     self.batch = ManualIndexWriteBatch(self.graph)
     self.alice = cast_node({"name": "Alice", "surname": "Allison"})
     self.bob = cast_node({"name": "Bob", "surname": "Robertson"})
     self.friends = cast_relationship((self.alice, "KNOWS", self.bob, {
         "since": 2000
     }))
     self.graph.create(self.alice | self.bob | self.friends)
Example #2
0
 def test_can_create_path_with_existing_nodes(self):
     alice = cast_node({"name": "Alice"})
     bob = cast_node({"name": "Bob"})
     self.graph.create(alice | bob)
     self.batch.create_path(alice, "KNOWS", bob)
     results = self.batch.run()
     path = results[0]
     assert len(path) == 1
     assert path.nodes()[0] == alice
     assert path[0].type() == "KNOWS"
     assert path.nodes()[1] == bob
Example #3
0
 def test_can_delete_properties_on_preexisting_node(self):
     alice = cast_node({"name": "Alice", "age": 34})
     self.graph.create(alice)
     self.batch.delete_properties(alice)
     self.batch.run()
     self.graph.pull(alice)
     assert not alice
Example #4
0
 def test_can_create_concrete_node(self):
     alice = cast_node({"name": "Alice", "age": 34})
     self.graph.create(alice)
     assert isinstance(alice, Node)
     assert remote(alice)
     assert alice["name"] == "Alice"
     assert alice["age"] == 34
Example #5
0
 def test_schema_index(self):
     label_1 = next(self.unique_string)
     label_2 = next(self.unique_string)
     munich = cast_node({'name': "München", 'key': "09162000"})
     self.graph.create(munich)
     munich.clear_labels()
     munich.update_labels({label_1, label_2})
     self.schema.create_index(label_1, "name")
     self.schema.create_index(label_1, "key")
     self.schema.create_index(label_2, "name")
     self.schema.create_index(label_2, "key")
     found_borough_via_name = self.node_selector.select(label_1,
                                                        name="München")
     found_borough_via_key = self.node_selector.select(label_1,
                                                       key="09162000")
     found_county_via_name = self.node_selector.select(label_2,
                                                       name="München")
     found_county_via_key = self.node_selector.select(label_2,
                                                      key="09162000")
     assert list(found_borough_via_name) == list(found_borough_via_key)
     assert list(found_county_via_name) == list(found_county_via_key)
     assert list(found_borough_via_name) == list(found_county_via_name)
     keys = self.schema.get_indexes(label_1)
     assert "name" in keys
     assert "key" in keys
     self.schema.drop_index(label_1, "name")
     self.schema.drop_index(label_1, "key")
     self.schema.drop_index(label_2, "name")
     self.schema.drop_index(label_2, "key")
     with self.assertRaises(GraphError):
         self.schema.drop_index(label_2, "key")
     self.graph.delete(munich)
Example #6
0
 def test_can_delete_property_on_preexisting_node(self):
     alice = cast_node({"name": "Alice", "age": 34})
     self.graph.create(alice)
     self.batch.delete_property(alice, "age")
     self.batch.run()
     self.graph.pull(alice)
     assert alice["name"] == "Alice"
     assert alice["age"] is None
Example #7
0
 def test_can_create_multiple_nodes(self):
     self.batch.create({"name": "Alice"})
     self.batch.create(cast_node({"name": "Bob"}))
     self.batch.create(Node(name="Carol"))
     alice, bob, carol = self.batch.run()
     assert isinstance(alice, Node)
     assert isinstance(bob, Node)
     assert isinstance(carol, Node)
     assert alice["name"] == "Alice"
     assert bob["name"] == "Bob"
     assert carol["name"] == "Carol"
Example #8
0
 def test_create_node_with_mixed_property_types(self):
     a = cast_node({
         "number": 13,
         "foo": "bar",
         "true": False,
         "fish": "chips"
     })
     self.graph.create(a)
     assert len(a) == 4
     assert a["fish"] == "chips"
     assert a["foo"] == "bar"
     assert a["number"] == 13
     assert not a["true"]
Example #9
0
 def test_cast_node(self):
     alice = Node("Person", "Employee", name="Alice", age=33)
     assert cast_node(None) is None
     assert cast_node(alice) is alice
     assert_node(cast_node("Person"), "Person")
     assert_node(cast_node({"name": "Alice"}), name="Alice")
     assert_node(cast_node(("Person", "Employee", {
         "name": "Alice",
         "age": 33
     })),
                 "Person",
                 "Employee",
                 name="Alice",
                 age=33)
     with self.assertRaises(TypeError):
         cast_node(3.14)
Example #10
0
 def test_all_property_types(self):
     data = {
         "nun": None,
         "yes": True,
         "no": False,
         "int": 42,
         "float": 3.141592653589,
         "long": long("9223372036854775807"),
         "str": "hello, world",
         "unicode": u"hello, world",
         "boolean_list": [True, False, True, True, False],
         "int_list": [1, 1, 2, 3, 5, 8, 13, 21, 35],
         "str_list": ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
     }
     foo = cast_node(data)
     self.graph.create(foo)
     for key, value in data.items():
         self.assertEqual(foo[key], value)
Example #11
0
 def test_create_node_with_null_properties(self):
     a = cast_node({"foo": "bar", "no-foo": None})
     self.graph.create(a)
     assert a["foo"] == "bar"
     assert a["no-foo"] is None