[Checkins] SVN: zope.globalrequest/trunk/src/zope/globalrequest/ move the view registration into the doctest so that reading it makes more sense... :)
Andreas Zeidler
az at zitc.de
Thu Jan 15 11:10:42 EST 2009
Log message for revision 94760:
move the view registration into the doctest so that reading it makes more sense... :)
Changed:
U zope.globalrequest/trunk/src/zope/globalrequest/README.txt
U zope.globalrequest/trunk/src/zope/globalrequest/ftesting.zcml
D zope.globalrequest/trunk/src/zope/globalrequest/ftests.py
-=-
Modified: zope.globalrequest/trunk/src/zope/globalrequest/README.txt
===================================================================
--- zope.globalrequest/trunk/src/zope/globalrequest/README.txt 2009-01-15 16:10:35 UTC (rev 94759)
+++ zope.globalrequest/trunk/src/zope/globalrequest/README.txt 2009-01-15 16:10:41 UTC (rev 94760)
@@ -18,8 +18,46 @@
The remainder of this file contains functional tests to demonstrate that the
package works as intended.
-First we make sure our test view works:
+First we need to define a browser view along with an interface for a utility
+that will be used by that view:
+ >>> from zope.interface import Interface
+ >>> class IFoo(Interface):
+ ... """ interface for a foo-ish utility """
+ ... def foo():
+ ... """ return some foo """
+
+ >>> from zope.publisher.browser import BrowserPage
+ >>> from zope.component import queryUtility
+ >>> class FooView(BrowserPage):
+ ... """ a browser view """
+ ... def __call__(self, *args, **kw):
+ ... foo = queryUtility(IFoo, default=None)
+ ... if foo is not None:
+ ... return foo.foo()
+ ... else:
+ ... return 'sif!'
+
+Unfortunately the view class cannot be directly imported from here, i.e.
+relatively, so we have to make it available from somewhere else in order to register it:
+
+ >>> from zope.globalrequest import tests
+ >>> tests.FooView = FooView
+ >>> zcml("""
+ ... <configure
+ ... xmlns="http://namespaces.zope.org/zope"
+ ... xmlns:browser="http://namespaces.zope.org/browser">
+ ... <include package="zope.app.publisher" file="meta.zcml" />
+ ... <browser:page
+ ... name="foo"
+ ... for="*"
+ ... class="zope.globalrequest.tests.FooView"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """)
+
+Next let's make sure our test view actually works:
+
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.open('http://localhost/@@foo')
@@ -30,10 +68,9 @@
so let's define one:
>>> from zope.interface import implements
- >>> from zope.globalrequest import ftests
>>> from zope.globalrequest import getRequest
>>> class Foo(object):
- ... implements(ftests.IFoo)
+ ... implements(IFoo)
... def foo(self):
... request = getRequest()
... if request:
@@ -42,17 +79,18 @@
... name = 'foo'
... return 'y0 %s!' % name
-Unfortunately the utility class cannot be directly imported from here, i.e.
-relatively, so we have to make it available from somewhere else to register
-the utility:
+Again, the utility class and interface cannot be directly imported from here,
+so let's also make them available from somewhere else in order to register
+utility:
- >>> ftests.Foo = Foo
+ >>> tests.Foo = Foo
+ >>> tests.IFoo = IFoo
>>> zcml("""
... <configure xmlns="http://namespaces.zope.org/zope">
... <include package="zope.component" file="meta.zcml" />
... <utility
- ... factory="zope.globalrequest.ftests.Foo"
- ... provides="zope.globalrequest.ftests.IFoo" />
+ ... factory="zope.globalrequest.tests.Foo"
+ ... provides="zope.globalrequest.tests.IFoo" />
... </configure>
... """)
Modified: zope.globalrequest/trunk/src/zope/globalrequest/ftesting.zcml
===================================================================
--- zope.globalrequest/trunk/src/zope/globalrequest/ftesting.zcml 2009-01-15 16:10:35 UTC (rev 94759)
+++ zope.globalrequest/trunk/src/zope/globalrequest/ftesting.zcml 2009-01-15 16:10:41 UTC (rev 94760)
@@ -25,11 +25,4 @@
<grant permission="zope.View"
role="zope.Anonymous" />
- <browser:page
- name="foo"
- for="*"
- class=".ftests.FooView"
- permission="zope.Public"
- />
-
</configure>
Deleted: zope.globalrequest/trunk/src/zope/globalrequest/ftests.py
===================================================================
--- zope.globalrequest/trunk/src/zope/globalrequest/ftests.py 2009-01-15 16:10:35 UTC (rev 94759)
+++ zope.globalrequest/trunk/src/zope/globalrequest/ftests.py 2009-01-15 16:10:41 UTC (rev 94760)
@@ -1,22 +0,0 @@
-from zope.publisher.browser import BrowserPage
-from zope.interface import Interface
-from zope.component import queryUtility
-
-
-class IFoo(Interface):
- """ interface for a foo-ish utility """
-
- def foo():
- """ return some foo """
-
-
-class FooView(BrowserPage):
- """ a browser view """
-
- def __call__(self, *args, **kw):
- foo = queryUtility(IFoo, default=None)
- if foo is not None:
- return foo.foo()
- else:
- return 'sif!'
-
More information about the Checkins
mailing list