def test_move(self): f1 = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f2 = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f1_id, f1_changekey, f1_parent = f1.id, f1.changekey, f1.parent with self.assertRaises(TypeError) as e: f1.move(to_folder="XXX") # Must be folder instance self.assertEqual( e.exception.args[0], "'to_folder' 'XXX' must be of type (<class 'exchangelib.folders.base.BaseFolder'>, " "<class 'exchangelib.properties.FolderId'>)", ) f1.move(f2) self.assertEqual(f1.id, f1_id) self.assertNotEqual(f1.changekey, f1_changekey) self.assertEqual(f1.parent, f2) self.assertNotEqual(f1.changekey, f1_parent) f1_id, f1_changekey, f1_parent = f1.id, f1.changekey, f1.parent f1.refresh() self.assertEqual(f1.id, f1_id) self.assertEqual(f1.parent, f2) self.assertNotEqual(f1.changekey, f1_parent) f1.delete() f2.delete()
def test_counts(self): # Test count values on a folder f = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f.refresh() self.assertEqual(f.total_count, 0) self.assertEqual(f.unread_count, 0) self.assertEqual(f.child_folder_count, 0) # Create some items items = [] for i in range(3): subject = 'Test Subject %s' % i item = Message(account=self.account, folder=f, is_read=False, subject=subject, categories=self.categories) item.save() items.append(item) # Refresh values and see that total_count and unread_count changes f.refresh() self.assertEqual(f.total_count, 3) self.assertEqual(f.unread_count, 3) self.assertEqual(f.child_folder_count, 0) for i in items: i.is_read = True i.save() # Refresh values and see that unread_count changes f.refresh() self.assertEqual(f.total_count, 3) self.assertEqual(f.unread_count, 0) self.assertEqual(f.child_folder_count, 0) self.bulk_delete(items) # Refresh values and see that total_count changes f.refresh() self.assertEqual(f.total_count, 0) self.assertEqual(f.unread_count, 0) self.assertEqual(f.child_folder_count, 0) # Create some subfolders subfolders = [] for i in range(3): subfolders.append( Folder(parent=f, name=get_random_string(16)).save()) # Refresh values and see that child_folder_count changes f.refresh() self.assertEqual(f.total_count, 0) self.assertEqual(f.unread_count, 0) self.assertEqual(f.child_folder_count, 3) for sub_f in subfolders: sub_f.delete() # Refresh values and see that child_folder_count changes f.refresh() self.assertEqual(f.total_count, 0) self.assertEqual(f.unread_count, 0) self.assertEqual(f.child_folder_count, 0) f.delete()
def test_generic_folder(self): f = Folder(parent=self.account.inbox, name=get_random_string(16)) f.save() f.name = get_random_string(16) f.save() f.delete() self.assertEqual(Folder().has_distinguished_name, None) self.assertEqual(Inbox(name="XXX").has_distinguished_name, False) self.assertEqual(Inbox(name="Inbox").has_distinguished_name, True) self.assertEqual(Inbox(is_distinguished=False).is_deletable, True) self.assertEqual(Inbox(is_distinguished=True).is_deletable, False)
def test_move(self): f1 = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f2 = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f1_id, f1_changekey, f1_parent = f1.id, f1.changekey, f1.parent f1.move(f2) self.assertEqual(f1.id, f1_id) self.assertNotEqual(f1.changekey, f1_changekey) self.assertEqual(f1.parent, f2) f1_id, f1_changekey, f1_parent = f1.id, f1.changekey, f1.parent f1.refresh() self.assertEqual(f1.id, f1_id) self.assertEqual(f1.parent, f2) f1.delete() f2.delete()
def test_folder_query_set(self): # Create a folder hierarchy and test a folder queryset # # -f0 # - f1 # - f2 # - f21 # - f22 f0 = Folder(parent=self.account.inbox, name=get_random_string(16)).save() f1 = Folder(parent=f0, name=get_random_string(16)).save() f2 = Folder(parent=f0, name=get_random_string(16)).save() f21 = Folder(parent=f2, name=get_random_string(16)).save() f22 = Folder(parent=f2, name=get_random_string(16)).save() folder_qs = SingleFolderQuerySet(account=self.account, folder=f0) try: # Test all() self.assertSetEqual({f.name for f in folder_qs.all()}, {f.name for f in (f1, f2, f21, f22)}) # Test only() self.assertSetEqual({f.name for f in folder_qs.only("name").all()}, {f.name for f in (f1, f2, f21, f22)}) self.assertSetEqual({f.child_folder_count for f in folder_qs.only("name").all()}, {None}) # Test depth() self.assertSetEqual({f.name for f in folder_qs.depth(SHALLOW).all()}, {f.name for f in (f1, f2)}) # Test filter() self.assertSetEqual({f.name for f in folder_qs.filter(name=f1.name)}, {f.name for f in (f1,)}) self.assertSetEqual( {f.name for f in folder_qs.filter(name__in=[f1.name, f2.name])}, {f.name for f in (f1, f2)} ) # Test get() self.assertEqual(folder_qs.get(id=f2.id).name, f2.name) self.assertEqual(folder_qs.get(id=f2.id, changekey=f2.changekey).name, f2.name) self.assertEqual(folder_qs.get(name=f2.name).child_folder_count, 2) self.assertEqual(folder_qs.filter(name=f2.name).get().child_folder_count, 2) self.assertEqual(folder_qs.only("name").get(name=f2.name).name, f2.name) self.assertEqual(folder_qs.only("name").get(name=f2.name).child_folder_count, None) with self.assertRaises(DoesNotExist): folder_qs.get(name=get_random_string(16)) with self.assertRaises(MultipleObjectsReturned): folder_qs.get() finally: f0.wipe() f0.delete()
def test_generic_folder(self): f = Folder(parent=self.account.inbox, name=get_random_string(16)) f.save() f.name = get_random_string(16) f.save() f.delete()