예제 #1
0
class DirectoryFileManipulationBase(CASetup, ESetup, unittest.TestCase):
    def setUp(self):
        CASetup.setUp(self)
        ESetup.setUp(self)

        from Products.Reflecto.content.reflector import Reflector

        self.reflecto = Reflector('reflecto')
        self.indexview = MockIndexView()

        try:
            # Plone 3 needs a schema factory to be able to index things
            from Products.Archetypes.Schema.factory import instanceSchemaFactory
            provideAdapter(instanceSchemaFactory)
        except ImportError:
            pass

        # ease use of ITraversable by setting REQUEST to None
        self.reflecto.REQUEST = None
        # use the bog-standard traverser for views too
        provideAdapter(DefaultTraversable, (None,), name='view')
        # DefaultTraversable will look up the view as 'index'
        setattr(self.reflecto, 'index', self.indexview)

        self.tmppath = tempfile.mkdtemp()
        self.reflecto.setRelativePath(self.tmppath)

        os.mkdir(os.path.join(self.tmppath, 'subdir'))
        open(os.path.join(self.tmppath, 'foo'), 'w')
        open(os.path.join(self.tmppath, 'subdir', 'bar'), 'w')

    def tearDown(self):
        os.chmod(self.tmppath, stat.S_IRWXU)
        shutil.rmtree(self.tmppath)
        super(DirectoryFileManipulationBase, self).tearDown()
예제 #2
0
    def setUp(self):
        CASetup.setUp(self)
        ESetup.setUp(self)

        from Products.Reflecto.content.reflector import Reflector

        self.reflecto = Reflector('reflecto')
        self.indexview = MockIndexView()

        try:
            # Plone 3 needs a schema factory to be able to index things
            from Products.Archetypes.Schema.factory import instanceSchemaFactory
            provideAdapter(instanceSchemaFactory)
        except ImportError:
            pass

        # ease use of ITraversable by setting REQUEST to None
        self.reflecto.REQUEST = None
        # use the bog-standard traverser for views too
        provideAdapter(DefaultTraversable, (None, ), name='view')
        # DefaultTraversable will look up the view as 'index'
        setattr(self.reflecto, 'index', self.indexview)

        self.tmppath = tempfile.mkdtemp()
        self.reflecto.setRelativePath(self.tmppath)

        os.mkdir(os.path.join(self.tmppath, 'subdir'))
        open(os.path.join(self.tmppath, 'foo'), 'w')
        open(os.path.join(self.tmppath, 'subdir', 'bar'), 'w')
예제 #3
0
class IndexViewTests(unittest.TestCase):
    def setUp(self):
        self.reflector = Reflector("reflector")
        self.reflector.setRelativePath(samplesPath)
        self.reflector.portal_catalog = MockCatalog()

    def createView(self, context=None):
        if context is None:
            context = self.reflector
        view = IndexView(context, TestRequest())
        return view

    def testViewBasics(self):
        view = self.createView()
        self.failUnless(IIndexView.providedBy(view))
        self.failUnless(verifyObject(IIndexView, view))

    def testFileIndex(self):
        file = self.reflector["reflecto.txt"]
        view = self.createView(file)
        view.index()
        results = ["/".join(x.getPathToReflectoParent()) for x in self.reflector.portal_catalog.indexed]
        self.assertEqual(results, ["reflecto.txt"])

    def testSubdirIndex(self):
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        view.index()
        results = ["/".join(x.getPathToReflectoParent()) for x in self.reflector.portal_catalog.indexed]
        self.assertEqual(set(results), set(["subdir", "subdir/emptyfile.txt"]))

    def testNoSubdirIndexInLifeMode(self):
        self.reflector.setLife(True)
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        view.index()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])

    def testFileUnindex(self):
        file = self.reflector["reflecto.txt"]
        view = self.createView(file)
        self.reflector.portal_catalog.results = [MockBrain("reflecto.txt")]
        view.unindex()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])
        self.assertEqual(self.reflector.portal_catalog.searches, [{"path": "reflector/reflecto.txt"}])
        self.assertEqual(self.reflector.portal_catalog.removed, ["reflecto.txt"])

    def testDirectoryUnindex(self):
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        self.reflector.portal_catalog.results = [MockBrain("subdir"), MockBrain("subdir/reflecto.txt")]
        view.unindex()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])
        self.assertEqual(self.reflector.portal_catalog.searches, [{"path": "reflector/subdir"}])
        self.assertEqual(set(self.reflector.portal_catalog.removed), set(["subdir", "subdir/reflecto.txt"]))
