[Checkins] SVN: five.grok/trunk/src/five/grok/ First test of tests
copied from Grok running.
Lennart Regebro
regebro at gmail.com
Thu Jul 17 07:49:10 EDT 2008
Log message for revision 88433:
First test of tests copied from Grok running.
Changed:
U five.grok/trunk/src/five/grok/__init__.py
U five.grok/trunk/src/five/grok/components.py
A five.grok/trunk/src/five/grok/interfaces.py
U five.grok/trunk/src/five/grok/meta.py
A five.grok/trunk/src/five/grok/testing.py
U five.grok/trunk/src/five/grok/tests/adapters.py
U five.grok/trunk/src/five/grok/tests/configure.zcml
U five.grok/trunk/src/five/grok/tests/multiadapter.py
U five.grok/trunk/src/five/grok/tests/subscribers.py
U five.grok/trunk/src/five/grok/tests/test_all.py
D five.grok/trunk/src/five/grok/tests/test_secure_views.py
U five.grok/trunk/src/five/grok/tests/utilities.py
A five.grok/trunk/src/five/grok/tests/view/
A five.grok/trunk/src/five/grok/tests/view/__init__.py
A five.grok/trunk/src/five/grok/tests/view/view.py
D five.grok/trunk/src/five/grok/tests/views.py
-=-
Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/__init__.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,6 +1,14 @@
# Import adapter and utility support from grokcore.component.
-from grokcore.component import *
+from zope.interface import implements
+from zope.component import adapts
-from five.grok.components import View
+from grokcore.component import Adapter, MultiAdapter, GlobalUtility
+from grokcore.component.directive import context, name, provides
+from grokcore.component.decorators import subscribe
+
+from five.grok.components import View, Model
from five.grok.directive import require, layer
+
+# I don't know why this is necessary:
+from five.grok import testing
\ No newline at end of file
Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/components.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,5 +1,23 @@
+from zope import interface
+from zope.annotation.interfaces import IAttributeAnnotatable
+
+from OFS.SimpleItem import SimpleItem
from Products.Five import BrowserView
+from five.grok import interfaces
+
+from zope.app.container.contained import Contained
+import persistent
+
+class Model(Contained, persistent.Persistent):
+ # XXX Inheritance order is important here. If we reverse this,
+ # then containers can't be models anymore because no unambigous MRO
+ # can be established.
+ interface.implements(IAttributeAnnotatable, interfaces.IContext)
+
+
class View(BrowserView):
- pass
+
+ def __call__(self):
+ return self.render()
Added: five.grok/trunk/src/five/grok/interfaces.py
===================================================================
--- five.grok/trunk/src/five/grok/interfaces.py (rev 0)
+++ five.grok/trunk/src/five/grok/interfaces.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -0,0 +1,525 @@
+##############################################################################
+#
+# Copyright (c) 2006-2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Grok interfaces
+"""
+from zope import interface, schema
+from zope.publisher.interfaces.browser import IBrowserPage, IBrowserView
+from zope.formlib.interfaces import reConstraint
+from zope.interface.interfaces import IInterface
+from zope.viewlet.interfaces import IViewletManager as IViewletManagerBase
+from zope.app.container.interfaces import IContainer as IContainerBase
+
+from grokcore.component.interfaces import IContext
+
+class IGrokBaseClasses(interface.Interface):
+ ClassGrokker = interface.Attribute("Base class to define a class "
+ "grokker.")
+ InstanceGrokker = interface.Attribute("Base class to define an "
+ "instance grokker.")
+ ModuleGrokker = interface.Attribute("Base class to define a "
+ "module grokker.")
+ Model = interface.Attribute("Base class for persistent content objects "
+ "(models).")
+ Container = interface.Attribute("Base class for containers.")
+ OrderedContainer = interface.Attribute("Base class for ordered containers.")
+ Site = interface.Attribute("Mixin class for sites.")
+ Application = interface.Attribute("Base class for applications.")
+ Adapter = interface.Attribute("Base class for adapters.")
+ MultiAdapter = interface.Attribute("Base class for multi-adapters.")
+ Annotation = interface.Attribute("Base class for persistent annotations.")
+ GlobalUtility = interface.Attribute("Base class for global utilities.")
+ LocalUtility = interface.Attribute("Base class for local utilities.")
+ View = interface.Attribute("Base class for browser views.")
+ XMLRPC = interface.Attribute("Base class for XML-RPC methods.")
+ JSON = interface.Attribute("Base class for JSON methods.")
+ REST = interface.Attribute("Base class for REST views.")
+ Traverser = interface.Attribute("Base class for custom traversers.")
+ Form = interface.Attribute("Base class for forms.")
+ AddForm = interface.Attribute("Base class for add forms.")
+ EditForm = interface.Attribute("Base class for edit forms.")
+ DisplayForm = interface.Attribute("Base class for display forms.")
+ Indexes = interface.Attribute("Base class for catalog index definitions.")
+ Layer = interface.Attribute("Base interface for layers.")
+ Skin = interface.Attribute("Base class for skin.")
+ ViewletManager = interface.Attribute("Base class for viewletmanager.")
+ Viewlet = interface.Attribute("Base class for viewlet.")
+ Permission = interface.Attribute("Base class for permissions.")
+ Role = interface.Attribute("Base class for roles.")
+ Public = interface.Attribute("Marker for explicitly not requiring a permission.")
+
+
+class IGrokErrors(interface.Interface):
+
+ def GrokError(message, component):
+ """Error indicating that a problem occurrend during the
+ grokking of a module (at "grok time")."""
+
+ def GrokImportError(*args):
+ """Error indicating a problem at import time."""
+
+
+class IGrokDirectives(interface.Interface):
+
+ def implements(*interfaces):
+ """Declare that a class implements the given interfaces."""
+
+ def adapts(*classes_or_interfaces):
+ """Declare that a class adapts objects of the given classes or
+ interfaces."""
+
+ def context(class_or_interface):
+ """Declare the context for views, adapters, etc.
+
+ This directive can be used on module and class level. When
+ used on module level, it will set the context for all views,
+ adapters, etc. in that module. When used on class level, it
+ will set the context for that particular class."""
+
+ def name(name):
+ """Declare the name of a view or adapter/multi-adapter.
+
+ This directive can only be used on class level."""
+
+ def layer(layer):
+ """Declare the layer for the view.
+
+ This directive acts as a contraint on the 'request' of
+ grok.View. This directive can only be used on class level."""
+
+ def skin(skin):
+ """Declare this layer as a named skin.
+
+ This directive can only be used on class level."""
+
+ def template(template):
+ """Declare the template name for a view.
+
+ This directive can only be used on class level."""
+
+ def templatedir(directory):
+ """Declare a directory to be searched for templates.
+
+ By default, grok will take the name of the module as the name
+ of the directory. This can be overridden using
+ ``templatedir``."""
+
+ def provides(interface):
+ """Explicitly specify with which interface a component will be
+ looked up."""
+
+ def baseclass():
+ """Mark this class as a base class.
+
+ This means it won't be grokked, though if it's a possible context,
+ it can still serve as a context.
+ """
+
+ def global_utility(factory, provides=None, name=u''):
+ """Register a global utility.
+
+ factory - the factory that creates the global utility
+ provides - the interface the utility should be looked up with
+ name - the name of the utility
+ """
+
+ def local_utility(factory, provides=None, name=u'',
+ setup=None, public=False, name_in_container=None):
+ """Register a local utility.
+
+ factory - the factory that creates the local utility
+ provides - the interface the utility should be looked up with
+ name - the name of the utility
+ setup - a callable that receives the utility as its single argument,
+ it is called after the utility has been created and stored
+ public - if False, the utility will be stored below ++etc++site
+ if True, the utility will be stored directly in the site.
+ The site should in this case be a container.
+ name_in_container - the name to use for storing the utility
+ """
+
+ def permissions(permissions):
+ """Specify the permissions that comprise a role.
+ """
+
+ def require(permission):
+ """Protect a view class or an XMLRPC method with ``permision``.
+
+ ``permission`` must already be defined, e.g. using
+ grok.Permission.
+
+ grok.require can be used as a class-level directive or as a
+ method decorator."""
+
+ def site(class_or_interface):
+ """Specifies the site that an indexes definition is for.
+
+ It can only be used inside grok.Indexes subclasses.
+ """
+
+ def order(value=None):
+ """Control the ordering of components.
+
+ If the value is specified, the order will be determined by sorting on
+ it.
+ If no value is specified, the order will be determined by definition
+ order within the module.
+ If the directive is absent, the order will be determined by class name.
+ (unfortunately our preferred default behavior on absence which would
+ be like grok.order() without argument is hard to implement in Python)
+
+ Inter-module order is by dotted name of the module the
+ components are in; unless an explicit argument is specified to
+ ``grok.order()``, components are grouped by module.
+
+ The function grok.util.sort_components can be used to sort
+ components according to these rules.
+ """
+
+
+class IGrokDecorators(interface.Interface):
+
+ def subscribe(*classes_or_interfaces):
+ """Declare that a function subscribes to an event or a
+ combination of objects and events."""
+
+ def action(label, **options):
+ """Decorator that defines an action factory based on a form
+ method. The method receives the form data as keyword
+ parameters."""
+
+
+class IGrokEvents(interface.Interface):
+
+ IObjectCreatedEvent = interface.Attribute("")
+
+ ObjectCreatedEvent = interface.Attribute("")
+
+ IObjectModifiedEvent = interface.Attribute("")
+
+ ObjectModifiedEvent = interface.Attribute("")
+
+ IObjectCopiedEvent = interface.Attribute("")
+
+ ObjectCopiedEvent = interface.Attribute("")
+
+ IObjectAddedEvent = interface.Attribute("")
+
+ ObjectAddedEvent = interface.Attribute("")
+
+ IObjectMovedEvent = interface.Attribute("")
+
+ ObjectMovedEvent = interface.Attribute("")
+
+ IObjectRemovedEvent = interface.Attribute("")
+
+ ObjectRemovedEvent = interface.Attribute("")
+
+ IContainerModifiedEvent = interface.Attribute("")
+
+ ContainerModifiedEvent = interface.Attribute("")
+
+
+class IGrokAPI(IGrokBaseClasses, IGrokDirectives, IGrokDecorators,
+ IGrokEvents, IGrokErrors):
+
+ def grok(dotted_name):
+ """Grok a module or package specified by ``dotted_name``."""
+
+ def grok_component(name, component, context=None, module_info=None,
+ templates=None):
+ """Grok an arbitrary object. Can be useful during testing.
+
+ name - the name of the component (class name, or global instance name
+ as it would appear in a module).
+ component - the object (class, etc) to grok.
+ context - the context object (optional).
+ module_info - the module being grokked (optional).
+ templates - the templates registry (optional).
+
+ Note that context, module_info and templates might be required
+ for some grokkers which rely on them.
+ """
+
+ def url(request, obj, name=None, data=None):
+ """Generate the URL to an object with optional name attached.
+ An optional argument 'data' can be a dictionary that is converted
+ into a query string appended to the URL.
+ """
+
+ def notify(event):
+ """Send ``event`` to event subscribers."""
+
+ def getSite():
+ """Get the current site."""
+
+ def PageTemplate(template):
+ """Create a Grok PageTemplate object from ``template`` source
+ text. This can be used for inline PageTemplates."""
+
+ def PageTemplateFile(filename):
+ """Create a Grok PageTemplate object from a file specified by
+ ``filename``. It will be treated like an inline template
+ created with ``PageTemplate``."""
+
+ def Fields(*args, **kw):
+ """Return a list of formlib fields based on interfaces and/or schema
+ fields."""
+
+ def AutoFields(context):
+ """Return a list of fields for context autogenerated by grok.
+ """
+
+ def action(label, actions=None, **options):
+ """grok-specific action decorator.
+ """
+
+ IRESTSkinType = interface.Attribute('The REST skin type')
+
+class IGrokView(IBrowserPage, IBrowserView):
+ """Grok views all provide this interface."""
+
+ context = interface.Attribute('context', "Object that the view presents.")
+
+ request = interface.Attribute('request', "Request that the view was looked"
+ "up with.")
+
+ response = interface.Attribute('response', "Response object that is "
+ "associated with the current request.")
+
+ static = interface.Attribute('static', "Directory resource containing "
+ "the static files of the view's package.")
+
+ def redirect(url):
+ """Redirect to given URL"""
+
+ def url(obj=None, name=None, data=None):
+ """Construct URL.
+
+ If no arguments given, construct URL to view itself.
+
+ If only obj argument is given, construct URL to obj.
+
+ If only name is given as the first argument, construct URL
+ to context/name.
+
+ If both object and name arguments are supplied, construct
+ URL to obj/name.
+
+ Optionally pass a 'data' keyword argument which gets added to the URL
+ as a cgi query string.
+ """
+
+ def default_namespace():
+ """Returns a dictionary of namespaces that the template
+ implementation expects to always be available.
+
+ This method is *not* intended to be overridden by application
+ developers.
+ """
+
+ def namespace():
+ """Returns a dictionary that is injected in the template
+ namespace in addition to the default namespace.
+
+ This method *is* intended to be overridden by the application
+ developer.
+ """
+
+ def update(**kw):
+ """This method is meant to be implemented by grok.View
+ subclasses. It will be called *before* the view's associated
+ template is rendered and can be used to pre-compute values
+ for the template.
+
+ update() can take arbitrary keyword parameters which will be
+ filled in from the request (in that case they *must* be
+ present in the request)."""
+
+ def render(**kw):
+ """A view can either be rendered by an associated template, or
+ it can implement this method to render itself from Python.
+ This is useful if the view's output isn't XML/HTML but
+ something computed in Python (plain text, PDF, etc.)
+
+ render() can take arbitrary keyword parameters which will be
+ filled in from the request (in that case they *must* be
+ present in the request)."""
+
+ def application_url(name=None):
+ """Return the URL of the closest application object in the
+ hierarchy or the URL of a named object (``name`` parameter)
+ relative to the closest application object.
+ """
+
+ def flash(message, type='message'):
+ """Send a short message to the user."""
+
+
+class IGrokForm(IGrokView):
+ """Grok form API, inspired by zope.formlib's IFormBaseCustomization.
+
+ We explicitly don't inherit from IFormBaseCustomization because
+ that would imply ISubPage with another definition of update() and
+ render() than IGrokView has.
+ """
+
+ prefix = schema.ASCII(
+ constraint=reConstraint(
+ '[a-zA-Z][a-zA-Z0-9_]*([.][a-zA-Z][a-zA-Z0-9_]*)*',
+ "Must be a sequence of not-separated identifiers"),
+ description=u"""Page-element prefix
+
+ All named or identified page elements in a subpage should have
+ names and identifiers that begin with a subpage prefix
+ followed by a dot.
+ """,
+ readonly=True,
+ )
+
+ def setPrefix(prefix):
+ """Update the subpage prefix
+ """
+
+ label = interface.Attribute("A label to display at the top of a form")
+
+ status = interface.Attribute(
+ """An update status message
+
+ This is normally generated by success or failure handlers.
+ """)
+
+ errors = interface.Attribute(
+ """Sequence of errors encountered during validation
+ """)
+
+ form_result = interface.Attribute(
+ """Return from action result method
+ """)
+
+ form_reset = interface.Attribute(
+ """Boolean indicating whether the form needs to be reset
+ """)
+
+ form_fields = interface.Attribute(
+ """The form's form field definitions
+
+ This attribute is used by many of the default methods.
+ """)
+
+ widgets = interface.Attribute(
+ """The form's widgets
+
+ - set by setUpWidgets
+
+ - used by validate
+ """)
+
+ def setUpWidgets(ignore_request=False):
+ """Set up the form's widgets.
+
+ The default implementation uses the form definitions in the
+ form_fields attribute and setUpInputWidgets.
+
+ The function should set the widgets attribute.
+ """
+
+ def validate(action, data):
+ """The default form validator
+
+ If an action is submitted and the action doesn't have it's own
+ validator then this function will be called.
+ """
+
+ template = interface.Attribute(
+ """Template used to display the form
+ """)
+
+ def resetForm():
+ """Reset any cached data because underlying content may have changed
+ """
+
+ def error_views():
+ """Return views of any errors.
+
+ The errors are returned as an iterable.
+ """
+
+ def applyData(obj, **data):
+ """Save form data to an object.
+
+ This returns a dictionary with interfaces as keys and lists of
+ field names as values to indicate which fields in which
+ schemas had to be changed in order to save the data. In case
+ the method works in update mode (e.g. on EditForms) and
+ doesn't have to update an object, the dictionary is empty.
+ """
+
+class IREST(interface.Interface):
+ context = interface.Attribute("Object that the REST handler presents.")
+
+ request = interface.Attribute("Request that REST handler was looked"
+ "up with.")
+
+ body = interface.Attribute(
+ """The text of the request body.""")
+
+class IApplication(interface.Interface):
+ """Marker-interface for grok application factories.
+
+ Used to register applications as utilities to look them up and
+ provide a list of grokked applications.
+ """
+
+class IIndexDefinition(interface.Interface):
+ """Define an index for grok.Indexes.
+ """
+
+ def setup(catalog, name, context):
+ """Set up index called name in given catalog.
+
+ Use name for index name and attribute to index. Set up
+ index for interface or class context.
+ """
+
+class IRESTSkinType(IInterface):
+ """Skin type for REST requests.
+ """
+
+class ITemplateFileFactory(interface.Interface):
+ """Utility that generates templates from files in template directories.
+ """
+
+ def __call__(filename, _prefix=None):
+ """Creates an ITemplate from a file
+
+ _prefix is the directory the file is located in
+ """
+
+class ITemplate(interface.Interface):
+ """Template objects
+ """
+
+ def _initFactory(factory):
+ """Template language specific initializations on the view factory."""
+
+ def render(view):
+ """Renders the template"""
+
+class IContainer(IContext, IContainerBase):
+ """A Grok container.
+ """
+
+class IViewletManager(IViewletManagerBase):
+ """The Grok viewlet manager.
+ """
Property changes on: five.grok/trunk/src/five/grok/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: five.grok/trunk/src/five/grok/meta.py
===================================================================
--- five.grok/trunk/src/five/grok/meta.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/meta.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -13,13 +13,11 @@
return factory.__name__.lower()
class ViewGrokker(martian.ClassGrokker):
- component_class = grok.View
- directives = [
- grok.context.bind(),
- grok.layer.bind(default=IDefaultBrowserLayer),
- grok.name.bind(get_default=default_view_name),
- grok.require.bind(name='permission'),
- ]
+ martian.component(grok.View)
+ martian.directive(grok.context)
+ martian.directive(grok.layer, default=IDefaultBrowserLayer)
+ martian.directive(grok.name, get_default=default_view_name)
+ martian.directive(grok.require, name='permission')
def grok(self, name, factory, module_info, **kw):
# Need to store the module info object on the view class so that it
@@ -28,6 +26,8 @@
return super(ViewGrokker, self).grok(name, factory, module_info, **kw)
def execute(self, factory, config, context, layer, name, permission, **kw):
+ if permission is None:
+ permission = 'zope.Public'
# find templates
templates = factory.module_info.getAnnotation('grok.templates', None)
if templates is not None:
Added: five.grok/trunk/src/five/grok/testing.py
===================================================================
--- five.grok/trunk/src/five/grok/testing.py (rev 0)
+++ five.grok/trunk/src/five/grok/testing.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -0,0 +1,46 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Grok test helpers
+"""
+import grokcore.component
+from zope.configuration.config import ConfigurationMachine
+from martian import scan
+from grokcore.component import zcml
+
+def grok(module_name):
+ config = ConfigurationMachine()
+ zcml.do_grok('grokcore.component.meta', config)
+ zcml.do_grok('five.grok.meta', config)
+ zcml.do_grok(module_name, config)
+ config.execute_actions()
+
+def grok_component(name, component,
+ context=None, module_info=None, templates=None):
+ if module_info is None:
+ obj_module = getattr(component, '__grok_module__', None)
+ if obj_module is None:
+ obj_module = getattr(component, '__module__', None)
+ module_info = scan.module_info_from_dotted_name(obj_module)
+
+ module = module_info.getModule()
+ if context is not None:
+ grokcore.component.context.set(module, context)
+ if templates is not None:
+ module.__grok_templates__ = templates
+ config = ConfigurationMachine()
+ result = zcml.the_multi_grokker.grok(name, component,
+ module_info=module_info,
+ config=config)
+ config.execute_actions()
+ return result
Property changes on: five.grok/trunk/src/five/grok/testing.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: five.grok/trunk/src/five/grok/tests/adapters.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/adapters.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/adapters.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,5 +1,7 @@
"""Testing that grokcore adapters work under Zope2
+ >>> grok.testing.grok(__name__)
+
>>> from OFS.SimpleItem import SimpleItem
>>> item = SimpleItem()
>>> item.id = 'item'
Modified: five.grok/trunk/src/five/grok/tests/configure.zcml
===================================================================
--- five.grok/trunk/src/five/grok/tests/configure.zcml 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/configure.zcml 2008-07-17 11:49:10 UTC (rev 88433)
@@ -2,6 +2,4 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:grok="http://namespaces.zope.org/grok">
- <grok:grok package="." />
-
</configure>
Modified: five.grok/trunk/src/five/grok/tests/multiadapter.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/multiadapter.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/multiadapter.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -3,6 +3,8 @@
__init__():
+ >>> grok.testing.grok(__name__)
+
>>> cave = Cave()
>>> fireplace = Fireplace()
Modified: five.grok/trunk/src/five/grok/tests/subscribers.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/subscribers.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/subscribers.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,5 +1,7 @@
"""Testing that grokcore subscribers work under Zope2
+ >>> grok.testing.grok(__name__)
+
You can subscribe to events using the @grok.subscribe decorator:
>>> from OFS.SimpleItem import SimpleItem
Modified: five.grok/trunk/src/five/grok/tests/test_all.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/test_all.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/test_all.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,6 +1,6 @@
import unittest
-from zope.testing import doctestunit
+from zope.testing import doctestunit, doctest
from zope.component import testing
from Testing import ZopeTestCase
@@ -43,8 +43,9 @@
setUp=setUp, tearDown=testing.tearDown),
doctestunit.DocTestSuite(
- module='five.grok.tests.views',
- setUp=setUp, tearDown=testing.tearDown),
+ module='five.grok.tests.view.view',
+ setUp=setUp, tearDown=testing.tearDown,
+ optionflags=doctest.ELLIPSIS+doctest.NORMALIZE_WHITESPACE)
# Integration tests that use ZopeTestCase
#ztc.ZopeDocFileSuite(
Deleted: five.grok/trunk/src/five/grok/tests/test_secure_views.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/test_secure_views.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/test_secure_views.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,25 +0,0 @@
-import unittest
-from Testing import ZopeTestCase
-from test_all import setUp
-
-from AccessControl import Unauthorized
-from OFS.SimpleItem import SimpleItem
-
-class TestViews(ZopeTestCase.ZopeTestCase):
-
- def afterSetUp(self):
- setUp()
- self.folder._setObject('item', SimpleItem())
- self.folder.item.id = 'item'
-
- def test_views(self):
- self.logout()
- self.assertRaises(Unauthorized, self.folder.item.restrictedTraverse, ('@@aview',))
-
- def test_views(self):
- self.logout()
- self.assertRaises(Unauthorized, self.folder.item.restrictedTraverse, ('@@aview',))
-
-def test_suite():
- return unittest.makeSuite(TestViews)
-
Modified: five.grok/trunk/src/five/grok/tests/utilities.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/utilities.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/utilities.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,5 +1,7 @@
"""Testing that grokcore utilities work under Zope2
+ >>> grok.testing.grok(__name__)
+
>>> from zope import component
>>> club = component.getUtility(IFiveClub, 'five_inch')
>>> IFiveClub.providedBy(club)
Added: five.grok/trunk/src/five/grok/tests/view/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/view/__init__.py (rev 0)
+++ five.grok/trunk/src/five/grok/tests/view/__init__.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -0,0 +1 @@
+# this is a package
Property changes on: five.grok/trunk/src/five/grok/tests/view/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: five.grok/trunk/src/five/grok/tests/view/view.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/view/view.py (rev 0)
+++ five.grok/trunk/src/five/grok/tests/view/view.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -0,0 +1,50 @@
+"""
+
+ >>> grok.testing.grok(__name__)
+
+We should find the ``cavepainting`` view for a mammoth:
+
+ >>> manfred = Mammoth()
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> from zope import component
+ >>> view = component.getMultiAdapter((manfred, request), name='cavepainting')
+ >>> view()
+ 'A cave painting of a mammoth'
+
+ >>> view.context is manfred
+ True
+ >>> view.request is request
+ True
+
+Look up a view with a name explicitly set with ``grok.name``:
+
+ >>> view = component.getMultiAdapter((manfred, request), name='meal')
+ >>> view()
+ 'Mammoth burger'
+
+There's no view 'food':
+
+ >>> view = component.getMultiAdapter((manfred, request), name='food')
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ((<five.grok.tests.view.view.Mammoth object at 0x...>, <zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), <InterfaceClass zope.interface.Interface>, 'food')
+
+"""
+
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class CavePainting(grok.View):
+
+ def render(self):
+ return 'A cave painting of a mammoth'
+
+class Food(grok.View):
+ """Grok says: ME NO SEE MAMMOTH, ME SEE MEAL!"""
+ grok.name('meal')
+
+ def render(self):
+ return 'Mammoth burger'
Property changes on: five.grok/trunk/src/five/grok/tests/view/view.py
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: five.grok/trunk/src/five/grok/tests/views.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/views.py 2008-07-17 11:36:53 UTC (rev 88432)
+++ five.grok/trunk/src/five/grok/tests/views.py 2008-07-17 11:49:10 UTC (rev 88433)
@@ -1,28 +0,0 @@
-"""Testing five.grok Views.
-
- >>> from OFS.SimpleItem import SimpleItem
- >>> item = SimpleItem()
- >>> item.id = 'item'
-
-Setup a fake request:
-
- >>> from zope.publisher.browser import TestRequest
- >>> item.REQUEST = TestRequest()
-
-We should now be able to find the view:
-
- >>> view = item.unrestrictedTraverse('@@aview')
- >>> view()
- 'item'
-
-"""
-from five import grok
-from OFS.interfaces import ISimpleItem
-
-class SimpleItemView(grok.View):
- grok.context(ISimpleItem)
- grok.name('aview')
- grok.require('zope2.ViewManagementScreens')
-
- def __call__(self):
- return self.context.getId()
More information about the Checkins
mailing list