Exemplo n.º 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
Exemplo n.º 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 == {}
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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"}
Exemplo n.º 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
Exemplo n.º 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"
Exemplo n.º 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"
Exemplo n.º 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"}
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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"}
Exemplo n.º 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"}
Exemplo n.º 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
Exemplo n.º 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"}
Exemplo n.º 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"}
Exemplo n.º 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
Exemplo n.º 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 == {}
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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 == {}
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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 == {}
Exemplo n.º 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
Exemplo n.º 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"}
Exemplo n.º 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"}
Exemplo n.º 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"}