Plone Quick Upload Portlet
==========================

    >>> from zope.component import getMultiAdapter
    >>> from zope.component import getUtility
    >>> from plone.portlets.interfaces import IPortletType
    >>> from plone.portlets.interfaces import IPortletManager
    >>> from plone.portlets.interfaces import IPortletAssignment
    >>> from plone.portlets.interfaces import IPortletDataProvider
    >>> from plone.portlets.interfaces import IPortletRenderer
    >>> from plone.app.portlets.storage import PortletAssignmentMapping
    >>> from plone.app.testing import login
    >>> from plone.app.testing import setRoles
    >>> from plone.app.testing import TEST_USER_ID
    >>> from plone.app.testing import TEST_USER_NAME
    >>> from collective.quickupload.portlet import quickuploadportlet
    >>> portal = layer['portal']
    >>> folder = portal['test-folder']
    >>> setRoles(portal, TEST_USER_ID, ['Manager'])
    >>> login(portal, TEST_USER_NAME)

Test if portlet is registered
-----------------------------

    >>> qu_portlet = getUtility(IPortletType, name='collective.quickupload.QuickUploadPortlet')
    >>> qu_portlet.addview
    'collective.quickupload.QuickUploadPortlet'

Test portlet interface
----------------------

    >>> qu_portlet = quickuploadportlet.Assignment()
    >>> IPortletAssignment.providedBy(qu_portlet)
    True

# This failes when running whole tests.
    # >>> IPortletDataProvider.providedBy(qu_portlet.data)
    # True

Test portlet Add View
---------------------

    >>> qu_portlet = getUtility(IPortletType, name='collective.quickupload.QuickUploadPortlet')
    >>> mapping = portal.restrictedTraverse('++contextportlets++plone.rightcolumn')
    >>> for m in mapping.keys():
    ...     del mapping[m]
    >>> addview = mapping.restrictedTraverse('+/collective.quickupload.QuickUploadPortlet')
    >>> addview.createAndAdd(data={'header':u'', 'upload_portal_type': u'', 'upload_media_type': u''})
    >>> len(mapping)
    1
    >>> isinstance(mapping.values()[0], quickuploadportlet.Assignment)
    True

Test portlet Edit View
----------------------

    >>> mapping = PortletAssignmentMapping()
    >>> request = folder.REQUEST
    >>> mapping['foo'] = quickuploadportlet.Assignment(header=u"", upload_portal_type=u"Image", upload_media_type=u"image")
    >>> editview = getMultiAdapter((mapping['foo'], request), name='edit')
    >>> isinstance(editview, quickuploadportlet.EditForm)
    True

Test portlet Rendering
----------------------

    >>> request = folder.REQUEST
    >>> view = folder.restrictedTraverse('@@folder_contents')
    >>> manager = getUtility(IPortletManager, name='plone.rightcolumn', context=portal)
    >>> assignment = quickuploadportlet.Assignment(header=u"", upload_portal_type=u"Image", upload_media_type=u"image")
    >>> renderer = getMultiAdapter((folder, request, view, manager, assignment), IPortletRenderer)
    >>> isinstance(renderer, quickuploadportlet.Renderer)
    True
    >>> renderer.available
    True

Test portlet Template
---------------------

    >>> def renderer(context=None, request=None, view=None, manager=None, assignment=None):
    ...     context = context or folder
    ...     request = request or folder.REQUEST
    ...     view = view or folder.restrictedTraverse('@@folder_contents')
    ...     manager = manager or getUtility(IPortletManager, name='plone.rightcolumn', context=portal)
    ...     assignment = assignment or quickuploadportlet.Assignment(header=u"", upload_portal_type=u"", upload_media_type=u"")
    ...     return getMultiAdapter((context, request, view, manager, assignment), IPortletRenderer)

Test the Title when header is empty but not the mediatype (must use the mediatype 'image' in this case)
    >>> r = renderer(context=portal, assignment=quickuploadportlet.Assignment(header=u"", upload_portal_type=u"", upload_media_type=u"image"))
    >>> r = r.__of__(folder)
    >>> r.update()
    >>> output = r.render()
    >>> '<span>Images Quick Upload</span>' in output
    True

Test the Title when header is not empty (title must use the header in this case)
    >>> r = renderer(context=portal, assignment=quickuploadportlet.Assignment(header=u"Upload Strange Files", upload_portal_type=u"", upload_media_type=u"flash"))
    >>> r = r.__of__(folder)
    >>> r.update()
    >>> output = r.render()
    >>> '<span>Upload Strange Files</span>' in output
    True

Test the Title when everything is empty (default header must be used)
    >>> r = renderer(context=portal, assignment=quickuploadportlet.Assignment(header=u"", upload_portal_type=u"", upload_media_type=u""))
    >>> r = r.__of__(folder)
    >>> r.update()
    >>> output = r.render()
    >>> '<span>Files Quick Upload</span>' in output
    True

Test Upload url and upload params
    >>> r = renderer(context=folder, assignment=quickuploadportlet.Assignment(header=u"", upload_portal_type=u"Image", upload_media_type=u"image"))
    >>> r = r.__of__(folder)
    >>> r.update()
    >>> output = r.render()
    >>> '%s/@@quick_upload' %folder.absolute_url() in output
    True
    >>> 'typeupload=Image&amp;mediaupload=image' in output
    True
