I figured out how to avoid using TestBrowser. One key step was to shove
the default bugtask into LaunchBag. Then the view for each table row had
to be constructed and rendered separately. Obvious!
>
> The TestBrowser is an indirect means to test rendering. The view does that.
> you can render any view (that had the principal argument passed) by calling
> it; view(). Launchpad views add striping rules so __call__ calls render().
> You can render a view's templates using view() or view.render(). It is much
> faster than TestBrowser.
<new stuff> login_person(bugtask.owner) getUtility(ILaunchBag).add(bug.default_bugtask)
view = create_initialized_view( bug, name='+bugtasks-and-nominations-table', principal=bugtask.owner)
# We render the bug task table rows - there are 2 bug tasks. subviews = view.getBugTaskAndNominationViews() self.assertEqual(2, len(subviews)) default_bugtask_contents = subviews[0]() bugtask_contents = subviews[1]()
</new stuff>
# bugtask can be deleted because the user owns it. delete_icon = find_tag_by_id( bugtask_contents, 'bugtask-delete-task%d' % bugtask.id) delete_url = canonical_url( bugtask, rootsite='bugs', view_name='+delete') self.assertEqual(delete_url, delete_icon['href'])
# default_bugtask cannot be deleted. delete_icon = find_tag_by_id( default_bugtask_contents, 'bugtask-delete-task%d' % bug.default_bugtask.id) self.assertIsNone(delete_icon)
I figured out how to avoid using TestBrowser. One key step was to shove
the default bugtask into LaunchBag. Then the view for each table row had
to be constructed and rendered separately. Obvious!
>
> The TestBrowser is an indirect means to test rendering. The view does that.
> you can render any view (that had the principal argument passed) by calling
> it; view(). Launchpad views add striping rules so __call__ calls render().
> You can render a view's templates using view() or view.render(). It is much
> faster than TestBrowser.
<new stuff>
login_ person( bugtask. owner)
getUtilit y(ILaunchBag) .add(bug. default_ bugtask) initialized_ view(
bug, name='+ bugtasks- and-nominations -table' ,
principal= bugtask. owner)
subviews = view.getBugTask AndNominationVi ews()
self. assertEqual( 2, len(subviews))
default_ bugtask_ contents = subviews[0]()
bugtask_ contents = subviews[1]()
delete_ icon = find_tag_by_id(
bugtask_ contents, 'bugtask- delete- task%d' % bugtask.id)
delete_ url = canonical_url(
bugtask, rootsite='bugs', view_name= '+delete' )
self. assertEqual( delete_ url, delete_ icon['href' ])
delete_ icon = find_tag_by_id(
default_ bugtask_ contents,
'bugtask- delete- task%d' % bug.default_ bugtask. id)
self. assertIsNone( delete_ icon)
view = create_
# We render the bug task table rows - there are 2 bug tasks.
</new stuff>
# bugtask can be deleted because the user owns it.
# default_bugtask cannot be deleted.