[Checkins] SVN: zope.fanstatic/trunk/ fix bug where calling ensure_base_url 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 17 06:10:09 EDT 2011


Log message for revision 122601:
  fix bug where calling ensure_base_url 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/zopesupport.py

-=-
Modified: zope.fanstatic/trunk/CHANGES.txt
===================================================================
--- zope.fanstatic/trunk/CHANGES.txt	2011-08-17 09:28:55 UTC (rev 122600)
+++ zope.fanstatic/trunk/CHANGES.txt	2011-08-17 10:10:09 UTC (rev 122601)
@@ -4,15 +4,15 @@
 0.11 (unreleased)
 -----------------
 
-- Nothing changed yet.
+- Fix bug where calling `ensure_base_url()` failed for `DummyNeededResources`
+  objects. This was problematic when writing functional or "browser" tests
+  of applications that depend on fanstatic/zope.fanstatic.
 
-
 0.10 (2011-04-11)
 -----------------
 
 - Update to fanstatic 0.11 API.
 
-
 0.9.1 (2011-01-20)
 ------------------
 

Modified: zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py	2011-08-17 09:28:55 UTC (rev 122600)
+++ zope.fanstatic/trunk/src/zope/fanstatic/tests/test_computeurl.py	2011-08-17 10:10:09 UTC (rev 122601)
@@ -17,7 +17,7 @@
 from zope.traversing.interfaces import ITraversable
 
 import fanstatic
-from zope.fanstatic.zopesupport import ZopeFanstaticResource
+from zope.fanstatic.zopesupport import ZopeFanstaticResource, ensure_base_url
 from zope.fanstatic.tests import tests
 
 class ComputeURL(unittest.TestCase):
@@ -67,3 +67,14 @@
         a_js = resource.get('a.js')
         self.assertEquals(str(a_js), a_js())
 
+class NoComputeURLForDummyResources(unittest.TestCase):
+    # zopesupport.ensure_base_url() will call has_base_url() on the
+    # needed resources object, however DummyNeededResources will not
+    # implement this. We still need to be able to develop browser-tests in
+    # applications that depend on fanstatic/zope.fanstatic withou having
+    # to setup a full WSGI inclusing fanstatic. Make sure zopesupport
+    # works for DummyNeededResources.
+
+    def test_ensure_base_url(self):
+        dummy_needed = fanstatic.get_needed()
+        self.assertIsNone(ensure_base_url(dummy_needed, None))

Modified: zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py
===================================================================
--- zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py	2011-08-17 09:28:55 UTC (rev 122600)
+++ zope.fanstatic/trunk/src/zope/fanstatic/zopesupport.py	2011-08-17 10:10:09 UTC (rev 122601)
@@ -24,6 +24,9 @@
 from zope.fanstatic.interfaces import IZopeFanstaticResource
 
 def ensure_base_url(needed, request):
+    if not isinstance(needed, fanstatic.NeededResources):
+        # Do nothing if there's no concrete NeededResources at all.
+        return
     if not needed.has_base_url():
         # Only set the base_url if it has not been set just yet.
         #
@@ -48,15 +51,13 @@
     # on essential information for computing URLs. One example of such
     # information is that of the virtualhost namespace traversal.
     needed = fanstatic.get_needed()
-    if not needed.has_resources():
-        # Do nothing if there're no resources needed at all.
-        return
     ensure_base_url(needed, event.request)
 
 @adapter(IHandleExceptionEvent)
 def clear_needed_resources(event):
     needed = fanstatic.get_needed()
     if isinstance(needed, fanstatic.NeededResources):
+        # Only if there's a concrete NeededResources.
         needed.clear()
 
 _sentinel = object()



More information about the checkins mailing list