Test portlets
=============

We want to test some portlets.  We need some test requests for that.
A request needs to be annotatable as we use memoize.

    >>> from zope.publisher.browser import TestRequest
    >>> from zope.annotation.interfaces import IAttributeAnnotatable
    >>> from zope.interface import classImplements
    >>> classImplements(TestRequest, IAttributeAnnotatable)

Currently there is one Project, but we do not have any tasks assigned
to us there.  Since there is only one project, we simply show that one
and do not bother with filtering.

    >>> from urllib import unquote
    >>> def physicalPathFromURL(self, URL):
    ...     # Simplified version of ZPublisher.HTTPRequest.py
    ...     path = filter(None, URL.split( '/'))
    ...     if URL.find( '://') >= 0:
    ...         path = path[2:]
    ...     return map(unquote, path)
    >>> TestRequest.physicalPathFromURL = physicalPathFromURL
    >>> len(self.catalog(portal_type='Project'))
    1
    >>> len(self.catalog(portal_type='Task'))
    1
    >>> from Products.eXtremeManagement.browser.projects import MyProjects
    >>> myprojects = MyProjects(self.portal, TestRequest())
    >>> myprojects.projectlist
    [<Products.ZCatalog.Catalog.mybrains object at ...>]

We add another Project so we have to do some filtering.

    >>> self.setRoles(['Manager'])
    >>> dummy = self.portal.invokeFactory('Project', 'my-project')
    >>> self.setRoles(['Employee'])
    >>> myprojects = MyProjects(self.portal, TestRequest())
    >>> myprojects.projectlist
    []

Now we add ourselves and another employee to the assignees of a task
in one of the projects.  Now the portlet should return a result.

    >>> self.task.setAssignees(('employee', self.default_user,))
    >>> self.task.reindexObject()
    >>> myprojects = MyProjects(self.portal, TestRequest())
    >>> myprojects.projectlist
    [<Products.ZCatalog.Catalog.mybrains object at ...>]

