def test_api___simple_search_ok__by_comment_content( self, created_content_name, search_string, nb_content_result, first_search_result_content_name, first_created_comment_content, second_created_comment_content, ) -> None: dbsession = get_tm_session(self.session_factory, transaction.manager) admin = dbsession.query(User).filter(User.email == "*****@*****.**").one() uapi = UserApi(current_user=admin, session=dbsession, config=self.app_config) gapi = GroupApi(current_user=admin, session=dbsession, config=self.app_config) groups = [gapi.get_one_with_name("trusted-users")] user = uapi.create_user( "*****@*****.**", password="******", do_save=True, do_notify=False, groups=groups, ) workspace_api = WorkspaceApi( current_user=admin, session=dbsession, config=self.app_config, show_deleted=True ) workspace = workspace_api.create_workspace("test", save_now=True) rapi = RoleApi(current_user=admin, session=dbsession, config=self.app_config) rapi.create_one(user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, False) api = ContentApi(session=dbsession, current_user=user, config=self.app_config) content = api.create( content_type_slug="html-document", workspace=workspace, label=created_content_name, do_save=True, ) api.create_comment( workspace=workspace, parent=content, content=first_created_comment_content, do_save=True ) api.create_comment( workspace=workspace, parent=content, content=second_created_comment_content, do_save=True, ) api.create( content_type_slug="html-document", workspace=workspace, label="report", do_save=True ) api.create( content_type_slug="thread", workspace=workspace, label="discussion", do_save=True ) transaction.commit() self.testapp.authorization = ("Basic", ("*****@*****.**", "*****@*****.**")) params = {"search_string": search_string} res = self.testapp.get("/api/v2/search/content".format(), status=200, params=params) search_result = res.json_body assert search_result assert search_result["total_hits"] == nb_content_result assert search_result["is_total_hits_accurate"] is False assert search_result["contents"][0]["label"] == first_search_result_content_name
def test_func__create_comment_with_notification__ok__nominal_case(self): uapi = UserApi( current_user=None, session=self.session, config=self.app_config, ) current_user = uapi.get_one_by_email('*****@*****.**') # set admin as french, useful to verify if i18n work properly current_user.lang = 'fr' # Create new user with notification enabled on w1 workspace wapi = WorkspaceApi( current_user=current_user, session=self.session, config=self.app_config, ) workspace = wapi.get_one_by_label('Recipes') user = uapi.get_one_by_email('*****@*****.**') wapi.enable_notifications(user, workspace) api = ContentApi( current_user=user, session=self.session, config=self.app_config, ) item = api.create( content_type_list.Folder.slug, workspace, None, 'parent', do_save=True, do_notify=False, ) item2 = api.create( content_type_list.File.slug, workspace, item, 'file1', do_save=True, do_notify=False, ) api.create_comment(parent=item2, content='My super comment', do_save=True, do_notify=True) transaction.commit() # check mail received response = requests.get('http://127.0.0.1:8025/api/v1/messages') response = response.json() headers = response[0]['Content']['Headers'] assert headers['From'][ 0] == '"Bob i. via Tracim" <test_user_from+3@localhost>' # nopep8 assert headers['To'][0] == 'Global manager <*****@*****.**>' assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)' assert headers['References'][0] == 'test_user_refs+22@localhost' assert headers['Reply-to'][ 0] == '"Bob i. & all members of Recipes" <test_user_reply+22@localhost>' # nopep8
def test_func__create_comment_with_notification__ok__nominal_case(self): uapi = UserApi( current_user=None, session=self.session, config=self.app_config, ) current_user = uapi.get_one_by_email('*****@*****.**') # set admin as french, useful to verify if i18n work properly current_user.lang = 'fr' # Create new user with notification enabled on w1 workspace wapi = WorkspaceApi( current_user=current_user, session=self.session, config=self.app_config, ) workspace = wapi.get_one_by_label('Recipes') user = uapi.get_one_by_email('*****@*****.**') wapi.enable_notifications(user, workspace) api = ContentApi( current_user=user, session=self.session, config=self.app_config, ) item = api.create( content_type_list.Folder.slug, workspace, None, 'parent', do_save=True, do_notify=False, ) item2 = api.create( content_type_list.File.slug, workspace, item, 'file1', do_save=True, do_notify=False, ) api.create_comment(parent=item2, content='My super comment', do_save=True, do_notify=True) transaction.commit() # check mail received response = self.get_mailhog_mails() headers = response[0]['Content']['Headers'] assert headers['From'][0] == '"Bob i. via Tracim" <test_user_from+3@localhost>' # nopep8 assert headers['To'][0] == 'Global manager <*****@*****.**>' assert headers['Subject'][0] == '[TRACIM] [Recipes] file1 (Open)' assert headers['References'][0] == 'test_user_refs+22@localhost' assert headers['Reply-to'][0] == '"Bob i. & all members of Recipes" <test_user_reply+22@localhost>' # nopep8
def add_comment(self, context, request: TracimRequest, hapic_data=None): """ Add new comment """ # login = hapic_data.body app_config = request.registry.settings["CFG"] # type: CFG api = ContentApi( show_archived=True, show_deleted=True, current_user=request.current_user, session=request.dbsession, config=app_config, ) content = api.get_one(hapic_data.path.content_id, content_type=content_type_list.Any_SLUG) comment = api.create_comment(content.workspace, content, hapic_data.body.raw_content, do_save=True) return api.get_content_in_context(comment)
def add_comment(self, context, request: TracimRequest, hapic_data=None): """ Add new comment """ # login = hapic_data.body app_config = request.registry.settings['CFG'] api = ContentApi( show_archived=True, show_deleted=True, current_user=request.current_user, session=request.dbsession, config=app_config, ) content = api.get_one( hapic_data.path.content_id, content_type=content_type_list.Any_SLUG ) comment = api.create_comment( content.workspace, content, hapic_data.body.raw_content, do_save=True, ) return api.get_content_in_context(comment)
def upload_files( self, upload_permission: UploadPermission, uploader_username: str, message: typing.Optional[str], files: typing.List[cgi.FieldStorage], do_notify: bool = False, ) -> typing.List[ContentInContext]: content_api = ContentApi( config=self._config, current_user=upload_permission.author, session=self._session, namespaces_filter=[ContentNamespaces.UPLOAD], ) translator = Translator(app_config=self._config) _ = translator.get_translation current_datetime = datetime.utcnow() folder_label = _( "Files uploaded by {username} on {date} at {time}").format( username=uploader_username, date=format_date(current_datetime, locale=translator.default_lang), time=format_time(current_datetime, locale=translator.default_lang), ) try: upload_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=upload_permission.workspace, label=folder_label, do_notify=False, do_save=True, content_namespace=ContentNamespaces.UPLOAD, ) except ContentFilenameAlreadyUsedInFolder: upload_folder = content_api.get_one_by_filename( filename=folder_label, workspace=upload_permission.workspace) created_contents = [] if message: comment_message = _("Message from {username}: {message}").format( username=uploader_username, message=message) else: comment_message = _("Uploaded by {username}.").format( username=uploader_username) for _file in files: content = content_api.create( filename=_file.filename, content_type_slug=content_type_list.File.slug, workspace=upload_permission.workspace, parent=upload_folder, do_notify=False, content_namespace=ContentNamespaces.UPLOAD, ) content_api.save(content, ActionDescription.CREATION) with new_revision(session=self._session, tm=transaction.manager, content=content): content_api.update_file_data( content, new_filename=_file.filename, new_mimetype=_file.type, new_content=_file.file, ) content_api.create_comment(parent=content, content=comment_message, do_save=True, do_notify=False) created_contents.append( content_api.get_content_in_context(content)) content_api.execute_created_content_actions(content) if do_notify: workspace_lib = WorkspaceApi(config=self._config, current_user=upload_permission.author, session=self._session) self._notify_uploaded_contents( uploader_username=uploader_username, workspace_in_context=workspace_lib.get_workspace_with_context( upload_permission.workspace), uploader_message=message, uploaded_contents=created_contents, uploader_email=upload_permission.email, ) return created_contents
def insert(self): admin = self._session.query(User) \ .filter(User.email == '*****@*****.**') \ .one() bob = self._session.query(User) \ .filter(User.email == '*****@*****.**') \ .one() john_the_reader = self._session.query(User) \ .filter(User.email == '*****@*****.**') \ .one() admin_workspace_api = WorkspaceApi( current_user=admin, session=self._session, config=self._config, ) bob_workspace_api = WorkspaceApi( current_user=bob, session=self._session, config=self._config ) content_api = ContentApi( current_user=admin, session=self._session, config=self._config ) bob_content_api = ContentApi( current_user=bob, session=self._session, config=self._config ) reader_content_api = ContentApi( current_user=john_the_reader, session=self._session, config=self._config ) role_api = RoleApi( current_user=admin, session=self._session, config=self._config, ) # Workspaces business_workspace = admin_workspace_api.create_workspace( 'Business', description='All importants documents', save_now=True, ) recipe_workspace = admin_workspace_api.create_workspace( 'Recipes', description='Our best recipes', save_now=True, ) other_workspace = bob_workspace_api.create_workspace( 'Others', description='Other Workspace', save_now=True, ) # Workspaces roles role_api.create_one( user=bob, workspace=recipe_workspace, role_level=UserRoleInWorkspace.CONTENT_MANAGER, with_notif=False, ) role_api.create_one( user=john_the_reader, workspace=recipe_workspace, role_level=UserRoleInWorkspace.READER, with_notif=False, ) # Folders tool_workspace = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label='Tools', do_save=True, do_notify=False, ) menu_workspace = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label='Menus', do_save=True, do_notify=False, ) dessert_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Desserts', do_save=True, do_notify=False, ) salads_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Salads', do_save=True, do_notify=False, ) other_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=other_workspace, label='Infos', do_save=True, do_notify=False, ) # Pages, threads, .. tiramisu_page = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=dessert_folder, label='Tiramisu Recipes!!!', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=tiramisu_page, ): content_api.update_content( item=tiramisu_page, new_content='<p>To cook a greet Tiramisu, you need many ingredients.</p>', # nopep8 new_label='Tiramisu Recipes!!!', ) content_api.save(tiramisu_page) best_cake_thread = content_api.create( content_type_slug=content_type_list.Thread.slug, workspace=recipe_workspace, parent=dessert_folder, label='Best Cake', do_save=False, do_notify=False, ) best_cake_thread.description = 'Which is the best cake?' self._session.add(best_cake_thread) apple_pie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label='Apple_Pie', do_save=False, do_notify=False, ) apple_pie_recipe.file_extension = '.txt' apple_pie_recipe.depot_file = FileIntent( b'Apple pie Recipe', 'apple_Pie.txt', 'text/plain', ) self._session.add(apple_pie_recipe) Brownie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label='Brownie Recipe', do_save=False, do_notify=False, ) Brownie_recipe.file_extension = '.html' Brownie_recipe.depot_file = FileIntent( b'<p>Brownie Recipe</p>', 'brownie_recipe.html', 'text/html', ) self._session.add(Brownie_recipe) fruits_desserts_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Fruits Desserts', parent=dessert_folder, do_save=True, ) menu_page = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=business_workspace, parent=menu_workspace, label='Current Menu', do_save=True, ) new_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='New Fruit Salad', do_save=True, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='Fruit Salad', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=old_fruit_salad, ): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='Bad Fruit Salad', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=bad_fruit_salad, ): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad) # File at the root for test new_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='New Fruit Salad', do_save=True, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='Fruit Salad', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=old_fruit_salad, ): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='Bad Fruit Salad', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=bad_fruit_salad, ): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad) content_api.create_comment( parent=best_cake_thread, content='<p>What is for you the best cake ever? </br> I personnally vote for Chocolate cupcake!</p>', # nopep8 do_save=True, ) bob_content_api.create_comment( parent=best_cake_thread, content='<p>What about Apple Pie? There are Awesome!</p>', do_save=True, ) reader_content_api.create_comment( parent=best_cake_thread, content='<p>You are right, but Kouign-amann are clearly better.</p>', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=best_cake_thread, ): bob_content_api.update_content( item=best_cake_thread, new_content='What is the best cake?', new_label='Best Cakes?', ) bob_content_api.save(best_cake_thread) with new_revision( session=self._session, tm=transaction.manager, content=tiramisu_page, ): bob_content_api.update_content( item=tiramisu_page, new_content='<p>To cook a great Tiramisu, you need many ingredients.</p>', # nopep8 new_label='Tiramisu Recipe', ) bob_content_api.save(tiramisu_page) self._session.flush()
def insert(self): admin = self._session.query(User).filter(User.email == "*****@*****.**").one() bob = self._session.query(User).filter(User.email == "*****@*****.**").one() john_the_reader = ( self._session.query(User).filter(User.email == "*****@*****.**").one() ) admin_workspace_api = WorkspaceApi( current_user=admin, session=self._session, config=self._config ) bob_workspace_api = WorkspaceApi( current_user=bob, session=self._session, config=self._config ) content_api = ContentApi(current_user=admin, session=self._session, config=self._config) bob_content_api = ContentApi(current_user=bob, session=self._session, config=self._config) reader_content_api = ContentApi( current_user=john_the_reader, session=self._session, config=self._config ) role_api = RoleApi(current_user=admin, session=self._session, config=self._config) # Workspaces business_workspace = admin_workspace_api.create_workspace( "Business", description="All importants documents", save_now=True ) recipe_workspace = admin_workspace_api.create_workspace( "Recipes", description="Our best recipes", save_now=True ) other_workspace = bob_workspace_api.create_workspace( "Others", description="Other Workspace", save_now=True ) # Workspaces roles role_api.create_one( user=bob, workspace=recipe_workspace, role_level=UserRoleInWorkspace.CONTENT_MANAGER, with_notif=False, ) role_api.create_one( user=john_the_reader, workspace=recipe_workspace, role_level=UserRoleInWorkspace.READER, with_notif=False, ) # Folders content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label="Tools", do_save=True, do_notify=False, ) menu_workspace = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label="Menus", do_save=True, do_notify=False, ) dessert_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label="Desserts", do_save=True, do_notify=False, ) content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label="Salads", do_save=True, do_notify=False, ) content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=other_workspace, label="Infos", do_save=True, do_notify=False, ) # Pages, threads, .. tiramisu_page = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=dessert_folder, label="Tiramisu Recipes!!!", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=tiramisu_page): content_api.update_content( item=tiramisu_page, new_content="<p>To cook a greet Tiramisu, you need many ingredients.</p>", new_label="Tiramisu Recipes!!!", ) content_api.save(tiramisu_page, do_notify=False) best_cake_thread = content_api.create( content_type_slug=content_type_list.Thread.slug, workspace=recipe_workspace, parent=dessert_folder, label="Best Cake", do_save=False, do_notify=False, ) best_cake_thread.description = "Which is the best cake?" self._session.add(best_cake_thread) apple_pie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label="Apple_Pie", do_save=False, do_notify=False, ) apple_pie_recipe.file_extension = ".txt" apple_pie_recipe.depot_file = FileIntent(b"Apple pie Recipe", "apple_Pie.txt", "text/plain") self._session.add(apple_pie_recipe) brownie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label="Brownie Recipe", do_save=False, do_notify=False, ) brownie_recipe.file_extension = ".html" brownie_recipe.depot_file = FileIntent( b"<p>Brownie Recipe</p>", "brownie_recipe.html", "text/html" ) self._session.add(brownie_recipe) fruits_desserts_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label="Fruits Desserts", parent=dessert_folder, do_save=True, do_notify=False, ) content_api.create( content_type_slug=content_type_list.Page.slug, workspace=business_workspace, parent=menu_workspace, label="Current Menu", do_save=True, do_notify=False, ) content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label="New Fruit Salad", do_save=True, do_notify=False, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label="Fruit Salad", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=old_fruit_salad): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad, do_notify=False) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label="Bad Fruit Salad", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=bad_fruit_salad): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad, do_notify=False) # File at the root for test content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label="New Fruit Salad", do_save=True, do_notify=False, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label="Fruit Salad", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=old_fruit_salad): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad, do_notify=False) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label="Bad Fruit Salad", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=bad_fruit_salad): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad, do_notify=False) content_api.create_comment( parent=best_cake_thread, content="<p>What is for you the best cake ever? <br/> I personnally vote for Chocolate cupcake!</p>", do_save=True, do_notify=False, ) bob_content_api.create_comment( parent=best_cake_thread, content="<p>What about Apple Pie? There are Awesome!</p>", do_save=True, do_notify=False, ) reader_content_api.create_comment( parent=best_cake_thread, content="<p>You are right, but Kouign-amann are clearly better.</p>", do_save=True, do_notify=False, ) with new_revision(session=self._session, tm=transaction.manager, content=best_cake_thread): bob_content_api.update_content( item=best_cake_thread, new_content="What is the best cake?", new_label="Best Cakes?" ) bob_content_api.save(best_cake_thread, do_notify=False) with new_revision(session=self._session, tm=transaction.manager, content=tiramisu_page): bob_content_api.update_content( item=tiramisu_page, new_content="<p>To cook a great Tiramisu, you need many ingredients.</p>", new_label="Tiramisu Recipe", ) bob_content_api.save(tiramisu_page, do_notify=False) self._session.flush()
def insert(self): admin = self._session.query(models.User) \ .filter(models.User.email == '*****@*****.**') \ .one() bob = self._session.query(models.User) \ .filter(models.User.email == '*****@*****.**') \ .one() john_the_reader = self._session.query(models.User) \ .filter(models.User.email == '*****@*****.**') \ .one() admin_workspace_api = WorkspaceApi( current_user=admin, session=self._session, config=self._config, ) bob_workspace_api = WorkspaceApi(current_user=bob, session=self._session, config=self._config) content_api = ContentApi(current_user=admin, session=self._session, config=self._config) bob_content_api = ContentApi(current_user=bob, session=self._session, config=self._config) reader_content_api = ContentApi(current_user=john_the_reader, session=self._session, config=self._config) role_api = RoleApi( current_user=admin, session=self._session, config=self._config, ) # Workspaces business_workspace = admin_workspace_api.create_workspace( 'Business', description='All importants documents', save_now=True, ) recipe_workspace = admin_workspace_api.create_workspace( 'Recipes', description='Our best recipes', save_now=True, ) other_workspace = bob_workspace_api.create_workspace( 'Others', description='Other Workspace', save_now=True, ) # Workspaces roles role_api.create_one( user=bob, workspace=recipe_workspace, role_level=UserRoleInWorkspace.CONTENT_MANAGER, with_notif=False, ) role_api.create_one( user=john_the_reader, workspace=recipe_workspace, role_level=UserRoleInWorkspace.READER, with_notif=False, ) # Folders tool_workspace = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label='Tools', do_save=True, do_notify=False, ) menu_workspace = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=business_workspace, label='Menus', do_save=True, do_notify=False, ) dessert_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Desserts', do_save=True, do_notify=False, ) salads_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Salads', do_save=True, do_notify=False, ) other_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=other_workspace, label='Infos', do_save=True, do_notify=False, ) # Pages, threads, .. tiramisu_page = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=dessert_folder, label='Tiramisu Recipes!!!', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=tiramisu_page, ): content_api.update_content( item=tiramisu_page, new_content= '<p>To cook a greet Tiramisu, you need many ingredients.</p>', # nopep8 new_label='Tiramisu Recipes!!!', ) content_api.save(tiramisu_page) best_cake_thread = content_api.create( content_type_slug=content_type_list.Thread.slug, workspace=recipe_workspace, parent=dessert_folder, label='Best Cake', do_save=False, do_notify=False, ) best_cake_thread.description = 'Which is the best cake?' self._session.add(best_cake_thread) apple_pie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label='Apple_Pie', do_save=False, do_notify=False, ) apple_pie_recipe.file_extension = '.txt' apple_pie_recipe.depot_file = FileIntent( b'Apple pie Recipe', 'apple_Pie.txt', 'text/plain', ) self._session.add(apple_pie_recipe) Brownie_recipe = content_api.create( content_type_slug=content_type_list.File.slug, workspace=recipe_workspace, parent=dessert_folder, label='Brownie Recipe', do_save=False, do_notify=False, ) Brownie_recipe.file_extension = '.html' Brownie_recipe.depot_file = FileIntent( b'<p>Brownie Recipe</p>', 'brownie_recipe.html', 'text/html', ) self._session.add(Brownie_recipe) fruits_desserts_folder = content_api.create( content_type_slug=content_type_list.Folder.slug, workspace=recipe_workspace, label='Fruits Desserts', parent=dessert_folder, do_save=True, ) menu_page = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=business_workspace, parent=menu_workspace, label='Current Menu', do_save=True, ) new_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='New Fruit Salad', do_save=True, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='Fruit Salad', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=old_fruit_salad, ): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=recipe_workspace, parent=fruits_desserts_folder, label='Bad Fruit Salad', do_save=True, do_notify=False, ) with new_revision( session=self._session, tm=transaction.manager, content=bad_fruit_salad, ): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad) # File at the root for test new_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='New Fruit Salad', do_save=True, ) old_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='Fruit Salad', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=old_fruit_salad, ): content_api.archive(old_fruit_salad) content_api.save(old_fruit_salad) bad_fruit_salad = content_api.create( content_type_slug=content_type_list.Page.slug, workspace=other_workspace, label='Bad Fruit Salad', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=bad_fruit_salad, ): content_api.delete(bad_fruit_salad) content_api.save(bad_fruit_salad) content_api.create_comment( parent=best_cake_thread, content= '<p>What is for you the best cake ever? </br> I personnally vote for Chocolate cupcake!</p>', # nopep8 do_save=True, ) bob_content_api.create_comment( parent=best_cake_thread, content='<p>What about Apple Pie? There are Awesome!</p>', do_save=True, ) reader_content_api.create_comment( parent=best_cake_thread, content= '<p>You are right, but Kouign-amann are clearly better.</p>', do_save=True, ) with new_revision( session=self._session, tm=transaction.manager, content=best_cake_thread, ): bob_content_api.update_content( item=best_cake_thread, new_content='What is the best cake?', new_label='Best Cakes?', ) bob_content_api.save(best_cake_thread) with new_revision( session=self._session, tm=transaction.manager, content=tiramisu_page, ): bob_content_api.update_content( item=tiramisu_page, new_content= '<p>To cook a great Tiramisu, you need many ingredients.</p>', # nopep8 new_label='Tiramisu Recipe', ) bob_content_api.save(tiramisu_page) self._session.flush()