async def __call__(self): content_id = self.context.id parent = self.context.__parent__ await notify(BeforeObjectRemovedEvent(self.context, parent, content_id)) self.context._p_jar.delete(self.context) await notify(ObjectRemovedEvent(self.context, parent, content_id))
async def create(self, arguments, db): if arguments.force: async with transaction(db=db) as txn: tm = task_vars.tm.get() root = await tm.get_root(txn=txn) if await root.async_contains(arguments.name): context = await root.async_get(arguments.name) content_id = context.id parent = context.__parent__ await notify( BeforeObjectRemovedEvent(context, parent, content_id)) txn.delete(context) await notify( ObjectRemovedEvent(context, parent, content_id)) site = None async with transaction(db=db) as txn: tm = task_vars.tm.get() root = await tm.get_root(txn=txn) try: site = await create_content_in_container(root, "Site", arguments.name, check_security=False) await addons.install(site, "cms") await addons.install(site, "dbusers") workflow = IWorkflow(site) await workflow.do_action("publish", "Initial setup") except ConflictIdOnContainer: pass if site is None: return async with transaction(db=db) as txn: await txn.refresh(site) groups = await site.async_get("groups") obj = await create_content_in_container(groups, "Group", "Managers", check_security=False) obj.user_roles = [ "guillotina.Manager", "guillotina.ContainerAdmin", "guillotina.Owner", ] obj.register() async with transaction(db=db) as txn: await txn.refresh(site) users = await site.async_get("users") obj: IUser = await create_content_in_container( users, "User", "admin", check_security=False) await obj.set_password("admin") obj.groups = ["Managers"]
async def test_unindex_during_next_index(es_requester): async with es_requester as requester: await add_content(requester, 2) container, request, txn, tm = await setup_txn_on_container(requester) search = get_utility(ICatalogUtility) index_manager = get_adapter(container, IIndexManager) work_index_name = await index_manager.start_migration() await search.create_index(work_index_name, index_manager) await tm.commit(txn=txn) container, request, txn, tm = await setup_txn_on_container(requester) keys = await container.async_keys() item = await container.async_get(keys[0]) aiotask_context.set('request', request) await notify(ObjectRemovedEvent(item, container, item.id)) request.execute_futures() await asyncio.sleep(1)
async def test_unindex_during_next_index(es_requester): async with es_requester as requester: await add_content(requester, 2) container, request, txn, tm = await setup_txn_on_container(requester) search = getUtility(ICatalogUtility) migrator = Migrator(search, container, force=True, request=request) next_index_version, work_index_name = await migrator.create_next_index( ) await search.install_mappings_on_index(work_index_name) await search.activate_next_index(container, next_index_version, request=request) await tm.commit(txn=txn) container, request, txn, tm = await setup_txn_on_container(requester) keys = await container.async_keys() item = await container.async_get(keys[0]) aiotask_context.set('request', request) await notify(ObjectRemovedEvent(item, container, item.id)) request.execute_futures() await asyncio.sleep(1)
def test_event_raises_configuration_error(dummy_guillotina): ob = create_content() with pytest.raises(ConfigurationError): event.condition(ob, None, ObjectRemovedEvent(ob), {'event_name': 'foobar'})
def test_event_condition_does_not_match(dummy_guillotina): ob = create_content() assert not event.condition(ob, None, ObjectRemovedEvent(ob), {'event_name': 'add'})