def test_delete_occurrence_via_index(self): # Test deleting occurrences via occurrence index without knowing the ID of the occurrence. start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, subject=get_random_string(16), recurrence=Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4), categories=self.categories, ).save() # Delete the third occurrence third_occurrence = master_item.occurrence(index=3) third_occurrence.refresh() # Test that GetItem works third_occurrence = master_item.occurrence(index=3) third_occurrence.delete() # Test that DeleteItem works # Test change on the master item master_item.refresh() self.assertEqual(master_item.modified_occurrences, None) self.assertEqual(len(master_item.deleted_occurrences), 1) deleted_occurrence = master_item.deleted_occurrences[0] self.assertIsInstance(deleted_occurrence, DeletedOccurrence) self.assertEqual(deleted_occurrence.start, start + datetime.timedelta(days=2))
def test_change_occurrence(self): # Test that we can make changes to individual occurrences and see the effect on the master item. start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, recurrence=Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4), categories=self.categories, ).save() master_item.refresh() # Test occurrences as full calendar items, unfolded from the master range_start, range_end = start, end + datetime.timedelta(days=3) unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] # Change the start and end of the second occurrence second_occurrence = unfolded[1] second_occurrence.start += datetime.timedelta(hours=1) second_occurrence.end += datetime.timedelta(hours=1) second_occurrence.save() # Test change on the master item master_item.refresh() self.assertEqual(len(master_item.modified_occurrences), 1) modified_occurrence = master_item.modified_occurrences[0] self.assertIsInstance(modified_occurrence, Occurrence) self.assertEqual(modified_occurrence.id, second_occurrence.id) self.assertEqual(modified_occurrence.start, second_occurrence.start) self.assertEqual(modified_occurrence.end, second_occurrence.end) self.assertEqual(modified_occurrence.original_start, second_occurrence.start - datetime.timedelta(hours=1)) self.assertEqual(master_item.deleted_occurrences, None) # Test change on the unfolded item unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] self.assertEqual(len(unfolded), 4) self.assertEqual(unfolded[1].type, EXCEPTION) self.assertEqual(unfolded[1].start, second_occurrence.start) self.assertEqual(unfolded[1].end, second_occurrence.end) self.assertEqual(unfolded[1].original_start, second_occurrence.start - datetime.timedelta(hours=1))
def test_change_occurrence_via_index(self): # Test updating occurrences via occurrence index without knowing the ID of the occurrence. start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, subject=get_random_string(16), recurrence=Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4), categories=self.categories, ).save() # Change the start and end of the second occurrence second_occurrence = master_item.occurrence(index=2) second_occurrence.start = start + datetime.timedelta(days=1, hours=1) second_occurrence.end = end + datetime.timedelta(days=1, hours=1) second_occurrence.save(update_fields=[ 'start', 'end' ]) # Test that UpdateItem works with only a few fields second_occurrence = master_item.occurrence(index=2) second_occurrence.refresh() self.assertEqual(second_occurrence.subject, master_item.subject) second_occurrence.start += datetime.timedelta(hours=1) second_occurrence.end += datetime.timedelta(hours=1) second_occurrence.save( update_fields=['start', 'end']) # Test that UpdateItem works after refresh # Test change on the master item master_item.refresh() self.assertEqual(len(master_item.modified_occurrences), 1) modified_occurrence = master_item.modified_occurrences[0] self.assertIsInstance(modified_occurrence, Occurrence) self.assertEqual(modified_occurrence.id, second_occurrence.id) self.assertEqual(modified_occurrence.start, second_occurrence.start) self.assertEqual(modified_occurrence.end, second_occurrence.end) self.assertEqual(modified_occurrence.original_start, second_occurrence.start - datetime.timedelta(hours=2)) self.assertEqual(master_item.deleted_occurrences, None)
def test_get_master_recurrence(self): # Test getting the master recurrence via an occurrence start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) recurrence = Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, subject=get_random_string(16), recurrence=recurrence, categories=self.categories, ).save() # Get the master from an occurrence range_start, range_end = start, end + datetime.timedelta(days=3) unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] third_occurrence = unfolded[2] self.assertEqual(third_occurrence.recurrence, None) master_from_occurrence = third_occurrence.recurring_master() master_from_occurrence.refresh() # Test that GetItem works self.assertEqual(master_from_occurrence.recurrence, recurrence) self.assertEqual(master_from_occurrence.subject, master_item.subject) master_from_occurrence = third_occurrence.recurring_master() master_from_occurrence.subject = get_random_string(16) master_from_occurrence.save( update_fields=['subject']) # Test that UpdateItem works master_from_occurrence.delete() # Test that DeleteItem works with self.assertRaises(ErrorItemNotFound): master_item.delete( ) # Item is gone from the server, so this should fail with self.assertRaises(ErrorItemNotFound): third_occurrence.delete( ) # Item is gone from the server, so this should fail
def test_delete_occurrence(self): # Test that we can delete an occurrence and see the cange on the master item start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, recurrence=Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4), categories=self.categories, ).save() master_item.refresh() # Test occurrences as full calendar items, unfolded from the master range_start, range_end = start, end + datetime.timedelta(days=3) unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] # Delete the third occurrence third_occurrence = unfolded[2] third_occurrence.delete() # Test change on the master item master_item.refresh() self.assertEqual(master_item.modified_occurrences, None) self.assertEqual(len(master_item.deleted_occurrences), 1) deleted_occurrence = master_item.deleted_occurrences[0] self.assertIsInstance(deleted_occurrence, DeletedOccurrence) self.assertEqual(deleted_occurrence.start, third_occurrence.start) # Test change on the unfolded items unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] self.assertEqual(len(unfolded), 3)
def test_recurring_item(self): # Create a recurring calendar item. Test that occurrence fields are correct on the master item # Create a master item with 4 daily occurrences from 8:00 to 10:00. 'start' and 'end' are values for the first # occurrence. start = EWSDateTime(2016, 1, 1, 8, tzinfo=self.account.default_timezone) end = EWSDateTime(2016, 1, 1, 10, tzinfo=self.account.default_timezone) master_item = self.ITEM_CLASS( folder=self.test_folder, start=start, end=end, recurrence=Recurrence(pattern=DailyPattern(interval=1), start=start.date(), number=4), categories=self.categories, ).save() master_item.refresh() self.assertEqual(master_item.is_recurring, False) self.assertEqual(master_item.type, RECURRING_MASTER) self.assertIsInstance(master_item.first_occurrence, FirstOccurrence) self.assertEqual(master_item.first_occurrence.start, start) self.assertEqual(master_item.first_occurrence.end, end) self.assertIsInstance(master_item.last_occurrence, LastOccurrence) self.assertEqual(master_item.last_occurrence.start, start + datetime.timedelta(days=3)) self.assertEqual(master_item.last_occurrence.end, end + datetime.timedelta(days=3)) self.assertEqual(master_item.modified_occurrences, None) self.assertEqual(master_item.deleted_occurrences, None) # Test occurrences as full calendar items, unfolded from the master range_start, range_end = start, end + datetime.timedelta(days=3) unfolded = [ i for i in self.test_folder.view(start=range_start, end=range_end) if self.match_cat(i) ] self.assertEqual(len(unfolded), 4) for item in unfolded: self.assertEqual(item.type, OCCURRENCE) self.assertEqual(item.is_recurring, True) first_occurrence = unfolded[0] self.assertEqual(first_occurrence.id, master_item.first_occurrence.id) self.assertEqual(first_occurrence.start, master_item.first_occurrence.start) self.assertEqual(first_occurrence.end, master_item.first_occurrence.end) second_occurrence = unfolded[1] self.assertEqual(second_occurrence.start, master_item.start + datetime.timedelta(days=1)) self.assertEqual(second_occurrence.end, master_item.end + datetime.timedelta(days=1)) third_occurrence = unfolded[2] self.assertEqual(third_occurrence.start, master_item.start + datetime.timedelta(days=2)) self.assertEqual(third_occurrence.end, master_item.end + datetime.timedelta(days=2)) last_occurrence = unfolded[3] self.assertEqual(last_occurrence.id, master_item.last_occurrence.id) self.assertEqual(last_occurrence.start, master_item.last_occurrence.start) self.assertEqual(last_occurrence.end, master_item.last_occurrence.end)