예제 #4
0
    def setUp(self):
        super(CopyPasteTests, self).setUp()

        from Products.Reflecto.content.reflector import Reflector

        self.root = FakeRoot()
        self.root.reflecto = self.reflecto
        self.reflecto = self.root.reflecto  # Acquisition wrapped

        # Second reflector, using the subdir as it's filesystem path
        self.root.reflecto2 = Reflector('reflecto2')
        self.reflecto2 = self.root.reflecto2
        self.reflecto2.setRelativePath(os.path.join(self.tmppath, 'subdir'))
        self.indexview2 = MockIndexView()

        # duplicate fake @@index work for reflecto2
        if DefaultTraversable is not None:
            # ease use of ITraversable by setting REQUEST to None
            self.reflecto2.REQUEST = None
            # DefaultTraversable will look up the view as 'index'
            setattr(self.reflecto2, 'index', self.indexview2)
        else:
            setattr(self.reflecto2, '@@index', self.indexview2)

        self.oldpolicy = SecurityManager.setSecurityPolicy(
            UnitTestSecurityPolicy())
        newSecurityManager(None, UnitTestUser().__of__(self.root))
예제 #5
0
 def afterSetUp(self):
     super(DirectoryDownloadTests, self).afterSetUp()
     self.folder.reflector=Reflector('reflector')
     self.reflector=self.folder.reflector
     self.reflector.setRelativePath(samplesPath)
     self.subdir=self.reflector["subdir"]
     self.view=DirectoryDownloadView(self.reflector, self.app.REQUEST)
예제 #6
0
class IndexTests(ReflectoUnitTestCase):
    def setUp(self):
        super(IndexTests, self).setUp()
        self.reflector = Reflector("reflector")
        self.reflector.setRelativePath(samplesPath)

    def testTextFileIndex(self):
        file = self.reflector["reflecto.txt"]
        file.portal_catalog = MockCatalog()
        file.indexObject()
        self.assertEqual(file.portal_catalog.indexed, [file])

    def testDirectoryIndex(self):
        dir = self.reflector["subdir"]
        dir.portal_catalog = MockCatalog()
        dir.indexObject()
        self.assertEqual(dir.portal_catalog.indexed, [dir])
예제 #7
0
class IndexTests(ReflectoUnitTestCase):
    def setUp(self):
        super(IndexTests, self).setUp()
        self.reflector = Reflector('reflector')
        self.reflector.setRelativePath(samplesPath)

    def testTextFileIndex(self):
        file = self.reflector["reflecto.txt"]
        file.portal_catalog = MockCatalog()
        file.indexObject()
        self.assertEqual(file.portal_catalog.indexed, [file])

    def testDirectoryIndex(self):
        dir = self.reflector["subdir"]
        dir.portal_catalog = MockCatalog()
        dir.indexObject()
        self.assertEqual(dir.portal_catalog.indexed, [dir])
예제 #8
0
 def afterSetUp(self):
     ReflectoZopeTestCase.afterSetUp(self)
     self.folder.reflector = Reflector('reflector')
     self.reflector = self.folder.reflector
     self.reflector.setRelativePath(samplesPath)
     self.jpeg = self.reflector["reflecto.jpg"]
     self.text = self.reflector["reflecto.txt"]
     self.BIGJPEG = self.reflector["BIGFILE.JPG"]
     self.subdir = self.reflector["subdir"]
예제 #9
0
 def setUp(self):
     self.reflector = Reflector("reflector")
     self.reflector.setRelativePath(samplesPath)
     self.reflector.portal_catalog = MockCatalog()
예제 #10
0
 def setUp(self):
     super(IndexTests, self).setUp()
     self.reflector = Reflector("reflector")
     self.reflector.setRelativePath(samplesPath)
예제 #11
0
 def setUp(self):
     from Products.Reflecto.content.reflector import Reflector
     super(DirectoryTests, self).setUp()
     self.reflecto = Reflector('reflecto')
     self.reflecto.setRelativePath(samplesPath)
예제 #12
0
 def afterSetUp(self):
     ReflectoZopeTestCase.afterSetUp(self)
     self.folder.reflector=Reflector('reflector')
     self.reflector=self.folder.reflector
     self.reflector.setRelativePath(samplesPath)
예제 #13
0
 def setUp(self):
     self.reflector = Reflector('reflector')
     self.reflector.setRelativePath(samplesPath)
     self.reflector.portal_catalog = MockCatalog()
