예제 #1
0
    def test_event_created_last_day_of_month_invalidate_cache(self):
        # First render the calendar portlet when there's no events
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()
        html = portlet.render()

        # Now let's add a new event on the first day of the current month
        year, month = portlet.year_month_display()
        day = monthrange(year, month)[1]  # (wkday, days)

        tz = pytz.timezone(TZNAME)
        start = tz.localize(datetime(year, month, day, 23, 0, 0))
        end = tz.localize(datetime(year, month, day, 23, 30, 0))
        # Event starts at 23:00 and ends at 23:30
        createContentInContainer(self.portal,
                                 PTYPE,
                                 title='e1',
                                 start=start,
                                 end=end)

        # Try to render the calendar portlet again, it must be different Now
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()
        self.assertNotEqual(html, portlet.render(),
                            "Cache key wasn't invalidated")
예제 #2
0
    def test_portlet_config(self):
        tz = pytz.timezone(TZNAME)
        start = tz.localize(datetime.now())
        end = start + timedelta(hours=1)

        e1 = createContentInContainer(self.portal,
                                      PTYPE,
                                      title=u'e1',
                                      start=start,
                                      end=end)
        self.portal.invokeFactory('Folder', 'eventfolder')
        createContentInContainer(self.portal.eventfolder,
                                 PTYPE,
                                 title=u'e2',
                                 start=start,
                                 end=end)
        self.portal.portal_workflow.doActionFor(e1, 'publish')

        r = self.renderer(assignment=portlet_calendar.Assignment(
            state=('draft', )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' not in rd and 'e2' not in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(
            state=('published', )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' not in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(state=(
            'published',
            'private',
        )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment())
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' in rd)

        # No search base gives calendar urls with event_listing part
        self.assertTrue('event_listing?mode=day' in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(
            search_base_uid=self.portal.eventfolder.UID()))
        r.update()
        rd = r.render()
        self.assertTrue('e1' not in rd and 'e2' in rd)

        # A given search base gives calendar urls without event_listing part
        self.assertTrue('event_listing?mode=day' not in rd)

        # link to calendar view in rendering
        self.assertTrue('?mode=day&date=' in rd)
예제 #3
0
    def test_portlet_config(self):
        start = DateTime('Europe/Vienna')
        end = DateTime('Europe/Vienna') + 0.1
        self.portal.invokeFactory('Event', 'e1', startDate=start, endDate=end)
        self.portal.invokeFactory('Folder', 'eventfolder')
        # one event in the events folder
        self.portal.eventfolder.invokeFactory('Event',
                                              'e2',
                                              startDate=start,
                                              endDate=end)
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')

        r = self.renderer(assignment=portlet_calendar.Assignment(
            state=('draft', )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' not in rd and 'e2' not in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(
            state=('published', )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' not in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(state=(
            'published',
            'private',
        )))
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment())
        r.update()
        rd = r.render()
        self.assertTrue('e1' in rd and 'e2' in rd)

        # No search base gives calendar urls with event_listing part
        self.assertTrue('event_listing?mode=day' in rd)

        r = self.renderer(assignment=portlet_calendar.Assignment(
            search_base="/eventfolder"))
        r.update()
        rd = r.render()
        self.assertTrue('e1' not in rd and 'e2' in rd)

        # A given search base gives calendar urls without event_listing part
        self.assertTrue('event_listing?mode=day' not in rd)

        # link to calendar view in rendering
        self.assertTrue('?mode=day&date=' in rd)

        self.portal.manage_delObjects(['e1', 'eventfolder'])
예제 #4
0
def convert_legacy_portlets(context):
    """Convert legacy portlets (left_slots, right_slots) in the given
    context to new-style portlets.
    """

    portletsMapping = {
        'portlet_login': login.Assignment(),
        'portlet_news': news.Assignment(count=5),
        'portlet_navigation': navigation.Assignment(),
        'portlet_review': review.Assignment(),
        'portlet_recent': recent.Assignment(count=5),
        'portlet_related': DONT_MIGRATE,
        'portlet_languages': DONT_MIGRATE,
        'portlet_calendar': calendar.Assignment(),
        'portlet_events': events.Assignment(count=5),
    }

    # Convert left_slots and right_slots to portlets

    left = getUtility(IPortletManager, name='plone.leftcolumn')
    right = getUtility(IPortletManager, name='plone.rightcolumn')

    leftAssignable = getMultiAdapter((context, left),
                                     IPortletAssignmentMapping).__of__(context)
    rightAssignable = getMultiAdapter(
        (context, right), IPortletAssignmentMapping).__of__(context)

    IPortletPermissionChecker(leftAssignable)()
    IPortletPermissionChecker(rightAssignable)()

    leftChooser = INameChooser(leftAssignable)
    rightChooser = INameChooser(rightAssignable)

    left_slots = getattr(aq_base(context), 'left_slots', [])
    right_slots = getattr(aq_base(context), 'right_slots', [])

    for item in left_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                leftAssignable[leftChooser.chooseName(None,
                                                      newPortlet)] = newPortlet

    for item in right_slots:
        path = item.split('/')
        if len(path) == 4:
            newPortlet = portletsMapping.get(path[1], None)
            if newPortlet is None and path[0] in (
                    'context', 'here') and path[2] == 'macros':
                newPortlet = classic.Assignment(path[1], path[3])
            if newPortlet is not None and newPortlet is not DONT_MIGRATE:
                rightAssignable[rightChooser.chooseName(
                    None, newPortlet)] = newPortlet

    context.left_slots = []
    context.right_slots = []
