def test_wipe_without_empty(self): name = get_random_string(16) f = Messages(parent=self.account.inbox, name=name).save() Messages(parent=f, name=get_random_string(16)).save() self.assertEqual(len(list(f.children)), 1) tmp = f.empty try: f.empty = Mock(side_effect=ErrorCannotEmptyFolder("XXX")) f.wipe() finally: f.empty = tmp self.assertEqual(len(list(f.children)), 0)
def test_create_update_empty_delete(self): name = get_random_string(16) f = Messages(parent=self.account.inbox, name=name).save() with self.assertRaises(ErrorFolderExists): Messages(parent=self.account.inbox, name=name).save() self.assertIsNotNone(f.id) self.assertIsNotNone(f.changekey) new_name = get_random_string(16) f.name = new_name f.save() f.refresh() self.assertEqual(f.name, new_name) with self.assertRaises(ErrorObjectTypeChanged): # FolderClass may not be changed f.folder_class = get_random_string(16) f.save(update_fields=["folder_class"]) # Create a subfolder Messages(parent=f, name=get_random_string(16)).save() self.assertEqual(len(list(f.children)), 1) f.empty() self.assertEqual(len(list(f.children)), 1) f.empty(delete_sub_folders=True) self.assertEqual(len(list(f.children)), 0) # Create a subfolder again, and delete it by wiping Messages(parent=f, name=get_random_string(16)).save() self.assertEqual(len(list(f.children)), 1) f.wipe() self.assertEqual(len(list(f.children)), 0) item_id, changekey = f.id, f.changekey f.delete() with self.assertRaises(ValueError): # No longer has an ID f.refresh() with self.assertRaises(ErrorItemNotFound): f.id, f.changekey = item_id, changekey # Invalid ID f.save() with self.assertRaises(ErrorDeleteDistinguishedFolder): self.account.inbox.delete()