Test coverage for vnccollab.theme.portlets.zimbra_calendar

vnccollab/      covered 69% (1245 of 4098 uncovered)
    theme/      covered 69% (1245 of 4098 uncovered)
        portlets/      covered 68% (353 of 1108 uncovered)
            zimbra_calendar.py      covered 76% (24 of 101 uncovered)

    1: from zope import schema
    1: from zope.formlib import form
    1: from zope.interface import implements
       
    1: from Products.CMFCore.utils import getToolByName
    1: from Products.CMFPlone.utils import safe_unicode
    1: from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
       
    1: from plone.portlets.interfaces import IPortletDataProvider
    1: from plone.app.portlets.portlets import base
       
    1: from vnccollab.theme import messageFactory as _
       
       
    2: class IZimbraCalendarPortlet(IPortletDataProvider):
       
    1:     header = schema.TextLine(
    1:         title=_(u"Header"),
    1:         description=_(u"Header of the portlet."),
    1:         required=True,
    1:         default=u'Zimbra Calendar')
       
    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:     mail_domain = schema.TextLine(
    1:         title=_(u"Domain of the mail account"),
    1:         description=_(u"The part after the '@'."),
    1:         required=True,
    1:         default=u'vnc.biz')
       
    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:     calendar_name = schema.TextLine(
    1:         title=_(u"Name of The Calendar"),
    1:         description=_(u"Which calendar should be displayed."),
    1:         required=True,
    1:         default=u'Calendar')
       
    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(IZimbraCalendarPortlet)
       
    1:     @property
           def title(self):
               """Return portlet header"""
>>>>>> return self.header
1: def __init__(self, header=u'', url=u'https://zcs.vnc.biz', 1: mail_domain=u'vnc.biz', 1: username=u'', password=u'', calendar_name=u'', 1: timeout=5, request_timeout=15, failure_delay=5):
>>>>>> self.header = header
>>>>>> self.url = url
>>>>>> self.mail_domain = mail_domain
>>>>>> self.username = username
>>>>>> self.password = password
>>>>>> self.calendar_name = calendar_name
>>>>>> self.timeout = timeout
>>>>>> self.request_timeout = request_timeout
>>>>>> self.failure_delay = failure_delay
2: class AddForm(base.AddForm): 1: form_fields = form.Fields(IZimbraCalendarPortlet) 1: label = _(u"Add Zimbra Calendar Portlet") 1: description = _(u"This portlet allows managing Zimbra Calendar.") 1: def create(self, data):
>>>>>> return Assignment(**data)
2: class EditForm(base.EditForm): 1: form_fields = form.Fields(IZimbraCalendarPortlet) 1: label = _(u"Edit Zimbra Calendar Portlet") 1: description = _(u"This portlet allows managing Zimbra Calendar.") 2: class Renderer(base.Renderer): 1: render = ZopeTwoPageTemplateFile('templates/zimbra_calendar.pt') 1: 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
1: @property def src(self): '''Returs the url of the zimbra calendar'''
>>>>>> username, password = self.getAuthCredentials()
>>>>>> src = '%s/service/home/%s@%s/%s.html' % (
>>>>>> self.data.url, username, self.data.mail_domain,
>>>>>> self.data.calendar_name)
>>>>>> return src