[Checkins] SVN: grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple Rewrote the tests for the 'static' namespace in page templates. Use dummy resource instead of a real one.
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Sun Jan 2 16:37:09 EST 2011
Log message for revision 119266:
Rewrote the tests for the 'static' namespace in page templates. Use dummy resource instead of a real one.
Changed:
U grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py
D grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple_fixture/static/
-=-
Modified: grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py
===================================================================
--- grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py 2011-01-02 21:36:21 UTC (rev 119265)
+++ grokcore.view/trunk/src/grokcore/view/ftests/staticdir/simple.py 2011-01-02 21:37:08 UTC (rev 119266)
@@ -1,19 +1,13 @@
"""
-If there is a static/ directory inside of a grokked package, its
-contents will be available as static resources under a URL:
+We use a special name 'static' in page templates to allow easy linking
+to resources.
+In the context of a grok application, you can use fanstatic (through zope.fanstatic)
+instead of the dummy implementation in this test:
+
>>> from zope.app.wsgi.testlayer import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
- >>> browser.open(
- ... 'http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/'
- ... 'file.txt')
- >>> print browser.contents
- some text
-
-We use a special name 'static' in page templates to allow easy linking
-to resources:
-
>>> root = getRootFolder()
>>> from grokcore.view.ftests.staticdir.simple_fixture.ellie import Mammoth
>>> root[u'ellie'] = Mammoth()
@@ -21,42 +15,34 @@
>>> print browser.contents
<html>
<body>
- <a href="http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/file.txt">Some text in a file</a>
+ <a href="dummy:/file.txt">Some text in a file</a>
</body>
</html>
-Static also means that page templates will not be interpreted:
+"""
+import zope.interface
+import zope.component
- >>> browser.open(
- ... 'http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/'
- ... 'static.pt')
- >>> print browser.contents
- <html>
- <body>
- <h1 tal:content="string:will not be interpreted"/>
- </body>
- </html>
+from zope.traversing.interfaces import ITraversable
+from zope.traversing.browser.interfaces import IAbsoluteURL
+from zope.publisher.interfaces.browser import IBrowserRequest
-We also support subdirectories for resources:
+class DummyResource(object):
+ """ Dummy resource implementation. """
+ zope.interface.implements(ITraversable, IAbsoluteURL)
- >>> browser.open(
- ... 'http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/'
- ... 'subdir/otherfile.txt')
- >>> print browser.contents
- This is yet another file.
+ def __init__(self, request, name=''):
+ self.request = request
+ self.name = name
-There used to be a bug where subdirectories of the static directory were not
-instances of grokcore.view.component.DirectoryResource and as a result,
-pagetemplate files were actually executed. This is fixed.
+ def traverse(self, name, furtherPath):
+ name = '%s/%s' % (self.name, name)
+ return DummyResource(self.request, name=name)
- >>> browser.open(
- ... 'http://localhost/@@/grokcore.view.ftests.staticdir.simple_fixture/'
- ... 'subdir/static.pt')
- >>> print browser.contents
- <html>
- <body>
- <h1 tal:content="string:will not be interpreted"/>
- </body>
- </html>
+ def __str__(self):
+ return 'dummy:%s' % self.name
-"""
+zope.component.provideAdapter(factory=DummyResource,
+ adapts=(IBrowserRequest,),
+ provides=zope.interface.Interface,
+ name='grokcore.view.ftests.staticdir.simple_fixture')
More information about the checkins
mailing list