コード例 #1
0
 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()
コード例 #2
0
    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()
コード例 #3
0
    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"
コード例 #4
0
    def test_unit__update__ok__nominal_case(self, admin_user, session,
                                            content_type_list):
        workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user)
        session.add(workspace)
        session.flush()
        with freeze_time("1999-12-31 23:59:59"):
            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,
            )
            # TODO - G.M - 2019-07-05 - for unknown reason freeze-time doesn't work implicitly at
            # content creation, we do override date here to have correct behaviour.
            content.updated = content.created = datetime.utcnow()
            session.add(content)
            session.flush()
            transaction.commit()
        searched_content = session.query(Content).filter(
            Content.id == content.id).one()
        assert (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.label == "TEST_CONTENT_1").count() == 1)
        assert session.query(Content).filter(
            Content.id == searched_content.id).count() == 1
        with freeze_time("2000-01-01 00:00:05"):
            with new_revision(session=session,
                              tm=transaction.manager,
                              content=content):
                content.description = "TEST_CONTENT_DESCRIPTION_1_UPDATED"
            session.flush()
        assert (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.label == "TEST_CONTENT_1").count() == 2)
        assert session.query(Content).filter(
            Content.id == searched_content.id).count() == 1
        with freeze_time("2003-12-31 23:59:59"):
            with new_revision(session=session,
                              tm=transaction.manager,
                              content=content):
                content.description = "TEST_CONTENT_DESCRIPTION_1_UPDATED_2"
            session.flush()
        assert (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.label == "TEST_CONTENT_1").count() == 3)
        assert session.query(Content).filter(
            Content.id == searched_content.id).count() == 1

        revision_1 = (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.description ==
            "TEST_CONTENT_DESCRIPTION_1").one())
        revision_2 = (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.description ==
            "TEST_CONTENT_DESCRIPTION_1_UPDATED").one())
        revision_3 = (session.query(ContentRevisionRO).filter(
            ContentRevisionRO.description ==
            "TEST_CONTENT_DESCRIPTION_1_UPDATED_2").one())

        # Updated dates must be different
        assert revision_1.updated < revision_2.updated < revision_3.updated
        # Created dates must be equal
        assert revision_1.created == revision_2.created == revision_3.created
コード例 #5
0
    def test_unit__query_content__ok__nominal_case(self, admin_user, session,
                                                   content_type_list):
        workspace = Workspace(label="TEST_WORKSPACE_1", owner=admin_user)
        session.add(workspace)
        session.flush()
        workspace2 = Workspace(label="TEST_WORKSPACE_2", owner=admin_user)
        session.add(workspace2)
        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,
        )
        with new_revision(session=session,
                          tm=transaction.manager,
                          content=content1):
            content1.description = "TEST_CONTENT_DESCRIPTION_1_UPDATED"
            session.add(content1)
        session.flush()
        content2 = Content(
            owner=admin_user,
            workspace=workspace2,
            type=content_type_list.Page.slug,
            label="TEST_CONTENT_2",
            description="TEST_CONTENT_DESCRIPTION_2",
            revision_type=ActionDescription.CREATION,
            is_deleted=False,
            is_archived=False,
        )
        with new_revision(session=session,
                          tm=transaction.manager,
                          content=content2):
            content2.description = "TEST_CONTENT_DESCRIPTION_2_UPDATED"
            session.add(content2)
            session.flush()

        workspace1 = session.query(Workspace).filter(
            Workspace.label == "TEST_WORKSPACE_1").one()
        workspace2 = session.query(Workspace).filter(
            Workspace.label == "TEST_WORKSPACE_2").one()

        # To get Content in database
        # we have to join Content and ContentRevisionRO
        # with particular condition:
        # Join have to be on most recent revision
        join_sub_query = (session.query(ContentRevisionRO.revision_id).filter(
            ContentRevisionRO.content_id == Content.id).order_by(
                ContentRevisionRO.revision_id.desc()).limit(1).correlate(
                    Content))

        base_query = session.query(Content).join(
            ContentRevisionRO,
            and_(
                Content.id == ContentRevisionRO.content_id,
                ContentRevisionRO.revision_id == join_sub_query,
            ),
        )

        pattern = "TEST_CONTENT_DESCRIPTION_%_UPDATED"
        assert base_query.filter(
            Content.description.like(pattern)).count() == 2

        assert base_query.filter(Content.workspace == workspace1).count() == 1
        assert base_query.filter(Content.workspace == workspace2).count() == 1

        content1_from_query = base_query.filter(
            Content.workspace == workspace1).one()
        assert content1.id == content1_from_query.id
        assert "TEST_CONTENT_DESCRIPTION_1_UPDATED" == content1_from_query.description