Beispiel #1
0
    def test_children(self, admin_user, session, app_config,
                      content_api_factory, content_type_list):
        workspace = WorkspaceApi(current_user=admin_user,
                                 session=session,
                                 config=app_config).create_workspace(
                                     "workspace_1", save_now=True)
        folder = Content(type=content_type_list.Folder.slug, owner=admin_user)
        folder.label = "folder_1"
        folder.workspace = workspace
        session.add(folder)
        session.flush()

        thread = Content(type=content_type_list.Thread.slug,
                         owner=admin_user,
                         parent=folder)
        thread.label = "thread_1"
        thread.workspace = workspace
        session.add(folder)
        session.flush()
        workspace = session.query(Workspace).filter(
            Workspace.label == "workspace_1").one()
        content_api = content_api_factory.get()
        folder = content_api.get_canonical_query().filter(
            Content.label == "folder_1").one()
        assert [folder] == list(workspace.get_valid_children())
Beispiel #2
0
    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)
Beispiel #3
0
    def _create_content_and_test(self, name, workspace, *args,
                                 **kwargs) -> Content:
        """
        All extra parameters (*args, **kwargs) are for Content init
        :return: Created Content instance
        """
        content = Content(*args, **kwargs)
        content.label = name
        content.workspace = workspace
        self.session.add(content)
        self.session.flush()

        content_api = ContentApi(current_user=None,
                                 session=self.session,
                                 config=self.app_config)
        eq_(
            1,
            content_api.get_canonical_query().filter(
                Content.label == name).count())
        return content_api.get_canonical_query().filter(
            Content.label == name).one()