[Grok-dev] How does one unittest a view?

Uli Fouquet uli at gnufix.de
Wed Apr 8 10:07:09 EDT 2009

Hi there,

Wichert Akkerman wrote:
> How can you unittest a view? Trying to instantiate a view in a testcase
> fails when the constructor tries to access self.__view_name__ and
> self.module_info. 

Maybe something like this?

:test-layer: unit

    >>> import grok
    >>> grok.testing.grok('sample')
    >>> from zope.component import getMultiAdapter
    >>> from zope.publisher.browser import TestRequest
    >>> from sample.app import Sample
    >>> app = Sample()
    >>> request = TestRequest()
    >>> view = getMultiAdapter((app, request), name='index')
    >>> print view()
      <p>Your Grok application is up and running.
      Edit <code>sample/app_templates/index.pt</code> to change
      this page.</p>

Best regards,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090408/38262323/attachment.bin 

More information about the Grok-dev mailing list