Exemplo n.º 1
0
    def testContainerVersioning(self):
        from OFS.DTMLDocument import addDTMLDocument
        # Verify that containers and items are versioned independently.
        repository = self.repository
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        folder1.testattr = 'container_v1'
        folder2.testattr = 'item_v1'

        self.assert_(not repository.isUnderVersionControl(folder1))
        repository.applyVersionControl(folder1)
        folder1 = self.app.folder1
        self.assert_(repository.isUnderVersionControl(folder1))
        self.assert_(not repository.isUnderVersionControl(folder2))
        repository.applyVersionControl(folder2)
        folder2 = folder1.folder2
        self.assert_(repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder2.document1))

        # Make the first version of folder1 and check it in.
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        info = repository.getVersionInfo(folder1)
        first_version = info.version_id

        # Change folder1 and check it in again
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        folder1.testattr = 'container_v2'
        addDTMLDocument(folder1, 'document3', file='some more text')
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2

        # Change folder2
        repository.checkoutResource(folder2)
        folder2 = folder1.folder2
        folder2.testattr = 'item_v2'

        # Now revert folder1 and verify that folder2 was not reverted.
        repository.updateResource(folder1, first_version)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        self.assertEqual(folder1.testattr, 'container_v1')
        self.assertEqual(folder2.testattr, 'item_v2')

        # Verify that document3 remains an item of the reverted folder1.
        self.assert_(hasattr(folder1, 'document3'))
        self.assert_(str(folder1.document3) == 'some more text')

        # Remove document3 and verify that it doesn't reappear upon revert.
        folder1._delObject('document3')
        repository.updateResource(folder1, '')
        folder1 = self.app.folder1
        self.assertEqual(folder1.testattr, 'container_v2')
        self.assertEqual(folder1.folder2.testattr, 'item_v2')
        self.assert_(not hasattr(folder1, 'document3'))
Exemplo n.º 2
0
    def testContainerVersioning(self):
        from OFS.DTMLDocument import addDTMLDocument
        # Verify that containers and items are versioned independently.
        repository = self.repository
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        folder1.testattr = 'container_v1'
        folder2.testattr = 'item_v1'

        self.assert_(not repository.isUnderVersionControl(folder1))
        repository.applyVersionControl(folder1)
        folder1 = self.app.folder1
        self.assert_(repository.isUnderVersionControl(folder1))
        self.assert_(not repository.isUnderVersionControl(folder2))
        repository.applyVersionControl(folder2)
        folder2 = folder1.folder2
        self.assert_(repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder2.document1))

        # Make the first version of folder1 and check it in.
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        info = repository.getVersionInfo(folder1)
        first_version = info.version_id

        # Change folder1 and check it in again
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        folder1.testattr = 'container_v2'
        addDTMLDocument(folder1, 'document3', file='some more text')
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2

        # Change folder2
        repository.checkoutResource(folder2)
        folder2 = folder1.folder2
        folder2.testattr = 'item_v2'

        # Now revert folder1 and verify that folder2 was not reverted.
        repository.updateResource(folder1, first_version)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        self.assertEqual(folder1.testattr, 'container_v1')
        self.assertEqual(folder2.testattr, 'item_v2')

        # Verify that document3 remains an item of the reverted folder1.
        self.assert_(hasattr(folder1, 'document3'))
        self.assert_(str(folder1.document3) == 'some more text')

        # Remove document3 and verify that it doesn't reappear upon revert.
        folder1._delObject('document3')
        repository.updateResource(folder1, '')
        folder1 = self.app.folder1
        self.assertEqual(folder1.testattr, 'container_v2')
        self.assertEqual(folder1.folder2.testattr, 'item_v2')
        self.assert_(not hasattr(folder1, 'document3'))
Exemplo n.º 3
0
    def testIndexing(self):
        extra = {
            'lexicon': DEFAULT_LEXICON,
            'storage': DEFAULT_STORAGE,
            'splitter': DEFAULT_SPLITTER
        }
        self.folder.catalog.manage_addIndex('PrincipiaSearchSource',
                                            'TextIndexNG3', extra)

        from zopyx.txng3.core import tests
        datadir = os.path.join(os.path.dirname(tests.__file__), 'data',
                               'texts')
        for f in os.listdir(datadir):
            fname = os.path.join(datadir, f)
            if not os.path.isfile(fname): continue
            fp = open(fname)
            addDTMLDocument(self.folder, id=f, title=f, file=fp)
            fp.close()

        for obj in [
                o for o in self.folder.objectValues('DTML Document')
                if o.getId().endswith('txt')
        ]:
            self.folder.catalog.catalog_object(obj, obj.absolute_url(1))
        self.assertEqual(len(self.folder.catalog), 199)
