Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
fix bug where calling str(resource) would fail for DummyNeededResourc…
Browse files Browse the repository at this point in the history
…es objects. this hurts testability of applications that depend on fanstatic/zope.fanstatic.
  • Loading branch information
janwijbrand committed Aug 31, 2011
1 parent 6aa4fa1 commit 22f9189
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CHANGES.txt
Expand Up @@ -4,8 +4,10 @@ CHANGES
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)
-----------------
Expand Down
15 changes: 13 additions & 2 deletions src/zope/fanstatic/tests/test_computeurl.py
Expand Up @@ -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
Expand Down Expand Up @@ -75,6 +74,18 @@ class NoComputeURLForDummyResources(unittest.TestCase):
# 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())

8 changes: 6 additions & 2 deletions src/zope/fanstatic/tests/tests.py
Expand Up @@ -34,10 +34,14 @@ def testSetUp(self):
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(
Expand Down
4 changes: 4 additions & 0 deletions src/zope/fanstatic/zopesupport.py
Expand Up @@ -96,6 +96,10 @@ def __getitem__(self, name):

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

Expand Down

0 comments on commit 22f9189

Please sign in to comment.