Example #1
0
def test_can_set_properties_on_preexisting_node(graph):
    alice, = graph.create({})
    batch = WriteBatch(graph)
    batch.set_properties(alice, {"name": "Alice", "age": 34})
    batch.run()
    assert alice["name"] == "Alice"
    assert alice["age"] == 34
Example #2
0
def test_can_delete_properties_on_preexisting_node(graph):
    alice, = graph.create({"name": "Alice", "age": 34})
    batch = WriteBatch(graph)
    batch.delete_properties(alice)
    batch.run()
    props = alice.get_properties()
    assert props == {}
Example #3
0
def test_can_delete_property_on_preexisting_node(graph):
    alice, = graph.create({"name": "Alice", "age": 34})
    batch = WriteBatch(graph)
    batch.delete_property(alice, "age")
    batch.run()
    assert alice["name"] == "Alice"
    assert alice["age"] is None
Example #4
0
def test_cannot_create_with_bad_type(graph):
    batch = WriteBatch(graph)
    try:
        batch.create("this is not creatable")
    except TypeError:
        assert True
    else:
        assert False
Example #5
0
def test_can_add_labels_to_preexisting_node(graph):
    if not graph.supports_node_labels:
        return
    alice, = graph.create({"name": "Alice"})
    batch = WriteBatch(graph)
    batch.add_labels(alice, "human", "female")
    batch.run()
    assert alice.get_labels() == {"human", "female"}
Example #6
0
def test_cannot_create_with_bad_type(graph):
    batch = WriteBatch(graph)
    try:
        batch.create("this is not creatable")
    except TypeError:
        assert True
    else:
        assert False
Example #7
0
def test_can_create_path_with_new_nodes(graph):
    batch = WriteBatch(graph)
    batch.create_path({"name": "Alice"}, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0]["name"] == "Alice"
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1]["name"] == "Bob"
Example #8
0
def test_can_create_path_with_new_nodes(graph):
    batch = WriteBatch(graph)
    batch.create_path({"name": "Alice"}, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0]["name"] == "Alice"
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1]["name"] == "Bob"
Example #9
0
def test_can_set_labels_on_preexisting_node(graph):
    if not graph.supports_node_labels:
        return
    alice, = graph.create({"name": "Alice"})
    alice.add_labels("human", "female")
    batch = WriteBatch(graph)
    batch.set_labels(alice, "mystery", "badger")
    batch.run()
    assert alice.get_labels() == {"mystery", "badger"}
Example #10
0
def test_can_get_or_create_path_with_existing_nodes(graph):
    alice, bob = graph.create({"name": "Alice"}, {"name": "Bob"})
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", bob)
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0] == alice
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1] == bob
Example #11
0
def test_can_get_or_create_path_with_existing_nodes(graph):
    alice, bob = graph.create({"name": "Alice"}, {"name": "Bob"})
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", bob)
    results = batch.submit()
    path = results[0]
    assert len(path) == 1
    assert path.nodes[0] == alice
    assert path.relationships[0].type == "KNOWS"
    assert path.nodes[1] == bob
Example #12
0
def test_can_set_labels_on_node_in_same_batch(graph):
    if not graph.supports_node_labels:
        return
    batch = WriteBatch(graph)
    batch.create({"name": "Alice"})
    batch.add_labels(0, "human", "female")
    batch.set_labels(0, "mystery", "badger")
    results = batch.submit()
    alice = results[0]
    assert alice.labels == {"mystery", "badger"}
Example #13
0
def test_can_add_and_remove_labels_on_node_in_same_batch(graph):
    if not graph.supports_node_labels:
        return
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice"})
    batch.add_labels(alice, "human", "female")
    batch.remove_label(alice, "female")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice.labels == {"human"}
Example #14
0
def test_path_merging_is_idempotent(graph):
    alice, = graph.create({"name": "Alice"})
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    bob = path.nodes[1]
    assert path.nodes[0] == alice
    assert bob["name"] == "Bob"
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    assert path.nodes[0] == alice
    assert path.nodes[1] == bob
Example #15
0
def test_can_add_labels_to_node_in_same_batch(graph):
    if not graph.supports_node_labels:
        return
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice"})
    batch.add_labels(alice, "human", "female")
    batch.remove_label(alice, "female")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice.get_labels() == {"human"}
Example #16
0
def test_can_set_labels_on_node_in_same_batch(graph):
    if not graph.supports_node_labels:
        return
    batch = WriteBatch(graph)
    batch.create({"name": "Alice"})
    batch.add_labels(0, "human", "female")
    batch.set_labels(0, "mystery", "badger")
    results = batch.submit()
    alice = results[0]
    assert alice.get_labels() == {"mystery", "badger"}
