Exemplo n.º 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())
Exemplo n.º 2
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()