def afterSetUp(self): self.eventSetUp() self.loginAsPortalOwner() self.folder.invokeFactory('Topic', id='calendar-topic') self.topic = self.folder['calendar-topic'] criteria = self.topic.addCriterion('portal_type', 'ATPortalTypeCriterion') criteria.value = (u'Event', ) self.provider = IEventProvider(self.topic)
def exportCalendar(self, REQUEST=None): """ Export the contents of this Calendar as an iCalendar file """ if not self.has_ical_support(): return '' ct = getToolByName(self, 'portal_calendar') eventprovider = IEventProvider(self.context) events = [x.context.getObject() for x in eventprovider.all_events()] self.request.RESPONSE.setHeader( 'Content-Type', 'text/calendar;charset=utf-8') return ct.exportCalendar(events=events, REQUEST=REQUEST)
class TopicEventProviderTest(ATEventProviderTest): def afterSetUp(self): self.eventSetUp() self.loginAsPortalOwner() self.folder.invokeFactory('Topic', id='calendar-topic') self.topic = self.folder['calendar-topic'] criteria = self.topic.addCriterion('portal_type', 'ATPortalTypeCriterion') criteria.value = (u'Event', ) self.provider = IEventProvider(self.topic) def test_createlink(self): link = self.provider.event_creation_link() self.failUnlessEqual(link, "") def test_gather_events(self): # Make sure that restrictions made by the context topic and # our own query don't clash, see # http://plone4artists.org/products/plone4artistscalendar/issues/35 # First off, we're going to set a date restriction so that # only events in the future are shown: date_crit = self.topic.addCriterion('start', 'ATFriendlyDateCriteria') date_crit.setValue(0) date_crit.setDateRange('+') date_crit.setOperation('more') calls = [] def my_catalog(request, **kwargs): calls.append(kwargs) return LazyCat([]) self.folder.portal_catalog = my_catalog self.folder.portal_catalog.searchResults = my_catalog # Now let's make sure that a call to the catalog is done with # the correct set of arguments, and that the criteria defined # in the topic didn't interfere: self.provider.gather_events(start=datetime(1980, 10, 13), stop=datetime(1980, 10, 20)) self.assertEqual(len(calls), 1) # We don't mind the timezone at this point: self.assertEqual(str(calls[0]['end']['query']), str(DateTime('1980/10/13'))) self.assertEqual(str(calls[0]['start']['query']), str(DateTime('1980/10/20')))
class ATEventProviderTest(CalendarTestCase, EventProviderTestMixin): def eventSetUp(self): # Create folder. self.folder.invokeFactory('Folder', id='calendar-folder') cal = self.folder['calendar-folder'] id = cal.invokeFactory('Event', id='event1') cal['event1'].update(title='First Event', startDate=DateTime('2006-09-28 08:30am GMT+0'), endDate=DateTime('2006-09-28 09:30am GMT+0')) id = cal.invokeFactory('Event', id='event2') cal['event2'].update(title='Second Event', startDate=DateTime('2006-09-29 08:30am GMT+0'), endDate=DateTime('2006-09-29 09:30am GMT+0')) id = cal.invokeFactory('Event', id='meeting1') # Calling this event "Meeting" is just to have one event that does # not have the word "Event" in the title. cal['meeting1'].update(title='First Meeting', startDate=DateTime('2006-09-30 08:30am GMT+0'), endDate=DateTime('2006-09-30 09:30am GMT+0')) # Activate calendaring capabilities on this folder config = ICalendarConfig(cal) config.calendar_activated = True def afterSetUp(self): self.eventSetUp() self.provider = IEventProvider(self.folder['calendar-folder']) def test_createlink(self): link = self.provider.event_creation_link() self.failUnlessEqual( link, "http://nohost/plone/Members/test_user_1_/calendar-folder/createObject?type_name=Event" )
def afterSetUp(self): self.eventSetUp() self.provider = IEventProvider(self.folder['calendar-folder'])