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
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
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
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")], ]
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")], ]
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
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])], ]
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"})'
def test_can_represent_node_with_properties(self): node = Node(name="Alice", age=33) string = repr(node) assert string == '({"age":33,"name":"Alice"})'
def test_can_represent_node_with_labels(self): node = Node("Human", "Female") string = repr(node) assert string == '(:Female:Human)'
def test_can_hydrate_node_with_labels(self): hydrated = yaml.load('!Node {"labels":["Human","Female"]}') assert hydrated == Node("Human", "Female") assert not hydrated.bound
def test_multiple_node_labels(self): node = Node("Human", "Female", name="Alice") assert node.labels == {"Human", "Female"}
def test_duplicate_node_labels(self): node = Node("Human", "Human", name="Alice") assert node.labels == {"Human"}
def test_can_construct_empty_node(self): node = Node() assert node.labels == set() assert node.properties == {}
def test_casting_dict_will_return_node_with_properties(self): properties = {"name": "Alice"} casted = Node.cast(properties) assert casted == Node(**properties)
def test_casting_string_will_return_node_with_label(self): label = "Person" casted = Node.cast(label) assert casted == Node(label)
def test_casting_node_will_return_same(self): node = Node("Person", name="Alice") casted = Node.cast(node) assert casted is node
def test_casting_none_will_return_none(self): casted = Node.cast(None) assert casted is None
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
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
def test_equal_nodes(self): node_1 = Node("Person", name="Alice") node_2 = Node("Person", name="Alice") assert node_1 == node_2
def test_adding_node_label(self): node = Node("Person", name="Alice") node.labels.add("Employee") assert node.labels == {"Person", "Employee"}
def test_single_node_label(self): node = Node("Person", name="Alice") assert node.labels == {"Person"}
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}
def test_can_represent_empty_node(self): node = Node() string = repr(node) assert string == '()'
def test_can_construct_node_with_labels(self): node = Node("Human", "Female") assert node.labels == {"Human", "Female"} assert node.properties == {}
def test_remove_node_label(self): node = Node("Human", "Female", name="Alice") node.labels.remove("Female") assert node.labels == {"Human"}
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}
def test_can_hydrate_empty_node(self): hydrated = yaml.load('!Node {}') assert hydrated == Node() assert not hydrated.bound