def test_can_execute_example_code(self): class Person(object): def __init__(self, email=None, name=None, age=None): self.email = email self.name = name self.age = age def __str__(self): return self.name graph = Graph() store = Store(graph) alice = Person("*****@*****.**", "Alice", 34) store.save_unique("People", "email", alice.email, alice) bob = Person("*****@*****.**", "Bob", 66) carol = Person("*****@*****.**", "Carol", 42) store.relate(alice, "LIKES", bob) store.relate(alice, "LIKES", carol) store.save(alice) friends = store.load_related(alice, "LIKES", Person) print("Alice likes {0}".format(" and ".join(str(f) for f in friends)))
class TestDelete(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_delete_object(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) node = alice.__node__ assert node.exists self.store.delete(alice) assert not node.exists
class TestDelete(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_delete_object(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) node = alice.__node__ assert node.exists self.store.delete(alice) assert not node.exists
class TestReload(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_reload(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) assert alice.__node__["name"] == "Alice" assert alice.__node__["age"] == 34 alice.__node__["name"] = "Alice Smith" alice.__node__["age"] = 35 alice.__node__.push() self.store.reload(alice) assert alice.name == "Alice Smith" assert alice.age == 35
class TestSave(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_save_simple_object(self): alice = Person("*****@*****.**", "Alice", 34) assert not self.store.is_saved(alice) self.store.save_unique("People", "email", "*****@*****.**", alice) assert self.store.is_saved(alice) assert alice.__node__["name"] == "Alice" assert alice.__node__["age"] == 34 alice.name = "Alice Smith" alice.age = 35 self.store.save(alice) assert alice.__node__["name"] == "Alice Smith" assert alice.__node__["age"] == 35
class TestReload(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_reload(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) assert alice.__node__["name"] == "Alice" assert alice.__node__["age"] == 34 alice.__node__["name"] = "Alice Smith" alice.__node__["age"] = 35 alice.__node__.push() self.store.reload(alice) assert alice.name == "Alice Smith" assert alice.age == 35
class TestSave(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_save_simple_object(self): alice = Person("*****@*****.**", "Alice", 34) assert not self.store.is_saved(alice) self.store.save_unique("People", "email", "*****@*****.**", alice) assert self.store.is_saved(alice) assert alice.__node__["name"] == "Alice" assert alice.__node__["age"] == 34 alice.name = "Alice Smith" alice.age = 35 self.store.save(alice) assert alice.__node__["name"] == "Alice Smith" assert alice.__node__["age"] == 35
class TestSaveUnique(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_save_simple_object(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) assert hasattr(alice, "__node__") assert isinstance(alice.__node__, Node) assert alice.__node__ == self.graph.legacy.get_indexed_node( "People", "email", "*****@*****.**") def test_can_save_object_with_rels(self): alice = Person("*****@*****.**", "Alice Allison", 34) bob_node, carol_node = self.graph.create( {"name": "Bob"}, {"name": "Carol"}, ) alice.__rel__ = {"KNOWS": [({}, bob_node)]} self.store.save_unique("People", "email", "*****@*****.**", alice) assert hasattr(alice, "__node__") assert isinstance(alice.__node__, Node) assert alice.__node__ == self.graph.legacy.get_indexed_node( "People", "email", "*****@*****.**") friend_rels = list(alice.__node__.match_outgoing("KNOWS")) assert len(friend_rels) == 1 assert bob_node in (rel.end_node for rel in friend_rels) alice.__rel__ = {"KNOWS": [({}, bob_node), ({}, carol_node)]} self.store.save_unique("People", "email", "*****@*****.**", alice) friend_rels = list(alice.__node__.match_outgoing("KNOWS")) assert len(friend_rels) == 2 assert bob_node in (rel.end_node for rel in friend_rels) assert carol_node in (rel.end_node for rel in friend_rels)
def test_can_execute_example_code(self): class Person(object): def __init__(self, email=None, name=None, age=None): self.email = email self.name = name self.age = age def __str__(self): return self.name graph = Graph() store = Store(graph) alice = Person("*****@*****.**", "Alice", 34) store.save_unique("People", "email", alice.email, alice) bob = Person("*****@*****.**", "Bob", 66) carol = Person("*****@*****.**", "Carol", 42) store.relate(alice, "LIKES", bob) store.relate(alice, "LIKES", carol) store.save(alice) friends = store.load_related(alice, "LIKES", Person) print("Alice likes {0}".format(" and ".join(str(f) for f in friends)))
class TestSaveUnique(object): @pytest.fixture(autouse=True) def setup(self, graph): self.graph = graph self.store = Store(self.graph) def test_can_save_simple_object(self): alice = Person("*****@*****.**", "Alice", 34) self.store.save_unique("People", "email", "*****@*****.**", alice) assert hasattr(alice, "__node__") assert isinstance(alice.__node__, Node) assert alice.__node__ == self.graph.legacy.get_indexed_node( "People", "email", "*****@*****.**") def test_can_save_object_with_rels(self): alice = Person("*****@*****.**", "Alice Allison", 34) bob_node, carol_node = self.graph.create( {"name": "Bob"}, {"name": "Carol"}, ) alice.__rel__ = {"KNOWS": [({}, bob_node)]} self.store.save_unique("People", "email", "*****@*****.**", alice) assert hasattr(alice, "__node__") assert isinstance(alice.__node__, Node) assert alice.__node__ == self.graph.legacy.get_indexed_node( "People", "email", "*****@*****.**") friend_rels = list(alice.__node__.match_outgoing("KNOWS")) assert len(friend_rels) == 1 assert bob_node in (rel.end_node for rel in friend_rels) alice.__rel__ = {"KNOWS": [({}, bob_node), ({}, carol_node)]} self.store.save_unique("People", "email", "*****@*****.**", alice) friend_rels = list(alice.__node__.match_outgoing("KNOWS")) assert len(friend_rels) == 2 assert bob_node in (rel.end_node for rel in friend_rels) assert carol_node in (rel.end_node for rel in friend_rels)
class Person(object): def __init__(self, email=None, name=None, age=None): self.email = email self.name = name self.age = age def __str__(self): return self.name graph = Graph('http://127.0.0.1:7474/db/data/') store = Store(graph) alice = Person("*****@*****.**", "Tobin", 34) store.save_unique("People", "email", alice.email, alice) bob = Person("*****@*****.**", "Bob", 66) carol = Person("*****@*****.**", "Carol", 42) jenny = Person("*****@*****.**", "Jenny", 43) edgar = Person("*****@*****.**", "Edgar", 44) mike = Person("*****@*****.**", "Mike", 45) store.relate(alice, "LIKES", bob) # these relationships are not saved store.relate(alice, "LIKES", carol) # until `alice` is saved store.relate(alice, "LIKES", jenny) # until `alice` is saved store.relate(alice, "LIKES", edgar) # until `alice` is saved store.relate(alice, "LIKES", mike) # until `alice` is saved store.save(alice) friends = store.load_related(alice, "LIKES", Person) print "Alice likes {0}".format(" and ".join(str(f) for f in friends))