def test_unit__crud_caller__ok__workspace(self, session): hook = WorkspaceHookImpl() session.context.plugin_manager.register(hook) owner = User(email="john") session.add(owner) session.flush() workspace = Workspace(label="Hello", owner_id=owner.user_id) session.add(workspace) session.flush() hook.mock_hooks.assert_called_with("created", workspace=workspace, context=session.context) workspace.label = "World" session.flush() hook.mock_hooks.assert_called_with("modified", workspace=workspace, context=session.context) session.delete(workspace) session.flush() hook.mock_hooks.assert_called_with("deleted", workspace=workspace, context=session.context)
def update_workspace( self, workspace: Workspace, label: typing.Optional[str] = None, description: typing.Optional[str] = None, save_now: bool = False, agenda_enabled: typing.Optional[bool] = None, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if label is not None: if label == "": raise EmptyLabelNotAllowed("Workspace label cannot be empty") if (self._session.query(Workspace).filter( Workspace.label == label ).filter(Workspace.workspace_id != workspace.workspace_id).count() > 0): raise WorkspaceLabelAlreadyUsed( "A workspace with label {} already exist.".format(label)) workspace.label = label if description is not None: workspace.description = description if agenda_enabled is not None: workspace.agenda_enabled = agenda_enabled workspace.updated = datetime.utcnow() if save_now: self.save(workspace) return workspace
def update_workspace( self, workspace: Workspace, label: str, description: str, save_now: bool = False, agenda_enabled: bool = None, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if not label: raise EmptyLabelNotAllowed("Workspace label cannot be empty") workspace.label = label workspace.description = description if agenda_enabled is not None: workspace.agenda_enabled = agenda_enabled if save_now: self.save(workspace) return workspace
def delete(self, workspace: Workspace, flush=True): workspace.is_deleted = True label = "{label}-{action}-{date}".format( label=workspace.label, action="deleted", date=current_date_for_filename()) workspace.label = label if flush: self._session.flush()
def test_safe_update__ok__nominal_case(self, session, app_config, admin_user) -> None: assert session.query(Workspace).all() == [] cleanup_lib = CleanupLib(app_config=app_config, session=session, dry_run_mode=False) test_workspace = Workspace() test_workspace.owner_id = admin_user.user_id cleanup_lib.safe_update(test_workspace) transaction.commit() assert session.query(Workspace).one() == test_workspace
def test_safe_update__ok__dry_run(self, session, app_config, admin_user) -> None: assert session.query(Workspace).all() == [] cleanup_lib = CleanupLib(app_config=app_config, session=session, dry_run_mode=True) test_workspace = Workspace() test_workspace.owner_id = admin_user.user_id cleanup_lib.safe_update(test_workspace) transaction.commit() with pytest.raises(NoResultFound): assert session.query(Workspace).one() == test_workspace
def test_safe_delete__ok__dry_run(self, session, app_config, admin_user) -> None: assert session.query(Workspace).all() == [] cleanup_lib = CleanupLib(app_config=app_config, session=session, dry_run_mode=True) test_workspace = Workspace() test_workspace.owner_id = admin_user.user_id session.add(test_workspace) transaction.commit() cleanup_lib.safe_delete(test_workspace) transaction.commit() assert session.query(Workspace).one() == test_workspace
def test_unit__create_content__ok__nominal_case(self, admin_user, session, content_type_list): assert session.query(Workspace).filter( Workspace.label == "TEST_WORKSPACE_1").count() == 0 workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() assert session.query(Workspace).filter( Workspace.label == "TEST_WORKSPACE_1").count() == 1 assert (session.query(ContentRevisionRO).filter( ContentRevisionRO.label == "TEST_CONTENT_1").count() == 0) content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(content) session.flush() assert (session.query(ContentRevisionRO).filter( ContentRevisionRO.label == "TEST_CONTENT_1").count() == 1) searched_content = (session.query(ContentRevisionRO).filter( ContentRevisionRO.label == "TEST_CONTENT_1").one()) assert searched_content.label == content.label
def test_unit__content_depot_file__ok__nominal_case( self, admin_user, session, content_type_list): """ Depot file access thought content property methods. """ workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(content) session.flush() # tests uninitialized depot file assert content.depot_file is None # initializes depot file # which is able to behave like a python file object content.depot_file = b"test" # tests initialized depot file assert content.depot_file # tests type of initialized depot file assert type(content.depot_file) == UploadedFile # tests content of initialized depot file # using depot_file.file of type StoredFile to fetch content back assert content.depot_file.file.read() == b"test"
def test_unit__delete_revision__ok__with_unsafe_context( self, admin_user, session, content_type_list): with unprotected_content_revision(session) as unsafe_session: workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) unsafe_session.add(workspace) unsafe_session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) unsafe_session.add(content) unsafe_session.flush() with new_revision(session=unsafe_session, tm=transaction.manager, content=content): content.description = "TEST_CONTENT_DESCRIPTION_1_UPDATED" unsafe_session.add(content) unsafe_session.flush() unsafe_session.delete(content.revisions[0]) unsafe_session.flush()
def test_unit__delete_revision__err__nominal_case(self, admin_user, session, content_type_list): # file creation workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(content) session.flush() with new_revision(session=session, tm=transaction.manager, content=content): content.description = "TEST_CONTENT_DESCRIPTION_1_UPDATED" session.add(content) session.flush() session.delete(content.revisions[0]) # Raise ContentRevisionDeleteError because revision can't be deleted with pytest.raises(ContentRevisionDeleteError): session.flush()
def undelete(self, workspace: Workspace, flush=True): workspace.is_deleted = False if flush: self._session.flush() return workspace
def test__unit__CandidateWorkspaceRoleChecker__ok__nominal_case( self, session): current_user = User(user_id=2, email="*****@*****.**") current_user.profile = Profile.TRUSTED_USER candidate_workspace = Workspace(workspace_id=3, owner=current_user) role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=2) session.add(current_user) session.add(candidate_workspace) session.add(role) session.flush() transaction.commit() class FakeBaseFakeTracimContext(BaseFakeTracimContext): @property def current_user(self): return current_user @property def candidate_workspace(self): return candidate_workspace assert CandidateWorkspaceRoleChecker(1).check( FakeBaseFakeTracimContext()) assert CandidateWorkspaceRoleChecker(2).check( FakeBaseFakeTracimContext())
def test_unit_get_children(self): user_admin = self._get_user() workspace = Workspace(label="TEST_WORKSPACE_1") parent = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.Folder.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, ) self.session.flush() assert parent.children == [] children = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.Folder.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, parent=parent, ) self.session.flush() assert [type(child) == Content for child in parent.children] assert [child.revision_id for child in parent.children] == [children.revision_id] with new_revision(session=self.session, tm=transaction.manager, content=children): children.parent = None self.session.flush() assert parent.children == []
def test_unit__crud_caller__ok__user_role_in_workspace(self, session): hook = UserRoleInWorkspaceHookImpl() session.context.plugin_manager.register(hook) owner = User(email="john") workspace = Workspace(label="Hello", owner=owner) session.add(workspace) session.flush() role = UserRoleInWorkspace(role=UserRoleInWorkspace.READER, user=owner, workspace=workspace) session.add(role) session.flush() hook.mock_hooks.assert_called_with("created", role=role, context=session.context) role.role = UserRoleInWorkspace.WORKSPACE_MANAGER session.add(role) session.flush() hook.mock_hooks.assert_called_with("modified", role=role, context=session.context) session.delete(role) session.flush() hook.mock_hooks.assert_called_with("deleted", role=role, context=session.context)
def test__unit__CandidateWorkspaceRoleChecker__err_no_role_in_workspace( self): current_user = User(user_id=2, email='*****@*****.**') current_user.groups.append( Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME)) candidate_workspace = Workspace(workspace_id=3) self.session.add(current_user) self.session.add(candidate_workspace) self.session.flush() transaction.commit() class FakeTracimContext(TracimContext): @property def current_user(self): return current_user @property def candidate_workspace(self): return candidate_workspace assert CandidateWorkspaceRoleChecker(0).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(1).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(2).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(3).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(4).check(FakeTracimContext())
def test__unit__CandidateWorkspaceRoleChecker__err_no_role_in_workspace( self, session): current_user = User(user_id=2, email="*****@*****.**") current_user.profile = Profile.TRUSTED_USER candidate_workspace = Workspace(workspace_id=3, owner=current_user) session.add(current_user) session.add(candidate_workspace) session.flush() transaction.commit() class FakeBaseFakeTracimContext(BaseFakeTracimContext): @property def current_user(self): return current_user @property def candidate_workspace(self): return candidate_workspace assert CandidateWorkspaceRoleChecker(0).check( FakeBaseFakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(1).check(FakeBaseFakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(2).check(FakeBaseFakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(3).check(FakeBaseFakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): CandidateWorkspaceRoleChecker(4).check(FakeBaseFakeTracimContext())
def test__unit__RoleChecker__err_role_insufficient(self): current_user = User(user_id=2, email="*****@*****.**") current_user.groups.append( Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME)) current_workspace = Workspace(workspace_id=3) role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=2) self.session.add(current_user) self.session.add(current_workspace) self.session.add(role) self.session.flush() transaction.commit() class FakeTracimContext(TracimContext): @property def current_user(self): return current_user @property def current_workspace(self): return current_workspace assert RoleChecker(2).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): RoleChecker(3).check(FakeTracimContext()) with pytest.raises(InsufficientUserRoleInWorkspace): RoleChecker(4).check(FakeTracimContext())
def create_workspace( self, label: str='', description: str='', calendar_enabled: bool=False, save_now: bool=False, ) -> Workspace: if not label: raise EmptyLabelNotAllowed('Workspace label cannot be empty') if self._session.query(Workspace).filter(Workspace.label == label).count() > 0: # nopep8 raise WorkspaceLabelAlreadyUsed( 'A workspace with label {} already exist.'.format(label) ) workspace = Workspace() workspace.label = label workspace.description = description workspace.calendar_enabled = calendar_enabled # By default, we force the current user to be the workspace manager # And to receive email notifications role_api = RoleApi( session=self._session, current_user=self._user, config=self._config ) role = role_api.create_one( self._user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, with_notif=True, ) self._session.add(workspace) self._session.add(role) if save_now: self._session.flush() # TODO - G.M - 28-03-2018 - [Calendar] Reenable calendar stuff # if calendar_enabled: # self._ensure_calendar_exist(workspace) # else: # self._disable_calendar(workspace) return workspace
def test_creates(self): eq_( 0, self.session.query(ContentRevisionRO).filter( ContentRevisionRO.label == 'TEST_CONTENT_1').count()) eq_( 0, self.session.query(Workspace).filter( Workspace.label == 'TEST_WORKSPACE_1').count()) user_admin = self.session.query(User).filter( User.email == '*****@*****.**').one() workspace = Workspace(label="TEST_WORKSPACE_1") self.session.add(workspace) self.session.flush() eq_( 1, self.session.query(Workspace).filter( Workspace.label == 'TEST_WORKSPACE_1').count()) first_content = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.Page.slug, label='TEST_CONTENT_1', description='TEST_CONTENT_DESCRIPTION_1', revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) eq_( 1, self.session.query(ContentRevisionRO).filter( ContentRevisionRO.label == 'TEST_CONTENT_1').count()) content = self.session.query(Content).filter( Content.id == first_content.id).one() eq_('TEST_CONTENT_1', content.label) eq_('TEST_CONTENT_DESCRIPTION_1', content.description) # Create a second content second_content = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.Page.slug, label='TEST_CONTENT_2', description='TEST_CONTENT_DESCRIPTION_2', revision_type=ActionDescription.CREATION) eq_( 1, self.session.query(ContentRevisionRO).filter( ContentRevisionRO.label == 'TEST_CONTENT_2').count()) content = self.session.query(Content).filter( Content.id == second_content.id).one() eq_('TEST_CONTENT_2', content.label) eq_('TEST_CONTENT_DESCRIPTION_2', content.description)
def create_workspace( self, label: str = '', description: str = '', calendar_enabled: bool = False, save_now: bool = False, ) -> Workspace: if not label: raise EmptyLabelNotAllowed('Workspace label cannot be empty') if self._session.query(Workspace).filter( Workspace.label == label).count() > 0: # nopep8 raise WorkspaceLabelAlreadyUsed( 'A workspace with label {} already exist.'.format(label)) workspace = Workspace() workspace.label = label workspace.description = description workspace.calendar_enabled = calendar_enabled # By default, we force the current user to be the workspace manager # And to receive email notifications role_api = RoleApi(session=self._session, current_user=self._user, config=self._config) role = role_api.create_one( self._user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, with_notif=True, ) self._session.add(workspace) self._session.add(role) if save_now: self._session.flush() # TODO - G.M - 28-03-2018 - [Calendar] Reenable calendar stuff # if calendar_enabled: # self._ensure_calendar_exist(workspace) # else: # self._disable_calendar(workspace) return workspace
def _create_content_from_nothing(self): user_admin = self._get_user() workspace = Workspace(label="TEST_WORKSPACE_1") content = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.File.slug, label='TEST_CONTENT_1', description='TEST_CONTENT_DESCRIPTION_1', revision_type=ActionDescription.CREATION, ) return content
def update_workspace( self, workspace: Workspace, label: str, description: str, save_now: bool=False, ) -> Workspace: """ Update workspace :param workspace: workspace to update :param label: new label of workspace :param description: new description :param save_now: database flush :return: updated workspace """ if not label: raise EmptyLabelNotAllowed('Workspace label cannot be empty') workspace.label = label workspace.description = description if save_now: self.save(workspace) return workspace
def create_workspace( self, label: str = "", description: str = "", agenda_enabled: bool = True, save_now: bool = False, ) -> Workspace: if not label: raise EmptyLabelNotAllowed("Workspace label cannot be empty") if self._session.query(Workspace).filter( Workspace.label == label).count() > 0: raise WorkspaceLabelAlreadyUsed( "A workspace with label {} already exist.".format(label)) workspace = Workspace() workspace.label = label workspace.description = description workspace.agenda_enabled = agenda_enabled # By default, we force the current user to be the workspace manager # And to receive email notifications role_api = RoleApi(session=self._session, current_user=self._user, config=self._config) role = role_api.create_one(self._user, workspace, UserRoleInWorkspace.WORKSPACE_MANAGER, with_notif=True) self._session.add(workspace) self._session.add(role) if save_now: self._session.flush() return workspace
def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_role_in_workspace( self): current_user = User(user_id=2, email="*****@*****.**") current_user.groups.append( Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME)) current_workspace = Workspace(workspace_id=3) candidate_content_type = ContentType( slug="test", fa_icon="", hexcolor="", label="Test", creation_label="Test", available_statuses=[], minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER, ) role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=WorkspaceRoles.CONTRIBUTOR.level) self.session.add(current_user) self.session.add(current_workspace) self.session.add(role) self.session.flush() transaction.commit() class FakeContentTypeList(object): def get_one_by_slug(self, slug=str) -> ContentType: return candidate_content_type class FakeTracimContext(TracimContext): @property def current_user(self): return current_user @property def current_workspace(self): return current_workspace @property def candidate_content_type(self): return candidate_content_type with pytest.raises(InsufficientUserRoleInWorkspace): assert ContentTypeCreationChecker(FakeContentTypeList()).check( FakeTracimContext())
def test_create(self, key="1"): eq_( 0, self.session.query(ContentRevisionRO).filter( ContentRevisionRO.label == "TEST_CONTENT_%s" % key).count(), ) eq_( 0, self.session.query(Workspace).filter( Workspace.label == "TEST_WORKSPACE_%s" % key).count(), ) user_admin = self.session.query(User).filter( User.email == "*****@*****.**").one() workspace = Workspace(label="TEST_WORKSPACE_%s" % key) self.session.add(workspace) self.session.flush() eq_( 1, self.session.query(Workspace).filter( Workspace.label == "TEST_WORKSPACE_%s" % key).count(), ) created_content = self._create_content( owner=user_admin, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_%s" % key, description="TEST_CONTENT_DESCRIPTION_%s" % key, revision_type=ActionDescription.CREATION, ) eq_( 1, self.session.query(ContentRevisionRO).filter( ContentRevisionRO.label == "TEST_CONTENT_%s" % key).count(), ) content = self.session.query(Content).filter( Content.id == created_content.id).one() eq_("TEST_CONTENT_%s" % key, content.label) eq_("TEST_CONTENT_DESCRIPTION_%s" % key, content.description) return created_content
def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_role_in_workspace( self, session): current_user = User(user_id=2, email="*****@*****.**") current_user.profile = Profile.TRUSTED_USER current_workspace = Workspace(workspace_id=3, owner=current_user) candidate_content_type = TracimContentType( slug="test", fa_icon="", label="Test", creation_label="Test", available_statuses=[], minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER, ) role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=WorkspaceRoles.CONTRIBUTOR.level) session.add(current_user) session.add(current_workspace) session.add(role) session.flush() transaction.commit() class FakeContentTypeList(object): def get_one_by_slug(self, slug=str) -> TracimContentType: return candidate_content_type class FakeBaseFakeTracimContext(BaseFakeTracimContext): @property def current_user(self): return current_user @property def current_workspace(self): return current_workspace @property def candidate_content_type(self): return candidate_content_type with pytest.raises(InsufficientUserRoleInWorkspace): assert ContentTypeCreationChecker(FakeContentTypeList()).check( FakeBaseFakeTracimContext())
def test_unit__crud_caller__ok__content(self, session): hook = ContentHookImpl() session.context.plugin_manager.register(hook) owner = User(email="john") session.add(owner) workspace = Workspace(label="Hello", owner=owner) session.add(workspace) session.flush() content = Content( label="Foo", owner=owner, workspace=workspace, revision_type=ActionDescription.CREATION, type="html-document", ) session.add(content) session.flush() hook.mock_hooks.assert_called_with("created", content=content, context=session.context) with new_revision( session=session, tm=transaction.manager, content=content, ): content.label = "Bar" session.add(content) session.flush() hook.mock_hooks.assert_called_with("modified", content=content, context=session.context) # TODO SGD 2020/05/06: add this test when deleting a Content is possible session.delete(content) session.flush() hook.mock_hooks.assert_called_with("deleted", content=content, context=session.context)
def test_unit__get_children__ok__nominal_case(sel, admin_user, session, content_type_list): workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() parent_folder = Content( owner=admin_user, workspace=workspace, type=content_type_list.Folder.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(parent_folder) session.flush() assert parent_folder.children.all() == [] children_folder = Content( owner=admin_user, workspace=workspace, type=content_type_list.Folder.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, parent=parent_folder, ) session.add(children_folder) session.flush() assert [type(child) == Content for child in parent_folder.children] assert [child.revision_id for child in parent_folder.children ] == [children_folder.cached_revision_id] with new_revision(session=session, tm=transaction.manager, content=children_folder): children_folder.parent = None session.flush() assert parent_folder.children.all() == []
def test_unit__get_allowed_content_type__ok(self, admin_user, session, content_type_list) -> None: workspace = Workspace(label="TEST_WORKSPACE", owner=admin_user) session.add(workspace) session.flush() content1 = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) content1.properties = {"allowed_content": {"unknown_type": True}} try: assert content1.get_allowed_content_types() == [] except ValueError: pytest.fail( "Unknown content type should not raise exception anymore " "when getting allowed content_type")
def test__unit__ContentTypeCreationChecker__ok__explicit(self): current_user = User(user_id=2, email='*****@*****.**') current_user.groups.append( Group(group_id=2, group_name=Group.TIM_MANAGER_GROUPNAME)) current_workspace = Workspace(workspace_id=3) candidate_content_type = ContentType( slug='test', fa_icon='', hexcolor='', label='Test', creation_label='Test', available_statuses=[], minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER) role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=WorkspaceRoles.CONTENT_MANAGER.level) self.session.add(current_user) self.session.add(current_workspace) self.session.add(role) self.session.flush() transaction.commit() class FakeContentTypeList(object): def get_one_by_slug(self, slug=str) -> ContentType: return candidate_content_type class FakeTracimContext(TracimContext): @property def current_user(self): return current_user @property def current_workspace(self): return current_workspace assert ContentTypeCreationChecker(FakeContentTypeList(), content_type_slug='test').check( FakeTracimContext())
def test_unit__update__err__without_prepare(self, admin_user, session, content_type_list): # file creation workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user) session.add(workspace) session.flush() content = Content( owner=admin_user, workspace=workspace, type=content_type_list.Page.slug, label="TEST_CONTENT_1", description="TEST_CONTENT_DESCRIPTION_1", revision_type=ActionDescription.CREATION, is_deleted=False, is_archived=False, ) session.add(content) session.flush() # file update with pytest.raises(ContentRevisionUpdateError): content.description = "FOO"
def delete(self, workspace: Workspace, flush=True): workspace.is_deleted = True if flush: self._session.flush()