Test coverage for vnccollab.theme.portlets.world_clock

vnccollab/      covered 69% (1245 of 4098 uncovered)
    theme/      covered 69% (1245 of 4098 uncovered)
        portlets/      covered 68% (353 of 1108 uncovered)
            world_clock.py      covered 98% (2 of 139 uncovered)

    1: from pytz import timezone
    1: from datetime import datetime
       
    1: from zope.formlib import form
    1: from zope.interface import implements, Interface
    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.portlets.interfaces import IPortletDataProvider
    1: from plone.app.portlets.portlets import base
       
    1: from vnccollab.theme import messageFactory as _
       
       
    2: class IWorldClockPortlet(IPortletDataProvider):
       
    1:     header = schema.TextLine(
    1:         title=_(u"Header"),
    1:         description=_(u"Header of the portlet."),
    1:         required=True,
    1:         default=u'World Clocks')
       
    1:     tz_1 = schema.Choice(
    1:         title=_(u"Clock 1 Timezone"),
    1:         description=u'',
    1:         required=True,
    1:         vocabulary='vnccollab.theme.vocabularies.TimeZonesVocabulary',
    1:         default='Europe/Berlin')
       
    1:     skin_1 = schema.Choice(
    1:        title=_(u"Clock 1 Skin"),
    1:        description=u'',
    1:        required=True,
    1:        values=('chunkySwiss', 'chunkySwissOnBlack', 'swissRail', 'vnc'),
    1:        default='vnc')
       
    1:     radius_1 = schema.Int(
    1:         title=_(u"Clock 1 Radius"),
    1:         description=u'',
    1:         required=True,
    1:         default=35)
       
    1:     no_seconds_1 = schema.Bool(
    1:         title=_(u"Clock 1 Without Seconds"),
    1:         description=_(u"Do not show seconds handle."),
    1:         required=False,
    1:         default=False)
       
    1:     tz_2 = schema.Choice(
    1:         title=_(u"Clock 2 Timezone"),
    1:         description=u'',
    1:         required=False,
    1:         vocabulary='vnccollab.theme.vocabularies.TimeZonesVocabulary',
    1:         default='Europe/Berlin')
       
    1:     skin_2 = schema.Choice(
    1:        title=_(u"Clock 2 Skin"),
    1:        description=u'',
    1:        required=True,
>>>>>> values=('chunkySwiss', 'chunkySwissOnBlack', 'swissRail', 'vnc',
1: 'vncHeaderViewlet'), 1: default='vnc') 1: radius_2 = schema.Int( 1: title=_(u"Clock 2 Radius"), 1: description=u'', 1: required=False, 1: default=35) 1: no_seconds_2 = schema.Bool( 1: title=_(u"Clock 2 Without Seconds"), 1: description=_(u"Do not show seconds handle."), 1: required=False, 1: default=False) 1: tz_3 = schema.Choice( 1: title=_(u"Clock 3 Timezone"), 1: description=u'', 1: required=False, 1: vocabulary='vnccollab.theme.vocabularies.TimeZonesVocabulary', 1: default='Europe/Berlin') 1: skin_3 = schema.Choice( 1: title=_(u"Clock 3 Skin"), 1: description=u'', 1: required=True, 1: values=('chunkySwiss', 'chunkySwissOnBlack', 'swissRail', 'vnc'), 1: default='vnc') 1: radius_3 = schema.Int( 1: title=_(u"Clock 3 Radius"), 1: description=u'', 1: required=False, 1: default=35) 1: no_seconds_3 = schema.Bool( 1: title=_(u"Clock 3 Without Seconds"), 1: description=_(u"Do not show seconds handle."), 1: required=False, 1: default=False) 2: class Assignment(base.Assignment): 1: implements(IWorldClockPortlet) 1: header = u'World Clock' 1: tz_1 = 'Europe/Berlin' 1: skin_1 = 'vnc' 1: radius_1 = 35 1: no_seconds_1 = False 1: tz_2 = 'Europe/Berlin' 1: skin_2 = 'vnc' 1: radius_2 = 35 1: no_seconds_2 = False 1: tz_3 = 'Europe/Berlin' 1: skin_3 = 'vnc' 1: radius_3 = 35 1: no_seconds_3 = False 1: @property def title(self): """Return portlet header""" 2: return self.header 1: def __init__(self, header=_(u"World Clock"), tz_1='Europe/Berlin', 1: skin_1='vnc', radius_1=35, no_seconds_1=False, tz_2='Europe/Berlin', 1: skin_2='vnc', radius_2=35, no_seconds_2=False, tz_3='Europe/Berlin', 1: skin_3='vnc', radius_3=35, no_seconds_3=False): 2: self.header = header 2: self.tz_1 = tz_1 2: self.skin_1 = skin_1 2: self.radius_1 = radius_1 2: self.no_seconds_1 = no_seconds_1 2: self.tz_2 = tz_2 2: self.skin_2 = skin_2 2: self.radius_2 = radius_2 2: self.no_seconds_2 = no_seconds_2 2: self.tz_3 = tz_3 2: self.skin_3 = skin_3 2: self.radius_3 = radius_3 2: self.no_seconds_3 = no_seconds_3 2: class Renderer(base.Renderer): 1: render = ZopeTwoPageTemplateFile('templates/world_clock.pt') 1: def getTimeZoneInfo(self, zone_name): """Return timezone city name and hours offset""" 6: if not zone_name:
>>>>>> return None
6: offset = datetime.now(timezone(zone_name)).utcoffset() 6: hours = offset.seconds / 3600.0 # if time delta is negative, then subtract 24 hours 6: if offset.days < 0: 1: hours = hours - 24.0 6: return {'hours': '%.1f' % round(hours, 1), 6: 'city': zone_name.split('/')[-1].replace('_', ' ')} 2: class AddForm(base.AddForm): 1: form_fields = form.Fields(IWorldClockPortlet) 1: label = _(u"Add World Clock portlet") 1: description = _(u"A portlet displaying analog world clocks.") 1: def create(self, data): 1: return Assignment(**data) 2: class EditForm(base.EditForm): 1: form_fields = form.Fields(IWorldClockPortlet) 1: label = _(u"Edit World Clock portlet") 1: description = _(u"A portlet displaying analog world clocks.")