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 testRemove_ALL(self):
        self.event.itsItem.collections = [self.one, self.two]
        self.event.rruleset = self.rruleset

        firstProxy = pim.CHANGE_ALL(self.event.getFirstOccurrence())
        firstProxy.itsItem.collections.remove(self.one)

        self.failIf(self.event.itsItem in self.one)
        self.failUnless(self.event.itsItem in self.two)
    def testChangeRecurrence_ALL(self):
        self.event.rruleset = self.rruleset
        third = self.event.getFirstOccurrence().getNextOccurrence(
        ).getNextOccurrence()

        pim.CHANGE_ALL(third).rruleset = self.makeRuleset('weekly')

        self.failUnless(pim.isDead(third.itsItem))
        self.failIf(pim.isDead(self.event.itsItem))
        self.failUnlessEqual(self.event.rruleset.rrules.first().freq, 'weekly')
    def testChange_ALL(self):
        self.event.rruleset = self.rruleset

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

        pim.CHANGE_ALL(
            second).startTime = second.startTime + datetime.timedelta(hours=1)
        self.failUnless(self.event.itsItem.lastModified > self.start)
        self.failUnlessEqual(second.getNextOccurrence().itsItem.lastModified,
                             self.event.itsItem.lastModified)
    def testUnstampEvent_ALL(self):
        self.event.rruleset = self.rruleset
        third = self.event.getFirstOccurrence().getNextOccurrence(
        ).getNextOccurrence()

        pim.CHANGE_ALL(third).remove()

        self.failUnless(pim.isDead(third.itsItem))
        self.failIf(pim.isDead(self.event.itsItem))
        self.failIf(pim.has_stamp(self.event, pim.EventStamp))
    def testDeleteRecurrence_ALL(self):
        self.event.rruleset = self.rruleset
        first = self.event.getFirstOccurrence()
        third = first.getNextOccurrence().getNextOccurrence()

        del pim.CHANGE_ALL(third).rruleset

        self.failUnless(pim.isDead(first.itsItem))
        self.failUnless(pim.isDead(third.itsItem))
        self.failIf(pim.isDead(self.event.itsItem))
        self.failUnless(self.event.rruleset is None)
    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 testChangeOverlapping_THIS_ALL(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_ALL(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 testStamp_ALL(self):
        self.event.rruleset = self.rruleset
        ruleEnd = self.event.startTime + datetime.timedelta(days=10)
        self.event.rruleset.rrules.first().until = ruleEnd

        occurrences = [self.event.getFirstOccurrence()]
        for i in xrange(10):
            occurrences.append(occurrences[-1].getNextOccurrence())

        pim.TaskStamp(pim.CHANGE_ALL(occurrences[0])).add()

        for event in occurrences:
            self.failUnlessEqual(event.getMaster(), self.event)
        for item in self.event.occurrences:
            self.failUnless(pim.has_stamp(item, pim.TaskStamp))
        self.failUnless(pim.has_stamp(self.event, pim.TaskStamp))
    def testNoRecurrence_ALL(self):
        pim.CHANGE_ALL(self.event.itsItem).changeEditState()

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