예제 #14
0
class IndexViewTests(unittest.TestCase):
    def setUp(self):
        self.reflector = Reflector('reflector')
        self.reflector.setRelativePath(samplesPath)
        self.reflector.portal_catalog = MockCatalog()

    def createView(self, context=None):
        if context is None:
            context = self.reflector
        view = IndexView(context, TestRequest())
        return view

    def testViewBasics(self):
        view = self.createView()
        self.failUnless(IIndexView.providedBy(view))
        self.failUnless(verifyObject(IIndexView, view))

    def testFileIndex(self):
        file = self.reflector["reflecto.txt"]
        view = self.createView(file)
        view.index()
        results=["/".join(x.getPathToReflectoParent()) \
                    for x in self.reflector.portal_catalog.indexed]
        self.assertEqual(results, ["reflecto.txt"])

    def testSubdirIndex(self):
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        view.index()
        results=["/".join(x.getPathToReflectoParent()) \
                    for x in self.reflector.portal_catalog.indexed]
        self.assertEqual(set(results), set(["subdir", "subdir/emptyfile.txt"]))

    def testNoSubdirIndexInLifeMode(self):
        self.reflector.setLife(True)
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        view.index()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])

    def testFileUnindex(self):
        file = self.reflector["reflecto.txt"]
        view = self.createView(file)
        self.reflector.portal_catalog.results = [MockBrain("reflecto.txt")]
        view.unindex()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])
        self.assertEqual(self.reflector.portal_catalog.searches,
                         [{
                             'path': 'reflector/reflecto.txt'
                         }])
        self.assertEqual(self.reflector.portal_catalog.removed,
                         ["reflecto.txt"])

    def testDirectoryUnindex(self):
        dir = self.reflector["subdir"]
        view = self.createView(dir)
        self.reflector.portal_catalog.results = [
            MockBrain("subdir"),
            MockBrain("subdir/reflecto.txt")
        ]
        view.unindex()
        self.assertEqual(self.reflector.portal_catalog.indexed, [])
        self.assertEqual(self.reflector.portal_catalog.searches,
                         [{
                             "path": "reflector/subdir"
                         }])
        self.assertEqual(set(self.reflector.portal_catalog.removed),
                         set(["subdir", "subdir/reflecto.txt"]))
예제 #15
0
 def setUp(self):
     super(IndexTests, self).setUp()
     self.reflector = Reflector('reflector')
     self.reflector.setRelativePath(samplesPath)
예제 #16
0
class DirectoryTests(ReflectoUnitTestCase):
    def setUp(self):
        from Products.Reflecto.content.reflector import Reflector
        super(DirectoryTests, self).setUp()
        self.reflecto = Reflector('reflecto')
        self.reflecto.setRelativePath(samplesPath)

    def testIndexOnNonExistingPath(self):
        # Raising OSError for ENOENT has many implications for the user
        # interface: it makes it impossible to import, paste or view
        # reflectors which have a non-existing path. This makes migrating
        # sites extremely hard.
        self.reflecto.setRelativePath("/this/does/not/exist")
        self.assertEqual(self.reflecto.keys(), [])

    def testNotExisting(self):
        self.assertRaises(KeyError, operator.itemgetter('nonesuch'),
                          self.reflecto)
        self.assertRaises(KeyError, operator.itemgetter(1),
                          self.reflecto)

    def testSimpleFile(self):
        self.assertTrue(IReflectoFile.providedBy(self.reflecto['reflecto.jpg']))

    def testDirectory(self):
        self.assertTrue(IReflectoDirectory.providedBy(self.reflecto['subdir']))

    def testDeepFile(self):
        self.assertTrue(IReflectoFile.providedBy(
            self.reflecto['subdir']['emptyfile.txt']))

    def testUnrestrictedTraverse(self):
        self.assertTrue(IReflectoFile.providedBy(
            self.reflecto.unrestrictedTraverse("reflecto.txt")))
        self.assertTrue(IReflectoDirectory.providedBy(
            self.reflecto.unrestrictedTraverse("subdir")))
        self.assertTrue(IReflectoFile.providedBy(
            self.reflecto.unrestrictedTraverse("subdir/emptyfile.txt")))

    def testIteration(self):
        names = set(self.reflecto)
# + patch
#        self.assertEqual(names, set(['reflecto.jpg', 'reflecto.png',
#                                     'reflecto.txt', 'subdir', 'BIGFILE.JPG']))
        self.assert_(set(['reflecto.jpg', 'reflecto.png',
                          'reflecto.txt', 'subdir', 'BIGFILE.JPG']).issubset(self.reflecto))
