def testChangeNonOverlapping_THIS_ALL(self):
        # Make a THIS change to one occurrence, followed by an ALL
        # change of a different attribute to a different occurrence, and make
        # sure the lastModified is updated accordingly.
        self.event.rruleset = self.rruleset

        second = self.event.getFirstOccurrence().getNextOccurrence()
        third = second.getNextOccurrence()

        # THIS change to summary (a.k.a. displayName) ...
        pim.CHANGE_THIS(third).summary = u'This has been changed'
        # Make sure the lastModified changed for this event (third) ...
        self.failUnless(third.itsItem.lastModified > self.start)
        # ... but not for second, a different event in the series
        self.failUnlessEqual(second.itsItem.lastModified, self.start)

        # Now make an ALL change on duration
        pim.CHANGE_ALL(second).duration = datetime.timedelta(hours=4)

        # self.event (the master) should have a changed lastModified
        self.failIfEqual(self.event.itsItem.lastModified, self.start)
        # ... which is the same as for second
        self.failUnlessEqual(self.event.itsItem.lastModified,
                             second.itsItem.lastModified)
        # third was altered by the last change, so its
        # lastModified should be changed, too.
        self.failUnlessEqual(self.event.itsItem.lastModified,
                             third.itsItem.lastModified)
    def testChange_THIS(self):
        self.event.rruleset = self.rruleset

        second = self.event.getFirstOccurrence().getNextOccurrence()

        pim.CHANGE_THIS(second).summary = u'I am so special'
        self.failUnlessEqual(self.event.itsItem.lastModified, self.start)
        self.failUnless(second.itsItem.lastModified > self.start)
    def advanceState(self, item, attributeName):
        item = pim.CHANGE_THIS(item)
        # If there is one, remove the existing reminder
        if item.getUserReminder(expiredToo=False) is not None:
            item.userReminderTime = None
            return

        # No existing one -- create one.
        item.userReminderTime = pim.Reminder.defaultTime(item.itsView)
    def test_THIS(self):
        self.event.rruleset = self.rruleset
        third = self.event.getFirstOccurrence().getNextOccurrence(
        ).getNextOccurrence()

        pim.CHANGE_THIS(third).allDay = True

        self.failUnless(third.modificationFor is not None)
        self.failUnless(third.allDay)
        self.failIf(self.event.allDay)
    def testStamp_THIS(self):
        self.event.rruleset = self.rruleset
        third = self.event.getFirstOccurrence().getNextOccurrence(
        ).getNextOccurrence()

        pim.TaskStamp(pim.CHANGE_THIS(third)).add()

        self.failUnless(third.modificationFor is not None)
        self.failUnless(pim.has_stamp(third, pim.TaskStamp))
        self.failIf(pim.has_stamp(self.event, pim.TaskStamp))
        self.failIf(
            pim.has_stamp(self.event.getFirstOccurrence(), pim.TaskStamp))
    def testAdd_ALL(self):
        self.event.itsItem.collections = [self.one]
        self.event.rruleset = self.rruleset

        second = self.event.getFirstOccurrence().getNextOccurrence()
        pim.CHANGE_THIS(second).summary = u'New'
        secondProxy = pim.CHANGE_ALL(second)
        secondProxy.itsItem.collections.add(self.two)

        self.failUnless(self.event.itsItem in self.two)
        self.failUnless(self.event.modifications,
                        "No auto-generated occurrences?")
        for modItem in self.event.modifications:
            self.failUnless(modItem in self.two)
    def testAdd_THIS(self):
        # Adding just a THIS mod to a collection is disabled for now
        # (fails with an assertion).
        self.event.itsItem.collections = [self.one]
        self.event.rruleset = self.rruleset
        second = self.event.getFirstOccurrence().getNextOccurrence()
        proxiedSecond = pim.CHANGE_THIS(second)

        proxiedSecond.itsItem.collections.add(self.two)

        self.failUnless(second.itsItem in self.two)
        self.failIf(self.event.itsItem in self.two)
        for modItem in self.event.modifications:
            if modItem is not second.itsItem:
                self.failIf(modItem in self.two)
    def testChangeOverlapping_THIS_FUTURE(self):
        self.event.rruleset = self.rruleset

        second = self.event.getFirstOccurrence().getNextOccurrence()
        third = second.getNextOccurrence()

        pim.CHANGE_THIS(third).duration = datetime.timedelta(hours=2)
        self.failUnless(third.itsItem.lastModified > self.start)

        saveLastModified = third.itsItem.lastModified

        time.sleep(0.1)  # Make sure some time elapses for lastModified
        pim.CHANGE_FUTURE(second).duration = datetime.timedelta(hours=4)
        # However, third wasn't altered by the last change, so its
        # lastModified should be unchanged.
        self.failUnlessEqual(saveLastModified, third.itsItem.lastModified)
    def testAdd_THIS(self):
        # Adding just a THIS mod to a collection is disabled for now
        # (fails with an assertion).
        self.event.itsItem.collections = [self.one, self.two]
        self.event.rruleset = self.rruleset
        second = self.event.getFirstOccurrence().getNextOccurrence()
        proxiedSecond = pim.CHANGE_THIS(second)

        if __debug__:
            self.failUnlessRaises(AssertionError,
                                  proxiedSecond.itsItem.collections.remove,
                                  self.two)
        else:
            proxiedSecond.itsItem.collections.remove(self.two)

        self.failUnless(second.itsItem in self.two)
        self.failUnless(self.event.itsItem in self.two)
        for modItem in self.event.modifications:
            self.failUnless(modItem in self.two)
    def testChangeCC(self):

        #        email = pim.mail.EmailAddress(itsParent=self.sandbox, fullName=u'Tommy Totoro',
        #                             emailAddress=u'*****@*****.**')

        mei = pim.mail.EmailAddress(itsParent=self.sandbox,
                                    fullName=u'Mei Kusakabe',
                                    emailAddress=u'*****@*****.**')

        catbus = pim.mail.EmailAddress(
            itsParent=self.sandbox,
            fullName=u'Nekobasu',
            emailAddress=u'*****@*****.**')

        mail = messageTextToKind(
            self.sandbox.itsView,
            "From: Nekobasu <[email protected]\r\n"
            "To: Mei Kusakabe <[email protected]\r\n"
            "Subject: Do you need a ride home?\r\n"
            "Content-Type: text/plain; charset='US-ASCII'"
            "\r\n"
            "I think it's raining!\r\n")[1]
        mail.itsItem.lastModification = pim.Modification.created

        pim.mail.getCurrentMeEmailAddresses(mei.itsView).add(mei)

        event = pim.EventStamp(mail)
        event.add()
        event.rruleset = self.rruleset

        pim.CHANGE_THIS(mail.itsItem).displayName = u"You bet I do!"

        firstItem = event.getFirstOccurrence().itsItem

        self.failIf(
            firstItem.hasLocalAttributeValue(
                pim.mail.MailStamp.ccAddress.name))

        self.failUnless(mei is mail.fromAddress)
        self.failUnless(catbus in mail.ccAddress)
    def testChangeNonOverlapping_THIS_FUTURE(self):
        # Make a THIS change to one occurrence, followed by an FUTURE
        # change of a different attribute to a different occurrence, and make
        # sure the lastModified is updated accordingly.
        self.event.rruleset = self.rruleset

        second = self.event.getFirstOccurrence().getNextOccurrence()
        third = second.getNextOccurrence()

        # THIS change to summary (a.k.a. displayName) ...
        pim.CHANGE_THIS(third).summary = u'This has been changed'
        # Make sure the lastModified changed for this event (third) ...
        self.failUnless(third.itsItem.lastModified > self.start)
        # ... but not for second, a different event in the series
        self.failUnlessEqual(second.itsItem.lastModified, self.start)

        # Remember third's lastModified, so we can check that it changed
        # later.
        saveLastModified = third.itsItem.lastModified

        time.sleep(0.1)  # Make sure some time elapses for lastModified

        # Now make an FUTURE change on duration
        pim.CHANGE_FUTURE(second).duration = datetime.timedelta(hours=4)

        # self.event (the master) should have an unchanged lastModified
        self.failUnlessEqual(self.event.itsItem.lastModified, self.start)
        # second is now part of a new series, and so should have a new
        # lastModified
        self.failIfEqual(self.event.itsItem.lastModified,
                         second.itsItem.lastModified)
        # third was altered by the last change, so its
        # lastModified should be changed, too.
        self.failIfEqual(saveLastModified, third.itsItem.lastModified)
        self.failUnlessEqual(second.itsItem.lastModified,
                             third.itsItem.lastModified)
    def testNoRecurrence_THIS(self):
        pim.CHANGE_THIS(self.event.itsItem).changeEditState()

        self.failUnlessEqual(self.event.itsItem.lastModification,
                             pim.Modification.edited)
        self.failUnless(self.event.itsItem.lastModified > self.start)