async def test_events(async_db: AsyncArangoDB, test_collection: StandardCollection) -> None: tc = test_collection.name with pytest.raises(Exception): async with async_db.begin_transaction(read=[tc], write=[tc]) as tx: await tx.insert(tc, {"_key": "foo"}) raise Exception("foo") result = list(await async_db.all(tc)) assert len(result) == 0 async with async_db.begin_transaction(read=[tc], write=[tc]) as tx: await tx.insert(tc, {"_key": "foo"}) result = list(await async_db.all(tc)) assert len(result) == 1
def __init__( self, arango_database: StandardDatabase, event_sender: AnalyticsEventSender, adjust_node: AdjustNode, config: CoreConfig, model_name: str = "model", subscriber_name: str = "subscribers", running_task_name: str = "running_tasks", job_name: str = "jobs", deferred_edge_name: str = "deferred_outer_edges", config_entity: str = "configs", config_validation_entity: str = "config_validation", configs_model: str = "configs_model", template_entity: str = "templates", ): self.event_sender = event_sender self.database = arango_database self.db = AsyncArangoDB(arango_database) self.adjust_node = adjust_node self.model_db = EventEntityDb(model_db(self.db, model_name), event_sender, model_name) self.subscribers_db = EventEntityDb( subscriber_db(self.db, subscriber_name), event_sender, subscriber_name) self.running_task_db = running_task_db(self.db, running_task_name) self.pending_outer_edge_db = outer_edge_db(self.db, deferred_edge_name) self.job_db = job_db(self.db, job_name) self.config_entity_db = config_entity_db(self.db, config_entity) self.config_validation_entity_db = config_validation_entity_db( self.db, config_validation_entity) self.configs_model_db = model_db(self.db, configs_model) self.template_entity_db = template_entity_db(self.db, template_entity) self.graph_dbs: Dict[str, GraphDB] = {} self.config = config self.cleaner = Periodic("outdated_updates_cleaner", self.check_outdated_updates, timedelta(seconds=60))
async def async_db(test_db: StandardDatabase) -> AsyncArangoDB: return AsyncArangoDB(test_db)
async def graph_db(test_db: StandardDatabase) -> ArangoGraphDB: async_db = AsyncArangoDB(test_db) graph_db = ArangoGraphDB(async_db, "ns", NoAdjust()) await graph_db.create_update_schema() await async_db.truncate(graph_db.in_progress) return graph_db
async def subscriber_db(test_db: StandardDatabase) -> SubscriberDb: async_db = AsyncArangoDB(test_db) subscriber_db = subscriberdb.subscriber_db(async_db, "subscriber") await subscriber_db.create_update_schema() await subscriber_db.wipe() return subscriber_db
async def model_db(test_db: StandardDatabase) -> ModelDb: async_db = AsyncArangoDB(test_db) model_db = modeldb.model_db(async_db, "model") await model_db.create_update_schema() await model_db.wipe() return model_db
async def validation_db(test_db: StandardDatabase) -> ConfigValidationEntityDb: async_db = AsyncArangoDB(test_db) cfg_db = configdb.config_validation_entity_db(async_db, "config_models") await cfg_db.create_update_schema() await cfg_db.wipe() return cfg_db
async def template_db(test_db: StandardDatabase) -> TemplateEntityDb: async_db = AsyncArangoDB(test_db) template_db = templatedb.template_entity_db(async_db, "templates") await template_db.create_update_schema() await template_db.wipe() return template_db
async def job_db(test_db: StandardDatabase) -> JobDb: async_db = AsyncArangoDB(test_db) job_db = jobdb.job_db(async_db, "jobs") await job_db.create_update_schema() await job_db.wipe() return job_db
async def running_task_db(test_db: StandardDatabase) -> RunningTaskDb: async_db = AsyncArangoDB(test_db) task_db = runningtaskdb.running_task_db(async_db, "running_task") await task_db.create_update_schema() await task_db.wipe() return task_db