Beispiel #1
0
def GenerateMailMessage(view, tzinfo=None):
    global M_FROM
    message = Mail.MailMessage(itsView=view)
    body = M_TEXT

    outbound = random.randint(0, 1)
    type = random.randint(1, 8)
    numTo = random.randint(1, 3)

    if M_FROM is None:
        M_FROM = GenerateCalendarParticipant(view)

    message.fromAddress = M_FROM

    for num in range(numTo):
        message.toAddress.append(GenerateCalendarParticipant(view))

    message.subject = random.choice(TITLES)

    if TEST_I18N:
        message.subject = uw(message.subject)

    message.dateSent = datetime.now(tzinfo)

    if outbound:
        message.outgoingMessage()
        message.itsItem.changeEditState(Modification.sent, who=M_FROM)

    else:
        message.incomingMessage()

    if type == EVENT:
        Calendar.EventStamp(message).add()
        body += M_EVENT

    if type == TASK:
        pim.TaskStamp(message).add()
        body += M_TASK

    if type == BOTH:
        Calendar.EventStamp(message).add()
        pim.TaskStamp(message).add()
        body += M_BOTH

    if TEST_I18N:
        body = uw(body)

    message.body = body
    message.itsItem.setTriageStatus(randomEnum(pim.TriageEnum))

    return message.itsItem
    def setFreeBusy(self):

        if self._recalcCount == 0:
            zerotime = time(tzinfo=self.blockItem.itsView.tzinfo.default)
            start = self.GetStartDate()
            start = datetime.combine(start, zerotime)

            # ugh, why can't timedelta just support months?
            end = minical.MonthDelta(start, 3)
            end = datetime.combine(end, zerotime)

            if self.HasPendingEventChanges():
                addedItems, removedItems, changedItems = \
                           self.GetPendingChanges(False)

                if len(removedItems) + len(changedItems) > 0:
                    self._recalcCount += 1
                    self._eventsToAdd.clear()
                else:
                    for item in addedItems:
                        if not isDead(item):
                            if (not has_stamp(item, EventStamp)):
                                continue
                            event = Calendar.EventStamp(item)
                            if event.rruleset is not None:
                                # new recurring events should
                                self._recalcCount += 1
                                self._eventsToAdd.clear()
                                break
                            elif (event.isBetween(start, end)
                                  and event.transparency == 'confirmed'):
                                self._eventsToAdd.add(event)

            else:
                self._eventsToAdd.clear()

        if self._eventsToAdd:
            self._recalcCount += 1

        if self._recalcCount or self._eventsToAdd:
            self.Refresh()
    def testCalendar(self):
        """ Simple test for creating instances of calendar related kinds """
        def getEventValue(event, attrName):
            try:
                attrName = getattr(type(event), attrName).name
            except AttributeError:
                pass
            return getattr(event.itsItem, attrName)

        def _verifyCalendarEvent(event):
            self.failUnless(stamping.has_stamp(event, Calendar.EventStamp))

            self.assertEqual(event.summary, uw("simple headline"))

            self.assertEqual(event.itsItem.importance, 'fyi')
            self.assertEqual(getEventValue(event, 'importance'), 'fyi')

            self.assertEqual(event.transparency, "confirmed")
            self.assertEqual(getEventValue(event, 'transparency'), "confirmed")

            self.assertEqual(event.allDay, False)
            self.assertEqual(getEventValue(event, 'allDay'), False)

            self.assertEqual(event.anyTime, True)
            self.assertEqual(getEventValue(event, 'anyTime'), True)

        def _verifyCalendarItems(location, recurrence):
            self.assertEqual(location.displayName, uw("simple location"))

        # Check that the globals got created by the parcel
        calendarPath = Path('//parcels/osaf/pim/calendar')
        view = self.sandbox.itsView

        self.assertEqual(schema.itemFor(Calendar.EventStamp, view),
                         view.find(Path(calendarPath, 'EventStamp')))
        self.assertEqual(Calendar.Location.getKind(view),
                         view.find(Path(calendarPath, 'Location')))
        self.assertEqual(Calendar.RecurrencePattern.getKind(view),
                         view.find(Path(calendarPath, 'RecurrencePattern')))

        # Construct a sample item
        calendarEventItem = Calendar.CalendarEvent("calendarEventItem",
                                                   itsParent=self.sandbox)
        locationItem = Calendar.Location("locationItem",
                                         itsParent=self.sandbox)
        recurrenceItem = Calendar.RecurrencePattern("recurrenceItem",
                                                    itsParent=self.sandbox)

        # CalendarEvent properties
        calendarEventItem.summary = uw("simple headline")
        calendarEventItem.itsItem.importance = "fyi"
        _verifyCalendarEvent(calendarEventItem)
        calendarEventItem.location = locationItem

        # Calendar properties
        locationItem.displayName = uw("simple location")
        _verifyCalendarItems(locationItem, recurrenceItem)

        # Check cloud membership - event + location
        items = calendarEventItem.itsItem.getItemCloud('copying')
        self.assertEqual(len(items), 2)

        # Re-examine items
        self.reopenRepository()
        view = self.sandbox.itsView

        calendarEventItem = Calendar.EventStamp(
            self.sandbox.getItemChild("calendarEventItem"))
        locationItem = self.sandbox.getItemChild("locationItem")
        recurrenceItem = self.sandbox.getItemChild("recurrenceItem")

        _verifyCalendarEvent(calendarEventItem)
        _verifyCalendarItems(locationItem, recurrenceItem)