# - patch

    def testHasKey(self):
        self.assertTrue(self.reflecto.has_key('subdir'))
        self.assertFalse(self.reflecto.has_key('nonesuch'))

    def testAcceptableNames(self):
        self.assertFalse(self.reflecto.acceptableFilename("@@viewname"))
        self.assertTrue(self.reflecto.acceptableFilename("@viewname"))
        # this is allowed now + patch
        #self.assertFalse(self.reflecto.acceptableFilename("++view++viewname"))
        self.assertFalse(self.reflecto.acceptableFilename(".."))
        self.assertFalse(self.reflecto.acceptableFilename("aq_parent"))
        # "Unicode" in fullwidth characters
        # this is allowed now + patch
        #self.assertFalse(self.reflecto.acceptableFilename(
        #    u"\uff35\uff4e\uff49\uff43\uff4f\uff44\uff45"))
        self.assertTrue(self.reflecto.acceptableFilename('Compo\xcc\x81te.txt'))
예제 #17
0
 def setUp(self):
     from Products.Reflecto.content.reflector import Reflector
     super(DirectoryTests, self).setUp()
     self.reflecto = Reflector('reflecto')
     self.reflecto.setRelativePath(samplesPath)
예제 #18
0
class DirectoryTests(ReflectoUnitTestCase):
    def setUp(self):
        from Products.Reflecto.content.reflector import Reflector
        super(DirectoryTests, self).setUp()
        self.reflecto = Reflector('reflecto')
        self.reflecto.setRelativePath(samplesPath)

    def testIndexOnNonExistingPath(self):
        # Raising OSError for ENOENT has many implications for the user
        # interface: it makes it impossible to import, paste or view
        # reflectors which have a non-existing path. This makes migrating
        # sites extremely hard.
        self.reflecto.setRelativePath("/this/does/not/exist")
        self.assertEqual(self.reflecto.keys(), [])

    def testNotExisting(self):
        self.assertRaises(KeyError, operator.itemgetter('nonesuch'),
                          self.reflecto)
        self.assertRaises(KeyError, operator.itemgetter(1), self.reflecto)

    def testSimpleFile(self):
        self.assertTrue(IReflectoFile.providedBy(
            self.reflecto['reflecto.jpg']))

    def testDirectory(self):
        self.assertTrue(IReflectoDirectory.providedBy(self.reflecto['subdir']))

    def testDeepFile(self):
        self.assertTrue(
            IReflectoFile.providedBy(self.reflecto['subdir']['emptyfile.txt']))

    def testUnrestrictedTraverse(self):
        self.assertTrue(
            IReflectoFile.providedBy(
                self.reflecto.unrestrictedTraverse("reflecto.txt")))
        self.assertTrue(
            IReflectoDirectory.providedBy(
                self.reflecto.unrestrictedTraverse("subdir")))
        self.assertTrue(
            IReflectoFile.providedBy(
                self.reflecto.unrestrictedTraverse("subdir/emptyfile.txt")))

    def testIteration(self):
        names = set(self.reflecto)
        # + patch
        #        self.assertEqual(names, set(['reflecto.jpg', 'reflecto.png',
        #                                     'reflecto.txt', 'subdir', 'BIGFILE.JPG']))
        self.assert_(
            set([
                'reflecto.jpg', 'reflecto.png', 'reflecto.txt', 'subdir',
                'BIGFILE.JPG'
            ]).issubset(self.reflecto))


# - patch

    def testHasKey(self):
        self.assertTrue(self.reflecto.has_key('subdir'))
        self.assertFalse(self.reflecto.has_key('nonesuch'))

    def testAcceptableNames(self):
        self.assertFalse(self.reflecto.acceptableFilename("@@viewname"))
        self.assertTrue(self.reflecto.acceptableFilename("@viewname"))
        # this is allowed now + patch
        #self.assertFalse(self.reflecto.acceptableFilename("++view++viewname"))
        self.assertFalse(self.reflecto.acceptableFilename(".."))
        self.assertFalse(self.reflecto.acceptableFilename("aq_parent"))
        # "Unicode" in fullwidth characters
        # this is allowed now + patch
        #self.assertFalse(self.reflecto.acceptableFilename(
        #    u"\uff35\uff4e\uff49\uff43\uff4f\uff44\uff45"))
        self.assertTrue(
            self.reflecto.acceptableFilename('Compo\xcc\x81te.txt'))