예제 #5
0
 def test_event_nonascii(self):
     # test issue with non-ascii event title and location
     title = u'Plön€¢önf München 2012'
     self.portal.invokeFactory('Event', 'e1', title=title,
                               location=u'München')
     portlet = self.renderer(assignment=portlet_calendar.Assignment())
     portlet.update()
     self.assertTrue(title in portlet.render())
예제 #6
0
    def test_prev_next_query(self):
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()

        year, month = portlet.year_month_display()
        prev_expected = '?month={1}&year={0}'.format(
            *portlet.get_previous_month(year, month))
        next_expected = '?month={1}&year={0}'.format(
            *portlet.get_next_month(year, month))
        self.assertEqual(next_expected, portlet.next_query)
        self.assertEqual(prev_expected, portlet.prev_query)
예제 #7
0
    def testRenderer(self):
        context = self.portal
        view = context.restrictedTraverse('@@plone')
        manager = getUtility(IPortletManager,
                             name='plone.rightcolumn',
                             context=self.portal)
        assignment = portlet_calendar.Assignment()

        renderer = getMultiAdapter(
            (context, self.request, view, manager, assignment),
            IPortletRenderer)
        self.failUnless(isinstance(renderer, portlet_calendar.Renderer))
예제 #8
0
    def test_long_event(self):
        start = DateTime('Europe/Vienna')
        end = DateTime('Europe/Vienna') + 2
        self.portal.invokeFactory('Event', 'e1', startDate=start, endDate=end)
        self.portal.portal_workflow.doActionFor(self.portal.e1, 'publish')

        r = self.renderer(assignment=portlet_calendar.Assignment(
            state=('published', )))
        r.update()
        rd = r.render()
        self.assertEqual(rd.count('http://nohost/plone/e1'), 3)
        self.portal.manage_delObjects(['e1'])
예제 #9
0
    def test_event_created_last_day_of_month_invalidate_cache(self):
        # First render the calendar portlet when there's no events
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()
        html = portlet.render()

        # Now let's add a new event on the first day of the current month
        year, month = portlet.year_month_display()
        day = monthrange(year, month)[1]  # (wkday, days)
        last_day_month = DateTime('%s/%s/%s' % (year, month, day))
        hour = 1 / 24.0
        # Event starts at 23:00 and ends at 23:30
        self.portal.invokeFactory('Event', 'e1',
                                  startDate=last_day_month + 23 * hour,
                                  endDate=last_day_month + 23.5 * hour)

        # Try to render the calendar portlet again, it must be different Now
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()
        self.assertNotEqual(
            html, portlet.render(), "Cache key wasn't invalidated"
        )
    def test_event_nonascii(self):
        # test issue with non-ascii event title and location
        title = u'Plön€¢önf München 2012'

        tz = pytz.timezone(TZNAME)
        start = tz.localize(datetime.now())
        end = start + timedelta(hours=1)
        e1 = createContentInContainer(
            self.portal, PTYPE, title=title, start=start, end=end,
            location=u'München')
        self.wft.doActionFor(e1, 'publish')
        portlet = self.renderer(assignment=portlet_calendar.Assignment())
        portlet.update()
        self.assertTrue(title in portlet.render())
예제 #11
0
    def renderer(self,
                 context=None,
                 request=None,
                 view=None,
                 manager=None,
                 assignment=None):
        context = context or self.portal
        request = request or self.request
        view = view or context.restrictedTraverse('@@plone')
        manager = manager or getUtility(
            IPortletManager, name='plone.rightcolumn', context=self.portal)
        assignment = assignment or portlet_calendar.Assignment()

        return getMultiAdapter((context, request, view, manager, assignment),
                               IPortletRenderer)
    def test_long_event(self):
        tz = pytz.timezone(TZNAME)
        start = tz.localize(datetime.now())
        end = start + timedelta(days=2)

        e1 = createContentInContainer(
            self.portal, PTYPE, title='e1', start=start, end=end)
        self.portal.portal_workflow.doActionFor(e1, 'publish')

        r = self.renderer(
            assignment=portlet_calendar.Assignment(state=('published', ))
        )
        r.update()
        rd = r.render()
        self.assertEqual(rd.count('http://nohost/plone/e1'), 3)
예제 #13
0
 def testInterfaces(self):
     portlet = portlet_calendar.Assignment()
     self.failUnless(IPortletAssignment.providedBy(portlet))
     self.failUnless(IPortletDataProvider.providedBy(portlet.data))
예제 #14
0
 def testInterfaces(self):
     portlet = portlet_calendar.Assignment()
     self.assertTrue(IPortletAssignment.providedBy(portlet))
     self.assertTrue(IPortletDataProvider.providedBy(portlet.data))