Exemple #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
Exemple #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
Exemple #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
Exemple #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")],
     ]
Exemple #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")],
     ]
Exemple #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
Exemple #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])],
         ]
Exemple #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
Exemple #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
Exemple #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"})'
Exemple #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"})'
Exemple #12
0
 def test_can_represent_node_with_labels(self):
     node = Node("Human", "Female")
     string = repr(node)
     assert string == '(:Female:Human)'
Exemple #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
Exemple #14
0
 def test_multiple_node_labels(self):
     node = Node("Human", "Female", name="Alice")
     assert node.labels == {"Human", "Female"}
Exemple #15
0
 def test_duplicate_node_labels(self):
     node = Node("Human", "Human", name="Alice")
     assert node.labels == {"Human"}
Exemple #16
0
 def test_can_construct_empty_node(self):
     node = Node()
     assert node.labels == set()
     assert node.properties == {}
Exemple #17
0
 def test_casting_dict_will_return_node_with_properties(self):
     properties = {"name": "Alice"}
     casted = Node.cast(properties)
     assert casted == Node(**properties)
Exemple #18
0
 def test_casting_string_will_return_node_with_label(self):
     label = "Person"
     casted = Node.cast(label)
     assert casted == Node(label)
Exemple #19
0
 def test_casting_node_will_return_same(self):
     node = Node("Person", name="Alice")
     casted = Node.cast(node)
     assert casted is node
Exemple #20
0
 def test_casting_none_will_return_none(self):
     casted = Node.cast(None)
     assert casted is None
Exemple #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
Exemple #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
Exemple #23
0
 def test_equal_nodes(self):
     node_1 = Node("Person", name="Alice")
     node_2 = Node("Person", name="Alice")
     assert node_1 == node_2
Exemple #24
0
 def test_adding_node_label(self):
     node = Node("Person", name="Alice")
     node.labels.add("Employee")
     assert node.labels == {"Person", "Employee"}
Exemple #25
0
 def test_casting_node_will_return_same(self):
     node = Node("Person", name="Alice")
     casted = Node.cast(node)
     assert casted is node
Exemple #26
0
 def test_casting_none_will_return_none(self):
     casted = Node.cast(None)
     assert casted is None
Exemple #27
0
 def test_casting_dict_will_return_node_with_properties(self):
     properties = {"name": "Alice"}
     casted = Node.cast(properties)
     assert casted == Node(**properties)
Exemple #28
0
 def test_casting_string_will_return_node_with_label(self):
     label = "Person"
     casted = Node.cast(label)
     assert casted == Node(label)
Exemple #29
0
 def test_single_node_label(self):
     node = Node("Person", name="Alice")
     assert node.labels == {"Person"}
Exemple #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}
Exemple #31
0
 def test_can_represent_empty_node(self):
     node = Node()
     string = repr(node)
     assert string == '()'
Exemple #32
0
 def test_can_construct_node_with_labels(self):
     node = Node("Human", "Female")
     assert node.labels == {"Human", "Female"}
     assert node.properties == {}
Exemple #33
0
 def test_remove_node_label(self):
     node = Node("Human", "Female", name="Alice")
     node.labels.remove("Female")
     assert node.labels == {"Human"}
Exemple #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}
Exemple #35
0
 def test_can_hydrate_empty_node(self):
     hydrated = yaml.load('!Node {}')
     assert hydrated == Node()
     assert not hydrated.bound