Exemplo n.º 4
0
 def test_defaults_no_standard_html_header(self):
     # see LP #496961
     from OFS.DTMLDocument import addDTMLDocument
     from OFS.DTMLDocument import DTMLDocument
     dispatcher = DummyDispatcher()
     addDTMLDocument(dispatcher, 'id')
     method = dispatcher._set['id']
     self.assertTrue(isinstance(method, DTMLDocument))
     self.assertFalse('standard_html_header' in method.read())
     self.assertFalse('standard_html_footer' in method.read())
 def test_defaults_no_standard_html_header(self):
     # see LP #496961
     from OFS.DTMLDocument import addDTMLDocument
     from OFS.DTMLDocument import DTMLDocument
     dispatcher = DummyDispatcher()
     addDTMLDocument(dispatcher, 'id')
     method = dispatcher._set['id']
     self.assertTrue(isinstance(method, DTMLDocument))
     self.assertFalse('standard_html_header' in method.read())
     self.assertFalse('standard_html_footer' in method.read())
Exemplo n.º 6
0
    def _prepareTexts(self):
        """ import texts from 'texts' folder as DTML Document """

        from OFS.DTMLDocument import addDTMLDocument

        dirname = os.path.join(os.path.dirname(__file__), 'texts')
        files = os.listdir(dirname)
        self.num_files = 0
        for f in files:
            fname = os.path.join(dirname, f)
            if not os.path.isfile(fname): continue
            fp = open(fname) 
            addDTMLDocument(self.folder, id=f, title=f, file=fp)
            fp.close()
            self.num_files+=1
    def testIndexing(self):
        extra = {"lexicon": DEFAULT_LEXICON, "storage": DEFAULT_STORAGE, "splitter": DEFAULT_SPLITTER}
        self.folder.catalog.manage_addIndex("PrincipiaSearchSource", "TextIndexNG3", extra)

        from zopyx.txng3.core import tests

        datadir = os.path.join(os.path.dirname(tests.__file__), "data", "texts")
        for f in os.listdir(datadir):
            fname = os.path.join(datadir, f)
            if not os.path.isfile(fname):
                continue
            fp = open(fname)
            addDTMLDocument(self.folder, id=f, title=f, file=fp)
            fp.close()

        for obj in [o for o in self.folder.objectValues("DTML Document") if o.getId().endswith("txt")]:
            self.folder.catalog.catalog_object(obj, obj.absolute_url(1))
        self.assertEqual(len(self.folder.catalog), 199)
Exemplo n.º 8
0
    def testSearching(self):

        def extractIds(lst):
            r = [o.getObject().getId() for o in lst]
            r.sort()
            return r

        from OFS.DTMLDocument import addDTMLDocument
        from cStringIO import StringIO
        addDTMLDocument(self.folder, id='1.txt', file=StringIO('The quick brown fox jumps over the lazy dog'))
        addDTMLDocument(self.folder, id='2.txt', file=StringIO('dog lazy brown fox leap jumps over dog dog lazy quick'))
        self._indexTexts()
        result = self.catalog.searchResults(PrincipiaSearchSource={'query' : 'quick'})
        self.assertEqual(extractIds(result), ['1.txt', '2.txt'])
        result = self.catalog.searchResults(PrincipiaSearchSource={'query' : 'quick and leap'})
        self.assertEqual(extractIds(result), ['2.txt'])
        result = self.catalog.searchResults(PrincipiaSearchSource={'query' : 'quick or leap'})
        self.assertEqual(extractIds(result), ['1.txt', '2.txt'])
        result = self.catalog.searchResults(PrincipiaSearchSource={'query' : '"The quick brown fox jumps over the lazy lazy"'})
        self.assertEqual(extractIds(result), ['1.txt'])
