def test_trash_email_message(self, get_message_info_mock, trash_email_message_mock): """ Test the GmailManager on trashing an email message. """ message_id = '15af6279f554fd15' # Mock the responses of the API call. with open('lily/messaging/email/tests/data/trash_email_message_{0}.json'.format(message_id)) as infile: json_obj = json.load(infile) trash_email_message_mock.return_value = json_obj with open('lily/messaging/email/tests/data/get_message_info_{0}_trash.json'.format(message_id)) as infile: json_obj = json.load(infile) get_message_info_mock.return_value = json_obj email_account = EmailAccount.objects.first() email_message = EmailMessageFactory.create(account=email_account, message_id=message_id) labels = [settings.GMAIL_LABEL_UNREAD, settings.GMAIL_LABEL_TRASH, settings.GMAIL_LABEL_INBOX] for label in labels: EmailLabelFactory.create(account=email_account, label_id=label) manager = GmailManager(email_account) manager.trash_email_message(email_message) # Verify that the email message is trashed by looking at the labels, ie. INBOX is not presnt and TRASH is. email_message_labels = set(email_message.labels.all().values_list('label_id', flat=True)) self.assertEqual(email_message_labels, set([settings.GMAIL_LABEL_UNREAD, settings.GMAIL_LABEL_TRASH]))
def _create_object_stub(self, size=1, action=None, with_send_from=True, with_message=False, **kwargs): object_list = super(DraftEmailTests, self)._create_object_stub(size, force_to_list=True, **kwargs) for obj in object_list: obj['action'] = action or 'compose' # 'compose' is the default. account = EmailAccountFactory(owner=self.user_obj, tenant=self.user_obj.tenant) obj['send_from'] = None if with_send_from: obj['send_from'] = account.id if with_message: obj['message'] = EmailMessageFactory.create(account=account).id if size == 1: return object_list[0] return object_list
def _create_object_stub(self, size=1, action=None, with_send_from=True, with_message=False, **kwargs): object_list = super(DraftEmailTests, self)._create_object_stub(size, force_to_list=True, **kwargs) for obj in object_list: obj['action'] = action or 'compose' # 'compose' is the default. account = EmailAccountFactory( owner=self.user_obj, tenant=self.user_obj.tenant ) obj['send_from'] = None if with_send_from: obj['send_from'] = account.id if with_message: obj['message'] = EmailMessageFactory.create(account=account).id if size == 1: return object_list[0] return object_list