[CMF-checkins] CVS: Products/CMFCore/tests - test_DirectoryView.py:1.21

Jens Vagelpohl jens at dataflake.org
Mon Feb 28 16:47:22 EST 2005


Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv13816/tests

Modified Files:
	test_DirectoryView.py 
Log Message:
- Feature addition to DirectoryView and derived classes: It is now
  possible to customize what gets created to represent directories
  inside the directory view.

  Previously, the code had a fixed assumption that all directories
  on the file system must turn into instances of 
  CMFCore.DirectoryView.DirectoryView(Surrogate). It is now possible
  to register a class deriving from DirectoryView and have that be
  instantiated instead.

  Filesystem directories, unfortunately, carry no meta_type information
  or file extensions by which to recognize them using the available
  registration methods exposed by the DirectoryView module. The somewhat
  kludgy workaround involves using a hardcoded special meta_type with
  the name "FOLDER". Your DirectoryView-derived class can thus be
  registered using the registerMetaType function by specifying the
  name "FOLDER" as the meta_type to register for.


=== Products/CMFCore/tests/test_DirectoryView.py 1.20 => 1.21 ===
--- Products/CMFCore/tests/test_DirectoryView.py:1.20	Wed Nov 24 10:12:30 2004
+++ Products/CMFCore/tests/test_DirectoryView.py	Mon Feb 28 16:47:21 2005
@@ -13,6 +13,16 @@
 from Products.CMFCore.tests.base.testcase import _prefix
 from Products.CMFCore.tests.base.testcase import FSDVTest
 
+from Products.CMFCore.DirectoryView import DirectoryView
+
+
+class DummyDirectoryView(DirectoryView):
+    def __of__(self, parent):
+        return DummyDirectoryViewSurrogate()
+
+class DummyDirectoryViewSurrogate:
+    pass
+
 
 class DirectoryViewPathTests( TestCase ):
     """
@@ -148,6 +158,43 @@
         # Test that the .test1.py is ignored
         assert('#test1' not in self.ob.fake_skin.objectIds())
 
+
+class DirectoryViewFolderTests(FSDVTest):
+
+    def setUp(self):
+        FSDVTest.setUp(self)
+        self._registerDirectory(self)
+
+    def tearDown(self):
+        from Products.CMFCore import DirectoryView
+        # This is nasty, but there is no way to unregister anything
+        # right now...
+        metatype_registry = DirectoryView._dirreg._meta_types
+        if 'FOLDER' in metatype_registry.keys():
+            del metatype_registry['FOLDER']
+        FSDVTest.tearDown(self)
+
+    def test_DirectoryViewFolderDefault(self):
+        # Test that a folder inside the fake skin really is of type
+        # DirectoryViewSurrogate
+        from Products.CMFCore.DirectoryView import DirectoryViewSurrogate
+        testfolder = self.ob.fake_skin.test_directory
+        self.failUnless(isinstance(testfolder, DirectoryViewSurrogate))
+
+    def test_DirectoryViewFolderCustom(self):
+        # Now we register a different class under the fake meta_type
+        # "FOLDER" and test again...
+        from Products.CMFCore.DirectoryView import registerMetaType
+        registerMetaType('FOLDER', DummyDirectoryView)
+
+        # In order to regenerate the FSDV data we need to remove and
+        # register again, that way the newly registered meta_type is used
+        self.ob._delObject('fake_skin')
+        self._registerDirectory(self)
+        testfolder = self.ob.fake_skin.test_directory
+        self.failUnless(isinstance(testfolder, DummyDirectoryViewSurrogate))
+
+
 if DevelopmentMode:
 
   class DebugModeTests( FSDVTest ):
@@ -223,6 +270,7 @@
     return TestSuite((
         makeSuite(DirectoryViewPathTests),
         makeSuite(DirectoryViewTests),
+        makeSuite(DirectoryViewFolderTests),
         makeSuite(DebugModeTests),
         ))
 



More information about the CMF-checkins mailing list