def test_can_pull_node(self): alpha = Node("Person", name="Alice") beta = Node() self.graph.create(alpha) assert set(beta.labels()) == set() assert dict(beta) == {} beta.__remote__ = RemoteEntity(remote(alpha).uri) beta.pull() assert set(beta.labels()) == set(alpha.labels()) assert dict(beta) == dict(alpha)
def test_can_push_node(self): alice_1 = Node("Person", name="Alice") alice_2 = Node() self.graph.create(alice_2) assert set(alice_2.labels()) == set() assert dict(alice_2) == {} alice_1.__remote__ = RemoteEntity(remote(alice_2).uri) alice_1.push() alice_2.pull() assert set(alice_1.labels()) == set(alice_2.labels()) assert dict(alice_1) == dict(alice_2)
def test_can_set_labels_on_preexisting_node(self): alice = Node("human", "female", name="Alice") self.graph.create(alice) self.batch.set_labels(alice, "mystery", "badger") self.batch.run() self.graph.pull(alice) assert set(alice.labels()) == {"mystery", "badger"}
def test_can_remove_labels_from_preexisting_node(self): alice = Node("human", "female", name="Alice") self.graph.create(alice) self.batch.remove_label(alice, "human") self.batch.run() self.graph.pull(alice) assert set(alice.labels()) == {"female"}
def test_can_add_labels_to_preexisting_node(self): alice = Node(name="Alice") self.graph.create(alice) self.batch.add_labels(alice, "human", "female") self.batch.run() self.graph.pull(alice) assert set(alice.labels()) == {"human", "female"}
def test_pull_node_labels_if_stale(self): a = Node("Thing") self.graph.create(a) a.remove_label("Thing") a._Node__stale.add("labels") labels = a.labels() assert set(labels) == {"Thing"}
def test_can_create_remote_node(self): a = Node("Person", name="Alice", age=33) self.graph.create(a) assert set(a.labels()) == {"Person"} assert dict(a) == {"name": "Alice", "age": 33} assert remote(a).ref.startswith("node/") assert repr(remote(a))
def create_object(graph, atype, propertiesdict): """ creates a generic object """ graph = graphs[graph] if 'Unique ID' not in propertiesdict: propertiesdict['Unique ID'] = str(uuid.uuid4()) # if 'thing1' not in propertiesdict: # propertiesdict['thing2'] = atype # if 'label' not in propertiesdict: # propertiesdict['thing3'] = atype # tmpnode = Node(type, propertiesdict) tmpnode = Node(atype, id=propertiesdict['Unique ID']) # print(propertiesdict) for k in propertiesdict: tmpnode[k] = propertiesdict[k] # print (type(tmpnode)) # print(dict(tmpnode)) # print(type(propertiesdict)) # exit() graph.create(tmpnode) graph.push(tmpnode) tmpnode["nodeType"] = list(tmpnode.labels())[0] return tmpnode
def test_node_equality(self): alice_1 = Node(name="Alice", age=34) alice_2 = Node(name="Alice", age=34) assert set(alice_1.labels()) == set(alice_2.labels()) assert dict(alice_1) == dict(alice_2)
def test_unbound_node_equality(self): alice_1 = Node("Person", name="Alice") alice_2 = Node("Person", name="Alice") assert set(alice_1.labels()) == set(alice_2.labels()) assert dict(alice_1) == dict(alice_2)
def test_bound_node_equals_unbound_node_with_same_properties(self): alice_1 = Node(name="Alice") alice_1.__remote__ = RemoteEntity("http://localhost:7474/db/data/node/1") alice_2 = Node(name="Alice") assert set(alice_1.labels()) == set(alice_2.labels()) assert dict(alice_1) == dict(alice_2)
def test_can_create_local_node(self): a = Node("Person", name="Alice", age=33) assert set(a.labels()) == {"Person"} assert dict(a) == {"name": "Alice", "age": 33}