def test_auto_rollback(self): """ Sessions created without explicit transactions automatically rollback. """ with SessionContext(self.graph): self.store.create(self.person) with SessionContext(self.graph): people = self.store.search(name=self.name) assert_that( people, is_(empty()), )
def test_transaction_commit(self): """ Explicit transactions persist across sessions. """ with SessionContext(self.graph), transaction(): self.store.create(self.person) with SessionContext(self.graph): people = self.store.search(name=self.name) assert_that( people, contains(matches_person(self.person), ), )
def test_create_with_missing_dependency(self): with SessionContext(self.graph): self.person_store.create(self.left) assert_that( calling(self.store.create).with_args(self.relationship), raises(MissingDependencyError), )
def test_count(self): with SessionContext(self.graph): self.store.create(self.node) assert_that( self.store.count(), is_(equal_to(1)), )
def setup(self): self.graph = create_object_graph("microcosm_neo4j", testing=True) self.store = PersonStore(self.graph) with SessionContext(self.graph) as context: context.recreate_all() self.node = Person(name="name")
def test_delete(self): with SessionContext(self.graph): self.store.create(self.node) assert_that( self.store.delete(self.node.id), is_(equal_to(True)), )
def test_retrieve(self): with SessionContext(self.graph): self.store.create(self.node) assert_that( self.store.retrieve(self.node.id), is_(equal_to(self.node)), )
def test_search(self): with SessionContext(self.graph): self.store.create(self.node) assert_that( self.store.search(), contains(matches_person(self.node), ), )
def test_transaction_rollback_on_error(self): """ Errors raised during a transaction cause a rollback. """ with SessionContext(self.graph): try: with transaction(): self.store.create(self.person) raise Break() except Break: pass with SessionContext(self.graph): people = self.store.search(name=self.name) assert_that(people, is_(empty()))
def test_retrieve(self): with SessionContext(self.graph): self.person_store.create(self.left) self.person_store.create(self.right) self.store.create(self.relationship) assert_that( self.store.retrieve(self.relationship.id), is_(equal_to(self.relationship)), )
def test_count(self): with SessionContext(self.graph): self.person_store.create(self.left) self.person_store.create(self.right) self.store.create(self.relationship) assert_that( self.store.count(), is_(equal_to(1)), )
def test_upsert_search(self): with SessionContext(self.graph): self.person_store.create(self.left) self.person_store.create(self.right) self.store.create(self.relationship) self.store.create(self.relationship) assert_that( self.store.search(), has_length(1), )
def test_upsert(self): with SessionContext(self.graph): self.store.create(self.node) assert_that( self.store.create(self.node), matches_person(self.node), ) assert_that( self.store.count(), is_(equal_to(1)), )
def main(graph): """ Create and drop databases. """ args = parse_args(graph) with SessionContext(graph): if args.drop: warn( "Deleting all Neo4J nodes is not recommended for production systems. " "Delete Neo4J file system data instead.") graph.neo4j_schema_manager.drop_all(force=True) graph.neo4j_schema_manager.create_all()
def setup(self): self.graph = create_object_graph("microcosm_neo4j", testing=True) self.person_store = PersonStore(self.graph) self.store = IsFriendsWithStore(self.graph) with SessionContext(self.graph) as context: context.recreate_all() self.left = Person(name="left") self.right = Person(name="right") self.relationship = IsFriendsWith( in_id=self.left.id, out_id=self.right.id, )
def test_search_filter(self): other = Person(name="other") with SessionContext(self.graph): self.store.create(self.node) self.store.create(other) assert_that( self.store.search(), contains_inanyorder( matches_person(self.node), matches_person(other), ), ) assert_that( self.store.search(name=self.node.name), contains(matches_person(self.node), ), )
def test_retrieve_not_found(self): with SessionContext(self.graph): assert_that( calling(self.store.retrieve).with_args(self.node.id), raises(NotFoundError), )
def test_delete_not_found(self): with SessionContext(self.graph): assert_that( self.store.delete(self.node.id), is_(equal_to(False)), )
def test_create(self): with SessionContext(self.graph): self.person_store.create(self.left) self.person_store.create(self.right) self.store.create(self.relationship)
def test_create(self): with SessionContext(self.graph): assert_that( self.store.create(self.node), matches_person(self.node), )