[Zope-CVS] CVS: Products/Basket/tests - testBasket.py:1.34

Chris McDonough chrism at plope.com
Sat Nov 26 16:40:45 EST 2005


Update of /cvs-repository/Products/Basket/tests
In directory cvs.zope.org:/tmp/cvs-serv16148/tests

Modified Files:
	testBasket.py 
Log Message:
Add five product tests, external method tests, and fix a bug where StringIO was not properly imported and pkg_module was not passed in to a function which only used it in an error condition.

Rocky Burt contributed all external method fixes.


=== Products/Basket/tests/testBasket.py 1.33 => 1.34 ===
--- Products/Basket/tests/testBasket.py:1.33	Mon Nov 14 09:31:05 2005
+++ Products/Basket/tests/testBasket.py	Sat Nov 26 16:40:44 2005
@@ -14,6 +14,8 @@
 import App.config
 import zLOG
 
+from zope.app.tests.placelesssetup import PlacelessSetup
+
 here = os.path.dirname(__file__)
 
 class LogInterceptor:
@@ -101,7 +103,7 @@
 def legacymethod(self):
     pass
 
-class TestBasket(unittest.TestCase, LogInterceptor):
+class TestBasket(unittest.TestCase, PlacelessSetup, LogInterceptor):
 
     def setUp(self):
         self.working_set = pkg_resources.working_set
@@ -185,6 +187,26 @@
         self.failUnless(sys.modules.has_key('Products.product1'))
         self.failUnless(sys.modules.has_key('Products.product2'))
 
+    def test_externalmethod(self):
+        basket = self._makeOne()
+        from Products.Basket import monkeypatches
+        monkeypatches.patch_externalmethod(basket)
+        basket.preinitialized = False
+        basket.pdist_fname = os.path.join(self.fixtures,
+                                          'pdist-externalmethod.txt')
+        
+        sys.path.append(self.fixtures)
+        self.working_set.add_entry(self.fixtures)
+
+        result = basket.initialize(DummyProductContext('Basket'))
+        basket.cleanup()
+
+        print result
+
+        expected = [x for x in result if (x and x.startswith('external method')
+                                          )]
+        self.assertEqual(expected[0], 'external method')
+
     def test_initialize_of_broken_at_import_in_debug_mode(self):
         basket = self._makeOne()
         basket.pre_initialized = True
@@ -451,6 +473,62 @@
         self.assertEqual(
             get_containing_package('Shared.DC.ZRDB').__name__,
             'Shared.DC.ZRDB')
+
+    def test_five_product(self):
+        basket = self._makeOne()
+
+        basket.pdist_fname = os.path.join(self.fixtures,'pdist-fiveproduct.txt')
+        
+        sys.path.append(self.fixtures)
+        self.working_set.add_entry(self.fixtures)
+
+        self.failIf(sys.modules.has_key('Products.fiveproduct'))
+
+        result = basket.initialize(DummyProductContext('Basket'))
+
+        import Products.fiveproduct
+
+        self.failUnless(sys.modules.has_key('Products.fiveproduct'))
+
+        from Products.Five.fiveconfigure import findProducts
+        from Products.Five.fiveconfigure import loadProducts
+        from zope.configuration import xmlconfig
+
+        products = findProducts()
+        self.assert_(Products.fiveproduct in products)
+
+        try:
+            # do what Five.loadProduct does
+            sitezcml = """\
+            <configure xmlns="http://namespaces.zope.org/zope"
+               xmlns:five="http://namespaces.zope.org/five">
+               <include package="Products.Five" />
+               <redefinePermission from="zope2.Public" to="zope.Public" />
+               <include package="Products.fiveproduct"/>
+            </configure>"""
+
+            xmlconfig.string(sitezcml)
+
+            # verify that the zcml had the correct effect
+
+            from Products.fiveproduct.module import SampleAdapter
+            from Products.fiveproduct.module import ISampleAdapter
+            from Products.fiveproduct.module import ExtraSampleAdapter
+            from Products.fiveproduct.module import IExtraSampleAdapter
+
+            context = None
+
+            adapter = ISampleAdapter(context)
+            self.assertEqual(adapter.__class__, SampleAdapter)
+            self.assertEqual(adapter.context, context)
+
+            adapter = IExtraSampleAdapter(context)
+            self.assertEqual(adapter.__class__, ExtraSampleAdapter)
+            self.assertEqual(adapter.context, context)
+
+        finally:
+            # clean up
+            PlacelessSetup.tearDown(self)
 
     def _importProduct(self, name):
         __import__(name)



More information about the Zope-CVS mailing list