예제 #1
0
 def test_remote_node_changes_can_be_pulled(self):
     batch = Batch(self.graph)
     batch.create_node({"Person"}, {"name": "Alice"})
     result = batch.submit()
     remote = next(result)
     local = Node()
     local.bind(self.graph, id=remote._id)
     local.pull()
     assert local.labels == remote.labels
     assert local.properties == remote.properties
예제 #2
0
 def test_local_node_changes_can_be_pushed(self):
     batch = Batch(self.graph)
     batch.create_node()
     result = batch.submit()
     remote = next(result)
     local = Node("Person", name="Alice")
     local.bind(self.graph, id=remote._id)
     local.push()
     remote = Batch.single(self.graph, Batch.get_node, local._id)
     assert remote.labels == local.labels
     assert remote.properties == local.properties
예제 #3
0
 def test_can_batch_create_new_nodes(self):
     batch = BatchCreate(self.graph)
     batch.add(Node(name="Alice"))
     batch.add(Node(name="Bob"))
     result = batch.submit()
     result_list = list(result)
     assert len(result_list) == 2
     assert result_list[0] == Node(name="Alice")
     assert result_list[0].bound
     assert result_list[1] == Node(name="Bob")
     assert result_list[1].bound
예제 #4
0
 def test_simple_statement(self):
     result = self.graph.execute("CREATE (a:Person {name:'Alice'}) "
                                 "RETURN a")
     assert isinstance(result, Table)
     assert result.columns == ["a"]
     assert result.rows == [
         [Node("Person", name="Alice")],
     ]
예제 #5
0
 def test_statement_with_parameters(self):
     result = self.graph.execute(
         "CREATE (a:Person {name:{name}}) "
         "RETURN a", {"name": "Alice"})
     assert isinstance(result, Table)
     assert result.columns == ["a"]
     assert result.rows == [
         [Node("Person", name="Alice")],
     ]
예제 #6
0
 def test_can_batch_create_existing_nodes(self):
     result = self.graph.execute("""\
     CREATE (a {name:'Alice'}), (b {name:'Bob'})
     RETURN a, b
     """)
     a, b = next(iter(result))
     b["age"] = 44
     batch = BatchCreate(self.graph)
     batch.add(a)
     batch.add(b)
     result = batch.submit()
     result_list = list(result)
     assert len(result_list) == 2
     assert result_list[0] == Node(name="Alice")
     assert result_list[0].bound
     assert result_list[0] is a
     assert result_list[1] == Node(name="Bob", age=44)
     assert result_list[1].bound
     assert result_list[1] is b
예제 #7
0
 def test_statement_with_multiple_parameters(self):
     param_sets = [{"name": "Alice"}, {"name": "Bob"}, {"name": "Carol"}]
     results = self.graph.execute(
         "CREATE (a:Person {name:{name}}) "
         "RETURN a", *param_sets)
     assert len(results) == len(param_sets)
     for i, result in enumerate(results):
         assert isinstance(result, Table)
         assert result.columns == ["a"]
         assert result.rows == [
             [Node("Person", **param_sets[i])],
         ]
예제 #8
0
 def test_remote_node_changes_can_be_pulled(self):
     batch = Batch(self.graph)
     batch.create_node({"Person"}, {"name": "Alice"})
     result = batch.submit()
     remote = next(result)
     local = Node()
     local.bind(self.graph, id=remote._id)
     local.pull()
     assert local.labels == remote.labels
     assert local.properties == remote.properties
예제 #9
0
 def test_local_node_changes_can_be_pushed(self):
     batch = Batch(self.graph)
     batch.create_node()
     result = batch.submit()
     remote = next(result)
     local = Node("Person", name="Alice")
     local.bind(self.graph, id=remote._id)
     local.push()
     remote = Batch.single(self.graph, Batch.get_node, local._id)
     assert remote.labels == local.labels
     assert remote.properties == local.properties
예제 #10
0
 def test_can_represent_node_with_labels_and_properties(self):
     node = Node("Human", "Female", name="Alice", age=33)
     string = repr(node)
     assert string == '(:Female:Human {"age":33,"name":"Alice"})'
예제 #11
0
 def test_can_represent_node_with_properties(self):
     node = Node(name="Alice", age=33)
     string = repr(node)
     assert string == '({"age":33,"name":"Alice"})'
