Test coverage for vnccollab.theme.portlets.zimbra_mail

vnccollab/      covered 69% (1245 of 4098 uncovered)
    theme/      covered 69% (1245 of 4098 uncovered)
        portlets/      covered 68% (353 of 1108 uncovered)
            zimbra_mail.py      covered 78% (25 of 116 uncovered)

    1: import sys
    1: import logging
       
    1: from zope.formlib import form
    1: from zope.interface import implements
    1: from zope import schema
       
    1: from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
    1: from Products.CMFCore.utils import getToolByName
    1: from Products.CMFPlone.utils import safe_unicode
       
    1: from plone.memoize.instance import memoize
    1: from plone.portlets.interfaces import IPortletDataProvider
    1: from plone.app.portlets.portlets import base
       
    1: from vnccollab.theme import messageFactory as _
       
       
    1: MYLOGGER = logging.getLogger('vnccollab.theme.ZimbraMailPortlet')
       
       
    1: def logException(msg, context=None, logger=MYLOGGER):
>>>>>> logger.exception(msg)
>>>>>> if context is not None:
>>>>>> error_log = getattr(context, 'error_log', None)
>>>>>> if error_log is not None:
>>>>>> error_log.raising(sys.exc_info())
2: class IZimbraMailPortlet(IPortletDataProvider): 1: header = schema.TextLine( 1: title=_(u"Header"), 1: description=_(u"Header of the portlet."), 1: required=True, 1: default=u'Zimbra Mail') 1: url = schema.URI( 1: title=_(u"Zimbra service URL"), 1: description=_(u"Root url to your Zimbra service."), 1: required=True, 1: default='https://zcs.vnc.biz') 1: folder_id = schema.ASCIILine( 1: title=_(u"Mail Folder Id"), 1: description=_(u"The name of the mail folder to access. This can be a " "default or a user-defined folder. Default folders " "include: inbox, drafts, sent, trash, junk."), 1: required=True, 1: default='inbox') 1: count = schema.Int( 1: title=_(u"Number of items to display"), 1: description=_(u"How many items to list."), 1: required=True, 1: default=5) 1: username = schema.ASCIILine( 1: title=_(u"Username"), 1: description=_(u"If not set, zimbra_username property of authenticated " "user will be used."), 1: required=False, 1: default='') 1: password = schema.Password( 1: title=_(u"Password"), 1: description=_(u"If not set, zimbra_password property of authenticated " "user will be used."), 1: required=False, 1: default=u'') 1: timeout = schema.Int( 1: title=_(u"Data reload timeout"), 1: description=_(u"Time in minutes after which the data should be reloaded" " from Zimbra service. Minimun value: 1 minute."), 1: required=True, 1: default=5, 1: min=1) 1: request_timeout = schema.Int( 1: title=_(u"Request timeout"), 1: description=_(u"How many seconds to wait for hanging Zimbra request."), 1: required=True, 1: default=15) 1: failure_delay = schema.Int( 1: title=_(u"Failure delay"), 1: description=_(u"Time in minutes before retry to load data from Zimbra " "after a failure"), 1: required=True, 1: default=5) 2: class Assignment(base.Assignment): 1: implements(IZimbraMailPortlet) 1: header = u'Zimbra Mail' 1: protocol = 'https://' 1: url = 'https://zcs.vnc.biz' 1: folder_id = 'inbox' 1: count = 5 1: username = '' 1: password = u'' 1: timeout = 5 1: request_timeout = 15 1: failure_delay = 5 1: @property def title(self): """Return portlet header"""
>>>>>> return self.header
1: def __init__(self, header=u'', url='https://zcs.vnc.biz', 1: folder_id='inbox', count=5, username='', password=u'', 1: timeout=5, request_timeout=15, failure_delay=5):
>>>>>> self.header = header
>>>>>> self.url = url
>>>>>> self.folder_id = folder_id
>>>>>> self.count = count
>>>>>> self.username = username
>>>>>> self.password = password
>>>>>> self.timeout = timeout
>>>>>> self.request_timeout = request_timeout
>>>>>> self.failure_delay = failure_delay
2: class Renderer(base.Renderer): 1: render = ZopeTwoPageTemplateFile('templates/zimbra_mail.pt') 1: def update(self):
>>>>>> pass
1: @memoize def getAuthCredentials(self): """Returns username and password for zimbra user."""
>>>>>> username, password = self.data.username, self.data.password
>>>>>> if not (username and password):
# take username and password from authenticated user Zimbra creds
>>>>>> mtool = getToolByName(self.context, 'portal_membership')
>>>>>> member = mtool.getAuthenticatedMember()
>>>>>> username, password = member.getProperty('zimbra_username', ''), \
>>>>>> member.getProperty('zimbra_password', '')
# password could contain non-ascii chars, ensure it's properly encoded
>>>>>> return username, safe_unicode(password).encode('utf-8')
1: @property def title(self): """return title of feed for portlet"""
>>>>>> return self.data.header
2: class AddForm(base.AddForm): 1: form_fields = form.Fields(IZimbraMailPortlet) 1: label = _(u"Add Zimbra Mail Portlet") 1: description = _(u"This portlet allows managing Zimbra Mail box.") 1: def create(self, data):
>>>>>> return Assignment(**data)
2: class EditForm(base.EditForm): 1: form_fields = form.Fields(IZimbraMailPortlet) 1: label = _(u"Edit Zimbra Mail Portlet") 1: description = _(u"This portlet allows managing Zimbra Mail box.")