Exemplo n.º 9
0
    def testContainerVersioning(self):
        # Verify that containers and items are versioned independently,
        # except in the case of references.
        from OFS.DTMLDocument import addDTMLDocument

        repository = self.repository
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        folder1.testattr = 'container_v1'
        folder2.testattr = 'item_v1'
        folder1._setOb("ref", PathReference("ref", folder1.folder2))
        folder2._true_id = "folder2"
        self.assertEqual(folder1.ref._true_id, "folder2")

        self.assert_(not repository.isUnderVersionControl(folder1))
        repository.applyVersionControl(folder1)
        folder1 = self.app.folder1
        self.assert_(repository.isUnderVersionControl(folder1))
        self.assert_(not repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder1.ref))
        repository.applyVersionControl(folder2)
        folder2 = folder1.folder2
        self.assert_(repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder2.document1))

        # Make the first version of folder1 and check it in.
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        info = repository.getVersionInfo(folder1)
        first_version = info.version_id

        # Change folder1 and check it in again
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        folder1.testattr = 'container_v2'
        addDTMLDocument(folder1, 'document3', file='some more text')
        folder1.document3._true_id = "document3"
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2

        # Change ref to point to document3.
        folder1._delObject("ref")
        folder1._setOb("ref", PathReference("ref", folder1.document3))
        self.assertEqual(folder1.ref._true_id, "document3")

        # Change folder2
        repository.checkoutResource(folder2)
        folder2 = folder1.folder2
        folder2.testattr = 'item_v2'

        # Now revert folder1 and verify that folder2 was not reverted.
        # Also verify that ref now points back to folder2.
        repository.updateResource(folder1, first_version)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        self.assertEqual(folder1.testattr, 'container_v1')
        self.assertEqual(folder2.testattr, 'item_v2')
        self.assertEqual(folder1.ref._true_id, "folder2")

        # Verify that document3 remains an item of the reverted folder1.
        self.assert_(hasattr(folder1, 'document3'))
        self.assert_(str(folder1.document3) == 'some more text')

        # Remove document3 and verify that it doesn't reappear upon revert.
        folder1._delObject('document3')
        repository.updateResource(folder1, '')
        folder1 = self.app.folder1
        self.assertEqual(folder1.testattr, 'container_v2')
        self.assertEqual(folder1.folder2.testattr, 'item_v2')
        self.assert_(not hasattr(folder1, 'document3'))
Exemplo n.º 10
0
    def testContainerVersioning(self):
        # Verify that containers and items are versioned independently,
        # except in the case of references.
        from OFS.DTMLDocument import addDTMLDocument

        repository = self.repository
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        folder1.testattr = 'container_v1'
        folder2.testattr = 'item_v1'
        folder1._setOb("ref", PathReference("ref", folder1.folder2))
        folder2._true_id = "folder2"
        self.assertEqual(folder1.ref._true_id, "folder2")

        self.assert_(not repository.isUnderVersionControl(folder1))
        repository.applyVersionControl(folder1)
        folder1 = self.app.folder1
        self.assert_(repository.isUnderVersionControl(folder1))
        self.assert_(not repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder1.ref))
        repository.applyVersionControl(folder2)
        folder2 = folder1.folder2
        self.assert_(repository.isUnderVersionControl(folder2))
        self.assert_(not repository.isUnderVersionControl(folder2.document1))

        # Make the first version of folder1 and check it in.
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        info = repository.getVersionInfo(folder1)
        first_version = info.version_id

        # Change folder1 and check it in again
        repository.checkoutResource(folder1)
        folder1 = self.app.folder1
        folder1.testattr = 'container_v2'
        addDTMLDocument(folder1, 'document3', file='some more text')
        folder1.document3._true_id = "document3"
        repository.checkinResource(folder1)
        folder1 = self.app.folder1
        folder2 = folder1.folder2

        # Change ref to point to document3.
        folder1._delObject("ref")
        folder1._setOb("ref", PathReference("ref", folder1.document3))
        self.assertEqual(folder1.ref._true_id, "document3")

        # Change folder2
        repository.checkoutResource(folder2)
        folder2 = folder1.folder2
        folder2.testattr = 'item_v2'

        # Now revert folder1 and verify that folder2 was not reverted.
        # Also verify that ref now points back to folder2.
        repository.updateResource(folder1, first_version)
        folder1 = self.app.folder1
        folder2 = folder1.folder2
        self.assertEqual(folder1.testattr, 'container_v1')
        self.assertEqual(folder2.testattr, 'item_v2')
        self.assertEqual(folder1.ref._true_id, "folder2")

        # Verify that document3 remains an item of the reverted folder1.
        self.assert_(hasattr(folder1, 'document3'))
        self.assert_(str(folder1.document3) == 'some more text')

        # Remove document3 and verify that it doesn't reappear upon revert.
        folder1._delObject('document3')
        repository.updateResource(folder1, '')
        folder1 = self.app.folder1
        self.assertEqual(folder1.testattr, 'container_v2')
        self.assertEqual(folder1.folder2.testattr, 'item_v2')
        self.assert_(not hasattr(folder1, 'document3'))