def test_approved_transaction(self):
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).approve(DateTime() + 60)

        self.assertItemsEqual(self.search('/root/document'),
                              [('/root/document', 'approved'),
                               ('/root/document/0', 'approved')])
    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('editor')

        with CatalogTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addMockupVersionedContent('document', 'Document')
    def setUp(self):
        self.root = self.layer.get_application()
        self.layer.login('editor')

        with CatalogTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addFolder('folder', 'Data Folder')
    def test_deletion_transaction(self):
        """A removed folder is no longer cataloged within a transaction.
        """
        with CatalogTransaction():
            self.root.manage_delObjects(['folder'])

        self.assertItemsEqual(
            self.search(path='/root'),
            [('/root', 'unapproved')])
    def test_deletion_transaction(self):
        """A file is unindex when it is removed.
        """
        with CatalogTransaction():
            self.root.manage_delObjects(['universe'])

        self.assertItemsEqual(self.search(path='/root'),
                              [('/root', 'unapproved')])
        self.assertItemsEqual(self.search(fulltext='dark energy'), [])
    def test_copy_transaction(self):
        """A copy of a file is indexed.
        """
        with CatalogTransaction():
            token = self.root.manage_copyObjects(['universe'])
            self.root.manage_pasteObjects(token)

        self.assertItemsEqual(self.search(fulltext='dark energy'),
                              [('/root/universe', 'public'),
                               ('/root/copy_of_universe', 'public')])
    def test_deletion_transaction(self):
        """Test deleting a document.
        """
        with CatalogTransaction():
            with IContainerManager(self.root).deleter() as deleter:
                deleter(self.root.document)

        self.assertItemsEqual(self.search('/root'), [
            ('/root', 'unapproved'),
        ])
    def test_rename_transaction(self):
        """A renamed folder is reindexed within a transaction.
        """
        with CatalogTransaction():
            self.root.manage_renameObject('folder', 'renamed_folder')

        self.assertItemsEqual(
            self.search(path='/root'),
            [('/root', 'unapproved'),
             ('/root/renamed_folder', 'unapproved')])
    def test_rename_transaction(self):
        """A file is reindexed if it is renamed.
        """
        with CatalogTransaction():
            self.root.universe.set_title('All true in Zope')
            self.root.manage_renameObject('universe', 'renamed_universe')

        self.assertItemsEqual(self.search(fulltext='dark energy'),
                              [('/root/renamed_universe', 'public')])
        self.assertItemsEqual(self.search(fulltext='in zope'),
                              [('/root/renamed_universe', 'public')])
    def test_new_transaction(self):
        """If you create a new version of a published document within
        a transaction, it appears in the catalog.
        """
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).publish()
            IPublicationWorkflow(self.root.document).new_version()

        self.assertItemsEqual(self.search('/root/document'),
                              [('/root/document', 'public'),
                               ('/root/document/0', 'public'),
                               ('/root/document/1', 'unapproved')])
    def test_copy_transaction(self):
        """A copy of a folder is indexed within a transaction.
        """
        with CatalogTransaction():
            token = self.root.manage_copyObjects(['folder'])
            self.root.manage_pasteObjects(token)

        self.assertItemsEqual(
            self.search(path='/root'),
            [('/root', 'unapproved'),
             ('/root/folder', 'unapproved'),
             ('/root/copy_of_folder', 'unapproved')])
    def test_new_published_transaction(self):
        """If we published, make a new version and publish again the
        document, it should be published.
        """
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).publish()
            IPublicationWorkflow(self.root.document).new_version()
            IPublicationWorkflow(self.root.document).publish()

        self.assertItemsEqual(self.search('/root/document'),
                              [('/root/document', 'public'),
                               ('/root/document/1', 'public')])
    def test_add_deletion_transaction(self):
        """Add an remove a folder The catalog content should not change.
        """
        with CatalogTransaction():
            factory = self.root.folder.manage_addProduct['Silva']
            factory.manage_addAutoTOC('index', 'Index')
            self.root.folder.manage_delObjects(['index'])

        self.assertItemsEqual(
            self.search(path='/root'),
            [('/root', 'unapproved'),
             ('/root/folder', 'unapproved')])
    def test_closed_transaction(self):
        """If you close a document within a transaction, its version
        is no longer catalogued, and the document appears as
        unapproved.
        """
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).publish()
            IPublicationWorkflow(self.root.document).close()

        self.assertItemsEqual(self.search('/root'),
                              [('/root', 'unapproved'),
                               ('/root/document', 'unapproved')])
    def test_moving_transaction(self):
        """A moved filed is reindexed.
        """
        with CatalogTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addPublication('publication', 'Publication')
            token = self.root.manage_cutObjects(['universe'])

        self.root.publication.manage_pasteObjects(token)
        self.assertItemsEqual(self.search(path='/root'),
                              [('/root', 'unapproved'),
                               ('/root/publication', 'unapproved'),
                               ('/root/publication/universe', 'public')])
    def test_add_public_transaction(self):
        """A folder is public in the catalog if it is_published (have
        an index) within a transaction.
        """
        with CatalogTransaction():
            factory = self.root.folder.manage_addProduct['Silva']
            factory.manage_addAutoTOC('index', 'Index')

        self.assertItemsEqual(
            self.search(path='/root'),
            [('/root', 'unapproved'),
             ('/root/folder', 'public'),
             ('/root/folder/index', 'public')])
    def test_copy_transaction(self):
        """Copy a published document within a transaction. The copy
        should be catalogued and not published.
        """
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).publish()
            with IContainerManager(self.root).copier() as copier:
                copier(self.root.document)

        self.assertItemsEqual(self.search('/root'),
                              [('/root', 'public'),
                               ('/root/document', 'public'),
                               ('/root/document/0', 'public'),
                               ('/root/copy_of_document', 'unapproved')])
    def test_moving_transaction(self):
        """Test moving published elements into a folder within a transaction.
        """
        with CatalogTransaction():
            IPublicationWorkflow(self.root.document).publish()
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addFolder('folder', 'Folder')
            with IContainerManager(self.root.folder).mover() as mover:
                mover(self.root.document)

        self.assertItemsEqual(self.search('/root'),
                              [('/root', 'public'), ('/root/folder', 'public'),
                               ('/root/folder/document', 'public'),
                               ('/root/folder/document/0', 'public')])
    def test_remove_add_published_remove_transaction(self):
        """Test removing a content, adding a new one with the same,
        publishing it and remove it again.
        """
        with CatalogTransaction():
            with IContainerManager(self.root).deleter() as deleter:
                deleter(self.root.document)

            factory = self.root.manage_addProduct['Silva']
            factory.manage_addMockupVersionedContent('document', 'Fake')
            IPublicationWorkflow(self.root.document).publish()

            with IContainerManager(self.root).deleter() as deleter:
                deleter(self.root.document)

        self.assertItemsEqual(self.search('/root'), [('/root', 'unapproved')])
    def test_replaced_transaction(self):
        """A file is replaced. The new file should still be in the
        catalog.
        """
        with CatalogTransaction():
            self.root.manage_delObjects(['universe'])
            with self.layer.open_fixture('dark_energy.txt') as data:
                factory = self.root.manage_addProduct['Silva']
                factory.manage_addFile('universe', 'It is all about updates',
                                       data)

        self.assertItemsEqual(self.search(fulltext='dark energy'),
                              [('/root/universe', 'public')])
        self.assertItemsEqual(self.search(fulltext='updates'),
                              [('/root/universe', 'public')])
        self.assertItemsEqual(self.search(fulltext='silva'), [])
    def test_add_published_rename_transaction(self):
        """Test adding a new content, publishing it and moving it.
        """
        with CatalogTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addMockupVersionedContent('info', 'Content')
            IPublicationWorkflow(self.root.info).publish()
            with IContainerManager(self.root).renamer() as renamer:
                self.assertNotEqual(
                    renamer((self.root.info, 'renamed', 'Renamed content')),
                    None)

        self.assertItemsEqual(self.search('/root'),
                              [('/root', 'public'),
                               ('/root/renamed', 'public'),
                               ('/root/renamed/0', 'public'),
                               ('/root/document', 'unapproved'),
                               ('/root/document/0', 'unapproved')])
    def test_add_published_remove_rename_transaction(self):
        """Test removing a content, adding a new one with the same,
        publishing it and remove it again.
        """
        with CatalogTransaction():
            factory = self.root.manage_addProduct['Silva']
            factory.manage_addMockupVersionedContent('temp', 'Temp document')
            IPublicationWorkflow(self.root.temp).publish()

            with IContainerManager(self.root).deleter() as deleter:
                deleter(self.root.document)

            with IContainerManager(self.root).renamer() as renamer:
                self.assertNotEqual(
                    renamer((self.root.temp, 'document', 'Document')), None)

        self.assertItemsEqual(self.search('/root'),
                              [('/root', 'public'),
                               ('/root/document', 'public'),
                               ('/root/document/0', 'public')])