[Grok-dev] How does one unittest a view?
Uli Fouquet
uli at gnufix.de
Wed Apr 8 12:35:29 EDT 2009
Hi there,
Jan-Wijbrand Kolman wrote:
> Wichert Akkerman wrote:
> > Previously Jan-Wijbrand Kolman wrote:
> >> I wonder how this would work in a vanilla Zope 3 context though...
> >
> > One uses zope.component.testing.PlacelessSetup and manually calls
> > provideAdapter & friends when needed.
the latter is painless with Grok IMHO, where a single call to
grok.testing.grok is enough. For simple tests without any ZCA, however,
we seem indeed to have a problem here.
> Hmm, right.
>
> Then this seems to be a problematic area for right now in that sense, as
> the grokking process (at least in this case, for View components) mixes
> performing CA registrations and "setting up things on the View component
> itself".
>
> Not sure how to decouple things. Maybe by splitting the View grokker
> into two; one for registrations part and one for the "setting up
> things"-part and somehow have a way to invoke only one when unittesting.
> Hand-waving here obviously.
That would mean that you had to grok also in simple cases like Wicherts,
right? You would only use a different Grokker. I think this problem is
more specific to the View class than to the Grokkers: it does not work
at all if it was not grokked before. Instead it expects some attributes
to be present, which are not defined in the class.
What about simply providing some braindead (or smart) class attributes
such getting default values? Or setting the `__name__` and `static`
attribute conditionally/using useless values? You couldn't use framework
related functionality like myviewinstance.url(), __call__, etc. then
(which also wouldn't make much sense) but you could at least create view
instances and test their 'simple' functionality. Not sure whether this
would impact other behaviours like the grokking-process, though.
Best regards,
--
Uli
-------------- 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/3b3c4da4/attachment.bin
More information about the Grok-dev
mailing list