[Zope3-Users] Re: Writing tests for views
darryl at darrylcousins.net.nz
Sat Sep 23 19:50:15 EDT 2006
On Sun, 2006-09-24 at 01:37 +0200, Philipp von Weitershausen wrote:
> George Lee wrote:
> > I am trying to write a test for a view, and making sure that an object I've
> > created is associated with the correct view. But either of these lines fails
> > with a ComponentLookupError "Couldn't find view":
> > view = getView(self.event1, 'daterange_display', self.request)
> > view = getViewProviding(self.event1, IDateRangeDisplay, self.request)
> Use getMultiAdapter. These things are deprecated.
Which would look something like this:
>>> view = zapi.getMultiAdapter((self.event1, self.request), name="daterange_display")
To register the view in python for a non-functional doctest something
like this would work (maybe someone can correct me, because I've got
IBrowserRequest twice in there but it does work):
>>> component.provideAdapter(YourViewClass, [IYourInterface, IBrowserRequest], \
... IBrowserRequest, name='daterange_display')
> > even though in a page template that I view through the web,
> > context/@@daterange_display
> > retrieves the correct view. What am I doing incorrectly?
> Well, is the test a functional test? Only functional tests have all the
> configuration loaded. Otherwise you'll have to register the view first
> before you can test its lookup.
> By the way, testing views is best done with zope.testbrowser these days.
Yes. But all the same I do use a quick doctest to check that the view
class behaves as expected before going on to testbrowser functional
tests (which take longer to run). I save a bit of time then catching
silly import and syntax errors and tuning the view class.
> > Thanks -- I know I've asked a flood of questions today!
> Consider buying my book: http://worldcookery.com
> Also consider reading the docs that are there. Zope 3 has lots of docs
> (see http://localhost:8080/++apidoc++ after enabling devmode). There are
> also a couple of tutorials available at http://worldcookery.com/Appetizers.
> Zope3-users mailing list
> Zope3-users at zope.org
More information about the Zope3-users