<commit_before>from exchangelib.errors import ErrorItemNotFound, ErrorInvalidChangeKey, ErrorInvalidIdMalformed
from exchangelib.ewsdatetime import EWSDate
from exchangelib.fields import FieldPath
from exchangelib.folders import Inbox, Folder, Calendar
from exchangelib.items import Item, Message, SAVE_ONLY, SEND_ONLY, SEND_AND_SAVE_COPY, CalendarItem

from .test_basics import BaseItemTest


class BulkMethodTest(BaseItemTest):
    TEST_FOLDER = 'inbox'
    FOLDER_CLASS = Inbox
    ITEM_CLASS = Message

    def test_fetch(self):
        item = self.get_test_item()
        self.test_folder.bulk_create(items=[item, item])
        ids = self.test_folder.filter(categories__contains=item.categories)
        items = list(self.account.fetch(ids=ids))
        for item in items:
            self.assertIsInstance(item, self.ITEM_CLASS)
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=['subject']))
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=[FieldPath.from_string('subject', self.test_folder)]))
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=['id', 'changekey']))
        self.assertEqual(len(items), 2)

    def test_no_account(self):
        # Test bulk operations on items with no self.account
        item = self.get_test_item()
        item.account = None
        res = self.test_folder.bulk_create(items=[item])[0]
        item.id, item.changekey = res.id, res.changekey
        item.account = None
        self.assertEqual(list(self.account.fetch(ids=[item]))[0].id, item.id)
        item.account = None
        res = self.account.bulk_update(items=[(item, ('subject',))])[0]
        item.id, item.changekey = res
        item.account = None
        res = self.account.bulk_copy(ids=[item], to_folder=self.account.trash)[0]
        item.id, item.changekey = res
        item.account = None
        self.assertEqual(self.account.bulk_send(ids=[item]), [True])
        item.account = None
        res = self.account.bulk_move(ids=[item], to_folder=self.test_folder)[0]
        item.id, item.changekey = res
        item.account = None
        self.assertEqual(self.account.bulk_delete(ids=[item]), [True])

    def test_empty_args(self):
        # We allow empty sequences for these methods
        self.assertEqual(self.test_folder.bulk_create(items=[]), [])
        self.assertEqual(list(self.account.fetch(ids=[])), [])
        self.assertEqual(self.account.bulk_create(folder=self.test_folder, items=[]), [])
        self.assertEqual(self.account.bulk_update(items=[]), [])
        self.assertEqual(self.account.bulk_delete(ids=[]), [])
        self.assertEqual(self.account.bulk_send(ids=[]), [])
        self.assertEqual(self.account.bulk_copy(ids=[], to_folder=self.account.trash), [])
        self.assertEqual(self.account.bulk_move(ids=[], to_folder=self.account.trash), [])
        self.assertEqual(self.account.upload(data=[]), [])
        self.assertEqual(self.account.export(items=[]), [])

    def test_qs_args(self):<commit_msg>send() is not instant. Add test reliability<commit_after>from exchangelib.errors import ErrorItemNotFound, ErrorInvalidChangeKey, ErrorInvalidIdMalformed
from exchangelib.ewsdatetime import EWSDate
from exchangelib.fields import FieldPath
from exchangelib.folders import Inbox, Folder, Calendar
from exchangelib.items import Item, Message, SAVE_ONLY, SEND_ONLY, SEND_AND_SAVE_COPY, CalendarItem

from .test_basics import BaseItemTest


class BulkMethodTest(BaseItemTest):
    TEST_FOLDER = 'inbox'
    FOLDER_CLASS = Inbox
    ITEM_CLASS = Message

    def test_fetch(self):
        item = self.get_test_item()
        self.test_folder.bulk_create(items=[item, item])
        ids = self.test_folder.filter(categories__contains=item.categories)
        items = list(self.account.fetch(ids=ids))
        for item in items:
            self.assertIsInstance(item, self.ITEM_CLASS)
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=['subject']))
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=[FieldPath.from_string('subject', self.test_folder)]))
        self.assertEqual(len(items), 2)

        items = list(self.account.fetch(ids=ids, only_fields=['id', 'changekey']))
        self.assertEqual(len(items), 2)

    def test_no_account(self):
        # Test bulk operations on items with no self.account
        item = self.get_test_item()
        item.account = None
        res = self.test_folder.bulk_create(items=[item])[0]
        item.id, item.changekey = res.id, res.changekey
        item.account = None
        self.assertEqual(list(self.account.fetch(ids=[item]))[0].id, item.id)
        item.account = None
        res = self.account.bulk_update(items=[(item, ('subject',))])[0]
        item.id, item.changekey = res
        item.account = None
        res = self.account.bulk_copy(ids=[item], to_folder=self.account.trash)[0]
        item.id, item.changekey = res
        item.account = None
        res = self.account.bulk_move(ids=[item], to_folder=self.test_folder)[0]
        item.id, item.changekey = res
        item.account = None
        self.assertEqual(self.account.bulk_delete(ids=[item]), [True])
        item = self.get_test_item().save()
        item.account = None
        self.assertEqual(self.account.bulk_send(ids=[item]), [True])

    def test_empty_args(self):
        # We allow empty sequences for these methods
        self.assertEqual(self.test_folder.bulk_create(items=[]), [])
        self.assertEqual(list(self.account.fetch(ids=[])), [])
        self.assertEqual(self.account.bulk_create(folder=self.test_folder, items=[]), [])
        self.assertEqual(self.account.bulk_update(items=[]), [])
        self.assertEqual(self.account.bulk_delete(ids=[]), [])
        self.assertEqual(self.account.bulk_send(ids=[]), [])
        self.assertEqual(self.account.bulk_copy(ids=[], to_folder=self.account.trash), [])
        self.assertEqual(self.account.bulk_move(ids=[], to_folder=self.account.trash), [])
        self.assertEqual(self.account.upload(data=[]), [])
        self.assertEqual(self.account.export(items=[]), [])

    def test_qs_args(self):
{'fraction_non_alphanumeric': 0.13667353733946408, 'fraction_numerical': 0.0028539717773902015, 'mean_word_length': 3.502498215560314, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900977', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1966, 'n_words': 319}