Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ocigo (26-Jun @ 01:11)

Syntax Highlighted Code

  1. Do a simple doctest test on the app.
  2. ************************************
  3. :Test-Layer: functional
  4.  
  5.    >>> import grok
  6.    >>> from zope.component import getMultiAdapter
  7.    >>> from zope import schema
  8.    >>> from pymenthon.forms.components import AddForm
  9.    >>> from zope.interface import Interface
  10.    >>> from zope.publisher.browser import TestRequest
  11.    >>> class IPerson(Interface):
  12.    ...    firstname = schema.TextLine(title=u'Firstname')
  13.    ...    lastname = schema.TextLine(title=u'Lastname')
  14.    ...
  15.    >>> class People(grok.Application, grok.Container):
  16.    ...    pass
  17.    ...
  18.  
  19. Now we can create a JSON View
  20.  
  21.    >>> class PersonJSON(grok.JSON):
  22.    ...    grok.context(People)
  23.    ...
  24.    ...    def hello(self):
  25.    ...        return {'hi':'there'}
  26.    ...
  27.  
  28. Finally, let's get the view
  29.  
  30.   >>> persons = People()
  31.   >>> request = TestRequest()
  32.   >>> form = getMultiAdapter((persons, request), name="hello")
  33.  

Plain Code

Do a simple doctest test on the app.
************************************
:Test-Layer: functional

   >>> import grok
   >>> from zope.component import getMultiAdapter
   >>> from zope import schema
   >>> from pymenthon.forms.components import AddForm
   >>> from zope.interface import Interface
   >>> from zope.publisher.browser import TestRequest
   >>> class IPerson(Interface):
   ...    firstname = schema.TextLine(title=u'Firstname')
   ...    lastname = schema.TextLine(title=u'Lastname')
   ...
   >>> class People(grok.Application, grok.Container):
   ...    pass
   ...

Now we can create a JSON View

   >>> class PersonJSON(grok.JSON):
   ...    grok.context(People)
   ...
   ...    def hello(self):
   ...        return {'hi':'there'}
   ...

Finally, let's get the view

   >>> persons = People()
   >>> request = TestRequest()
   >>> form = getMultiAdapter((persons, request), name="hello")

Permalink: http://codedumper.com/ocigo