Example #17
0
def test_can_set_property_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice"})
    batch.set_property(alice, "age", 34)
    results = batch.submit()
    alice = results[batch.find(alice)]
    alice.auto_sync_properties = True
    assert alice["age"] == 34
Example #18
0
def test_can_delete_properties_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_properties(alice)
    results = batch.submit()
    alice = results[batch.find(alice)]
    alice.pull()
    assert alice.properties == {}
Example #19
0
def test_can_delete_property_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_property(alice, "age")
    results = batch.submit()
    alice = results[batch.find(alice)]
    alice.auto_sync_properties = True
    assert alice["name"] == "Alice"
    assert alice["age"] is None
Example #20
0
def test_can_set_property_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice"})
    batch.set_property(alice, "age", 34)
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice["age"] == 34
Example #21
0
def test_can_delete_properties_on_preexisting_node(graph):
    alice, = graph.create({"name": "Alice", "age": 34})
    batch = WriteBatch(graph)
    batch.delete_properties(alice)
    batch.run()
    alice.pull()
    assert alice.properties == {}
Example #22
0
def test_can_set_property_on_preexisting_node(graph):
    alice, = graph.create({"name": "Alice"})
    batch = WriteBatch(graph)
    batch.set_property(alice, "age", 34)
    batch.run()
    alice.pull()
    assert alice["age"] == 34
Example #23
0
def test_can_set_properties_on_preexisting_node(graph):
    alice, = graph.create({})
    batch = WriteBatch(graph)
    batch.set_properties(alice, {"name": "Alice", "age": 34})
    batch.run()
    alice.pull()
    assert alice["name"] == "Alice"
    assert alice["age"] == 34
Example #24
0
def test_path_merging_is_idempotent(graph):
    alice, = graph.create({"name": "Alice"})
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    bob = path.nodes[1]
    assert path.nodes[0] == alice
    assert bob["name"] == "Bob"
    batch = WriteBatch(graph)
    batch.get_or_create_path(alice, "KNOWS", {"name": "Bob"})
    results = batch.submit()
    path = results[0]
    assert path.nodes[0] == alice
    assert path.nodes[1] == bob
Example #25
0
def test_can_delete_property_on_preexisting_node(graph):
    alice, = graph.create({"name": "Alice", "age": 34})
    batch = WriteBatch(graph)
    batch.delete_property(alice, "age")
    batch.run()
    alice.pull()
    assert alice["name"] == "Alice"
    assert alice["age"] is None
Example #26
0
def test_can_delete_property_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_property(alice, "age")
    results = batch.submit()
    alice = results[batch.find(alice)]
    assert alice["name"] == "Alice"
    assert alice["age"] is None
Example #27
0
def test_can_delete_properties_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({"name": "Alice", "age": 34})
    batch.delete_properties(alice)
    results = batch.submit()
    alice = results[batch.find(alice)]
    props = alice.get_properties()
    assert props == {}
Example #28
0
def test_can_set_properties_on_node_in_same_batch(graph):
    batch = WriteBatch(graph)
    alice = batch.create({})
    batch.set_properties(alice, {"name": "Alice", "age": 34})
    results = batch.submit()
    alice = results[batch.find(alice)]
    alice.auto_sync_properties = True
    assert alice["name"] == "Alice"
    assert alice["age"] == 34
Example #29
0
def test_can_add_labels_to_preexisting_node(graph):
    if not graph.supports_node_labels:
        return
    alice, = graph.create({"name": "Alice"})
    batch = WriteBatch(graph)
    batch.add_labels(alice, "human", "female")
    batch.run()
    alice.pull()
    assert alice.labels == {"human", "female"}
Example #30
0
def test_can_remove_labels_from_preexisting_node(graph):
    if not graph.supports_node_labels:
        return
    alice, = graph.create(Node("human", "female", name="Alice"))
    batch = WriteBatch(graph)
    batch.remove_label(alice, "human")
    batch.run()
    alice.pull()
    assert alice.labels == {"female"}
Example #31
0
def test_can_set_labels_on_preexisting_node(graph):
    if not graph.supports_node_labels:
        return
    alice, = graph.create(Node("human", "female", name="Alice"))
    batch = WriteBatch(graph)
    batch.set_labels(alice, "mystery", "badger")
    batch.run()
    alice.pull()
    assert alice.labels == {"mystery", "badger"}