[Checkins] SVN: zope.fanstatic/trunk/ fix bug where calling str(resource) would fail for DummyNeededResources objects. this hurts testability of applications that depend on fanstatic/zope.fanstatic.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Wed Aug 31 07:59:41 EST 2011


Log message for revision 122709:
  fix bug where calling str(resource) would fail for DummyNeededResources objects. this hurts testability of applications that depend on fanstatic/zope.fanstatic.

Changed:
  U   zope.fanstatic/trunk/CHANGES.txt
  U   zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py
  U   zope.fanstatic/trunk/src/zope/fanstatic/tests/tests.py
  U   zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py

-=-
Modified: zope.fanstatic/trunk/CHANGES.txt
===================================================================
--- zope.fanstatic/trunk/CHANGES.txt	2011-08-30 13:40:26 UTC (rev 122708)
+++ zope.fanstatic/trunk/CHANGES.txt	2011-08-31 12:59:40 UTC (rev 122709)
@@ -4,9 +4,11 @@
 0.12 (unreleased)
 -----------------
 
-- Nothing changed yet.
+- Similar to the fix in 0.11, make sure calling for the URL of a resource
+  will not failed for a `DummyNeededResources` object which would badly hurt
+  testability of function or "browser" tests of applications that depend
+  on fanstatic/zope.fanstatic.
 
-
 0.11 (2011-08-17)
 -----------------
 

Modified: zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py	2011-08-30 13:40:26 UTC (rev 122708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py	2011-08-31 12:59:40 UTC (rev 122709)
@@ -15,7 +15,6 @@
 from zope.component import getMultiAdapter
 from zope.publisher.browser import TestRequest
 from zope.traversing.interfaces import ITraversable
-
 import fanstatic
 from zope.fanstatic.zopesupport import ZopeFanstaticResource, ensure_base_url
 from zope.fanstatic.tests import tests
@@ -75,6 +74,18 @@
     # to setup a full WSGI inclusing fanstatic. Make sure zopesupport
     # works for DummyNeededResources.
 
-    def test_ensure_base_url(self):
+    layer = tests.no_injector_layer
+
+    def test_ensure_base_url_wont_fail(self):
         dummy_needed = fanstatic.get_needed()
         self.assertIsNone(ensure_base_url(dummy_needed, None))
+
+    def test_call_wont_fail(self):
+        context = object()
+        request = TestRequest()
+        resource_namespace  = getMultiAdapter(
+            (context, request), ITraversable, name='resource')
+        resource = resource_namespace.traverse('foo', [])
+        a_js = resource.get('a.js')
+        self.assertEquals('++resource++foo/a.js', a_js())
+

Modified: zope.fanstatic/trunk/src/zope/fanstatic/tests/tests.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/tests.py	2011-08-30 13:40:26 UTC (rev 122708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/tests.py	2011-08-31 12:59:40 UTC (rev 122709)
@@ -34,10 +34,14 @@
         getGlobalSiteManager().registerAdapter(
             resource_factory, (IBrowserRequest,), Interface, foo.name)
 
+layer = TestLayer(zope.fanstatic.tests)
+
+class NoInjectorTestLayer(TestLayer):
+
     def setup_middleware(self, app):
-        return fanstatic.Injector(app)
+        return app
 
-layer = TestLayer(zope.fanstatic.tests)
+no_injector_layer = NoInjectorTestLayer(zope.fanstatic.tests)
 
 def test_suite():
     readme = doctest.DocFileSuite(

Modified: zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py	2011-08-30 13:40:26 UTC (rev 122708)
+++ zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py	2011-08-31 12:59:40 UTC (rev 122709)
@@ -96,6 +96,10 @@
 
     def __str__(self):
         needed = fanstatic.get_needed()
+        if not isinstance(needed, fanstatic.NeededResources):
+            # We cannot render a URL in this case, we just return some
+            # fake url to indicate this.
+            return '++resource++%s%s' % (self.library.name, self.name)
         ensure_base_url(needed, self.request)
         return needed.library_url(self.library) + self.name
 



More information about the checkins mailing list