예제 #12
0
 def test_can_represent_node_with_labels(self):
     node = Node("Human", "Female")
     string = repr(node)
     assert string == '(:Female:Human)'
예제 #13
0
 def test_can_hydrate_node_with_labels(self):
     hydrated = yaml.load('!Node {"labels":["Human","Female"]}')
     assert hydrated == Node("Human", "Female")
     assert not hydrated.bound
예제 #14
0
 def test_multiple_node_labels(self):
     node = Node("Human", "Female", name="Alice")
     assert node.labels == {"Human", "Female"}
예제 #15
0
 def test_duplicate_node_labels(self):
     node = Node("Human", "Human", name="Alice")
     assert node.labels == {"Human"}
예제 #16
0
 def test_can_construct_empty_node(self):
     node = Node()
     assert node.labels == set()
     assert node.properties == {}
예제 #17
0
 def test_casting_dict_will_return_node_with_properties(self):
     properties = {"name": "Alice"}
     casted = Node.cast(properties)
     assert casted == Node(**properties)
예제 #18
0
 def test_casting_string_will_return_node_with_label(self):
     label = "Person"
     casted = Node.cast(label)
     assert casted == Node(label)
예제 #19
0
 def test_casting_node_will_return_same(self):
     node = Node("Person", name="Alice")
     casted = Node.cast(node)
     assert casted is node
예제 #20
0
 def test_casting_none_will_return_none(self):
     casted = Node.cast(None)
     assert casted is None
예제 #21
0
 def test_can_hydrate_node_with_labels_and_properties(self):
     hydrated = yaml.load('!Node {"labels":["Human","Female"],'
                          '"properties":{"name":"Alice","age":33}}')
     assert hydrated == Node("Human", "Female", name="Alice", age=33)
     assert not hydrated.bound
예제 #22
0
 def test_can_hydrate_node_with_properties(self):
     hydrated = yaml.load('!Node {"properties":{"name":"Alice","age":33}}')
     assert hydrated == Node(name="Alice", age=33)
     assert not hydrated.bound
예제 #23
0
 def test_equal_nodes(self):
     node_1 = Node("Person", name="Alice")
     node_2 = Node("Person", name="Alice")
     assert node_1 == node_2
예제 #24
0
 def test_adding_node_label(self):
     node = Node("Person", name="Alice")
     node.labels.add("Employee")
     assert node.labels == {"Person", "Employee"}
예제 #25
0
 def test_casting_node_will_return_same(self):
     node = Node("Person", name="Alice")
     casted = Node.cast(node)
     assert casted is node
예제 #26
0
 def test_casting_none_will_return_none(self):
     casted = Node.cast(None)
     assert casted is None
예제 #27
0
 def test_casting_dict_will_return_node_with_properties(self):
     properties = {"name": "Alice"}
     casted = Node.cast(properties)
     assert casted == Node(**properties)
예제 #28
0
 def test_casting_string_will_return_node_with_label(self):
     label = "Person"
     casted = Node.cast(label)
     assert casted == Node(label)
예제 #29
0
 def test_single_node_label(self):
     node = Node("Person", name="Alice")
     assert node.labels == {"Person"}
예제 #30
0
 def test_can_construct_node_with_labels_and_properties(self):
     node = Node("Human", "Female", name="Alice", age=33)
     assert node.labels == {"Human", "Female"}
     assert node.properties == {"name": "Alice", "age": 33}
예제 #31
0
 def test_can_represent_empty_node(self):
     node = Node()
     string = repr(node)
     assert string == '()'
예제 #32
0
 def test_can_construct_node_with_labels(self):
     node = Node("Human", "Female")
     assert node.labels == {"Human", "Female"}
     assert node.properties == {}
예제 #33
0
 def test_remove_node_label(self):
     node = Node("Human", "Female", name="Alice")
     node.labels.remove("Female")
     assert node.labels == {"Human"}
예제 #34
0
 def test_can_construct_node_with_properties(self):
     node = Node(name="Alice", age=33)
     assert node.labels == set()
     assert node.properties == {"name": "Alice", "age": 33}
예제 #35
0
 def test_can_hydrate_empty_node(self):
     hydrated = yaml.load('!Node {}')
     assert hydrated == Node()
     assert not hydrated.bound