コード例 #1
0
    def test_post_sends_mail_and_deletes_previous_draft_if_it_exists(self):
        # act as if sending the mail by SMTP succeeded
        sendmail_deferred = defer.Deferred()
        when(self.mail_sender).sendmail(any()).thenReturn(sendmail_deferred)

        # creates one draft
        first_draft = MailBuilder().with_subject('First draft').build_json()
        first_draft_ident = (yield self.put_mail(first_draft)[0])['ident']

        # sends an updated version of the draft
        second_draft = MailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build_json()
        deferred_res = self.post_mail(second_draft)

        sendmail_deferred.callback(None)  # SMTP succeeded

        yield deferred_res

        sent_mails = yield self.get_mails_by_tag('sent')
        drafts = yield self.get_mails_by_tag('drafts')

        # make sure there is one email in the sent mailbox and it is the second draft
        self.assertEquals(1, len(sent_mails))
        self.assertEquals('Second draft', sent_mails[0].subject)

        # make sure that there are no drafts in the draft mailbox
        self.assertEquals(0, len(drafts))
コード例 #2
0
    def test_bounced_addresses_are_ignored(self):
        to_be_bounced = MailBuilder().with_to(
            '*****@*****.**').build_input_mail()
        self.add_mail_to_inbox(to_be_bounced)

        bounced_mail_template = MailBuilder().build_input_mail()
        bounced_mail = self.mailboxes.inbox().add(bounced_mail_template)
        bounced_mail.hdoc.content = self._bounced_mail_hdoc_content()
        bounced_mail.save()
        self.search_engine.index_mail(bounced_mail)

        not_bounced_mail = MailBuilder().with_tags([
            'important'
        ]).with_to('*****@*****.**').build_input_mail()
        self.add_mail_to_inbox(not_bounced_mail)

        d = self.get_contacts(query='this')

        def _assert(contacts):
            self.assertNotIn('*****@*****.**', contacts)
            self.assertNotIn("[email protected] (Mail Delivery System)",
                             contacts)
            self.assertIn('*****@*****.**', contacts)

        d.addCallback(_assert)
        return d
コード例 #3
0
    def test_respond_unprocessable_entity_if_draft_to_remove_doesnt_exist(self):
        draft = MailBuilder().with_subject('First draft').build_json()
        yield self.put_mail(draft)[0]

        updated_draft = MailBuilder().with_subject('First draft edited').with_ident('NOTFOUND').build_json()
        response, request = self.put_mail(updated_draft)
        yield response

        self.assertEquals(422, request.code)
コード例 #4
0
    def test_search_mails_different_window(self):
        input_mail = MailBuilder().build_input_mail()
        input_mail2 = MailBuilder().build_input_mail()
        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(input_mail2)

        first_page = self.get_mails_by_tag('inbox', page=1, window=1)

        self.assertEqual(len(first_page), 1)
コード例 #5
0
    def test_order_by_date(self):
        input_mail = MailBuilder().with_date('2014-10-15T15:15').build_input_mail()
        input_mail2 = MailBuilder().with_date('2014-10-15T15:16').build_input_mail()

        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(input_mail2)

        results = self.get_mails_by_tag('inbox')
        self.assertEqual(results[0].ident, input_mail2.ident)
        self.assertEqual(results[1].ident, input_mail.ident)
コード例 #6
0
    def test_put_updates_draft_if_it_already_exists(self):
        draft = MailBuilder().with_subject('First draft').build_json()
        draft_ident = (yield self.put_mail(draft)[0])['ident']

        updated_draft = MailBuilder().with_subject('First draft edited').with_ident(draft_ident).build_json()
        yield self.put_mail(updated_draft)[0]

        drafts = yield self.get_mails_by_tag('drafts')

        self.assertEquals(1, len(drafts))
        self.assertEquals('First draft edited', drafts[0].subject)
コード例 #7
0
    def test_mark_many_mails_as_unread(self):
        input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail()
        input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail()

        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(input_mail2)

        self.mark_many_as_unread([input_mail.ident, input_mail2.ident])

        mails = self.get_mails_by_tag('inbox')

        self.assertNotIn('read', mails[0].status)
        self.assertNotIn('read', mails[1].status)
コード例 #8
0
    def test_search_mails_with_multiple_pages(self):
        input_mail = MailBuilder().build_input_mail()
        input_mail2 = MailBuilder().build_input_mail()
        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(input_mail2)

        first_page = self.get_mails_by_tag('inbox', page=1, window=1)
        second_page = self.get_mails_by_tag('inbox', page=2, window=1)

        idents = [input_mail.ident, input_mail2.ident]

        self.assertIn(first_page[0].ident, idents)
        self.assertIn(second_page[0].ident, idents)
コード例 #9
0
    def test_FROM_address_is_being_searched(self):
        input_mail = MailBuilder().with_tags(['important']).with_from('Formatted Sender <*****@*****.**>').build_input_mail()
        yield self.add_mail_to_inbox(input_mail)

        contacts = yield self.get_contacts(query='Sender')

        self.assertIn('Formatted Sender <*****@*****.**>', contacts)
コード例 #10
0
    def test_tags_with_multiple_words_are_searchable(self):
        input_mail = MailBuilder().with_tags(['one tag four words']).build_input_mail()
        self.add_mail_to_inbox(input_mail)

        first_page = self.get_mails_by_tag('"one tag four words"', page=1, window=1)

        self.assertEqual(len(first_page), 1)
コード例 #11
0
def add_mail_impl(context):
    subject = 'Hi! This the subject %s' % uuid4()

    input_mail = MailBuilder().with_subject(subject).build_input_mail()
    context.client.add_mail_to_inbox(input_mail)

    context.last_subject = subject
コード例 #12
0
    def test_update_draft(self):
        input_mail = MailBuilder().with_body(
            'some test text').build_input_mail()
        saved_mail = yield self.mail_store.add_mail('DRAFTS', input_mail.raw)
        draft_id = saved_mail.ident
        new_email = MailBuilder().with_body('other test text').with_ident(
            draft_id).build_input_mail()

        stored_draft = yield self.draft_service.process_draft(
            draft_id, new_email)

        old_draft = yield self.mail_store.get_mail(draft_id, include_body=True)
        draft = yield self.mail_store.get_mail(stored_draft.ident,
                                               include_body=True)

        self.assertIsNone(old_draft)
        self.assertEqual('other test text', draft.body)
コード例 #13
0
    def test_search_base64_body(self):
        body = u'bl\xe1'
        input_mail = MailBuilder().with_body(body.encode('utf-8')).build_input_mail()
        self.add_mail_to_inbox(input_mail)
        results = self.search(body)

        self.assertGreater(len(results), 0, 'No results returned from search')
        self.assertEquals(results[0].ident, input_mail.ident)
コード例 #14
0
    def test_deduplication_on_same_mail_address_using_largest(self):
        input_mail = MailBuilder().with_tags(['important']).build_input_mail()

        formatted_input_mail = MailBuilder().with_tags(['important'])
        formatted_input_mail.with_to('Recipient Principal <*****@*****.**>')
        formatted_input_mail.with_cc('Recipient Copied <*****@*****.**>')
        formatted_input_mail.with_bcc('Recipient Carbon <*****@*****.**>')
        formatted_input_mail = formatted_input_mail.build_input_mail()

        yield self.add_mail_to_inbox(input_mail)
        yield self.add_mail_to_inbox(formatted_input_mail)

        contacts = yield self.get_contacts(query='Recipient')

        self.assertEquals(3, len(contacts))
        self.assertTrue('Recipient Principal <*****@*****.**>' in contacts)
        self.assertTrue('Recipient Copied <*****@*****.**>' in contacts)
        self.assertTrue('Recipient Carbon <*****@*****.**>' in contacts)
コード例 #15
0
    def test_use_old_casing_when_same_tag_with_different_casing_is_posted(
            self):
        mail = MailBuilder().with_subject('Mail with tags').build_input_mail()
        self.add_mail_to_inbox(mail)
        self.post_tags(mail.ident, self._tags_json(['ImPoRtAnT']))
        mails = self.get_mails_by_tag('ImPoRtAnT')
        self.assertEquals({'ImPoRtAnT'}, set(mails[0].tags))

        another_mail = MailBuilder().with_subject(
            'Mail with tags').build_input_mail()
        self.add_mail_to_inbox(another_mail)
        self.post_tags(another_mail.ident, self._tags_json(['IMPORTANT']))
        mails = self.get_mails_by_tag('IMPORTANT')
        self.assertEquals(0, len(mails))
        mails = self.get_mails_by_tag('ImPoRtAnT')
        self.assertEquals(2, len(mails))
        self.assertEquals({'ImPoRtAnT'}, set(mails[0].tags))
        self.assertEquals({'ImPoRtAnT'}, set(mails[1].tags))
コード例 #16
0
    def test_empty_tags_are_not_allowed(self):
        mail = MailBuilder().with_subject('Mail with tags').build_input_mail()
        self.add_mail_to_inbox(mail)

        self.post_tags(mail.ident, self._tags_json(['tag1', '   ']))

        mail = self.get_mail(mail.ident)

        self.assertEquals(mail['tags'], ['tag1'])
コード例 #17
0
    def test_mark_single_as_unread(self):
        input_mail = MailBuilder().build_input_mail()
        mail = yield self.add_mail_to_inbox(input_mail)
        yield self.mark_many_as_read([mail.ident])

        yield self.mark_many_as_unread([mail.ident])
        result = (yield self.get_mails_by_tag('inbox'))[0]

        self.assertNotIn('read', result.status)
コード例 #18
0
    def test_put_creates_a_draft_if_it_does_not_exist(self):
        mail = MailBuilder().with_subject('A new draft').build_json()
        print '\nAdding mail\n'
        yield self.put_mail(mail)[0]
        print '\nAdded mail\n'
        mails = yield self.get_mails_by_tag('drafts')
        print '\ngot mails by tag\n'

        self.assertEquals('A new draft', mails[0].subject)
コード例 #19
0
    def test_TO_CC_and_BCC_fields_are_being_searched(self):
        input_mail = MailBuilder().with_tags(['important']).build_input_mail()
        yield self.add_mail_to_inbox(input_mail)

        contacts = yield self.get_contacts(query='recipient')

        self.assertTrue('*****@*****.**' in contacts)
        self.assertTrue('*****@*****.**' in contacts)
        self.assertTrue('*****@*****.**' in contacts)
コード例 #20
0
    def test_mark_many_mails_as_read(self):
        input_mail = MailBuilder().build_input_mail()
        input_mail2 = MailBuilder().build_input_mail()

        yield self.add_mail_to_inbox(input_mail)
        yield self.add_mail_to_inbox(input_mail2)

        mails = yield self.get_mails_by_tag('inbox')

        self.assertNotIn('read', mails[0].status)
        self.assertNotIn('read', mails[1].status)

        yield self.mark_many_as_read([mails[0].ident, mails[1].ident])

        mails = yield self.get_mails_by_tag('inbox')

        self.assertIn('read', mails[0].status)
        self.assertIn('read', mails[1].status)
コード例 #21
0
    def test_tags_with_multiple_words_are_searchable(self):
        input_mail = MailBuilder().build_input_mail()
        mail = yield self.add_mail_to_inbox(input_mail)
        yield self.mail_service.update_tags(mail.ident, ['one tag four words'])

        first_page = yield self.get_mails_by_tag('"one tag four words"',
                                                 page=1,
                                                 window=1)

        self.assertEqual(len(first_page), 1)
コード例 #22
0
    def test_that_default_tags_are_ignorable(self):
        input_mail = MailBuilder().build_input_mail()
        mail = yield self.add_mail_to_inbox(input_mail)
        yield self.mail_service.update_tags(mail.ident, ['sometag'])

        all_tags = yield self.get_tags(skipDefaultTags=["true"])

        all_tag_names = [t['name'] for t in all_tags]
        self.assertEqual(1, len(all_tag_names))
        self.assertTrue('sometag' in all_tag_names)
コード例 #23
0
    def test_mark_many_mails_as_read(self):
        input_mail = MailBuilder().build_input_mail()
        input_mail2 = MailBuilder().build_input_mail()

        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(input_mail2)

        mails = self.get_mails_by_tag('inbox')

        self.assertNotIn('read', mails[0].status)
        self.assertNotIn('read', mails[1].status)

        response = self.mark_many_as_read([input_mail.ident, input_mail2.ident])
        self.assertEquals(200, response.code)

        mails = self.get_mails_by_tag('inbox')

        self.assertIn('read', mails[0].status)
        self.assertIn('read', mails[1].status)
コード例 #24
0
    def test_store_and_load_draft(self):
        input_mail = MailBuilder().with_body(
            'some test text').build_input_mail()

        stored_draft = yield self.draft_service.create_draft(input_mail)

        draft = yield self.mail_store.get_mail(stored_draft.ident,
                                               include_body=True)

        self.assertEqual('some test text', draft.body)
コード例 #25
0
    def test_FROM_address_is_being_searched(self):
        input_mail = MailBuilder().with_tags(['important']).build_input_mail()
        self.add_mail_to_inbox(input_mail)

        d = self.get_contacts(query='Sender')

        def _assert(contacts):
            self.assertIn('Formatted Sender <*****@*****.**>', contacts)

        d.addCallback(_assert)
        return d
コード例 #26
0
    def test_add_tag_to_an_inbox_mail_and_query(self):
        mail = MailBuilder().with_subject('Mail with tags').build_input_mail()
        self.add_mail_to_inbox(mail)

        self.post_tags(mail.ident, self._tags_json(['IMPORTANT']))

        mails = self.get_mails_by_tag('inbox')
        self.assertEquals({'IMPORTANT'}, set(mails[0].tags))

        mails = self.get_mails_by_tag('IMPORTANT')
        self.assertEquals('Mail with tags', mails[0].subject)
コード例 #27
0
    def test_mark_single_as_read(self):
        input_mail = MailBuilder().build_input_mail()
        self.add_mail_to_inbox(input_mail)

        mails = self.get_mails_by_tag('inbox')
        self.assertNotIn('read', mails[0].status)

        self.mark_many_as_read([input_mail.ident])

        mails = self.get_mails_by_tag('inbox')
        self.assertIn('read', mails[0].status)
コード例 #28
0
    def test_that_default_tags_are_ignorable(self):
        input_mail = MailBuilder().with_tags(['sometag']).build_input_mail()
        self.add_mail_to_inbox(input_mail)

        d = self.get_tags(skipDefaultTags=["true"])

        def _assert(all_tags):
            all_tag_names = [t['name'] for t in all_tags]
            self.assertEqual(1, len(all_tag_names))
            self.assertTrue('sometag' in all_tag_names)
        d.addCallback(_assert)
        return d
コード例 #29
0
def add_mail_to_user_inbox(context, username):
    subject = 'Hi! This the subject %s' % uuid4()

    input_mail = MailBuilder().with_subject(subject).build_input_mail()

    context.multi_user_client.add_mail_to_user_inbox(input_mail, username)
    wait_for_condition(context,
                       lambda _: context.multi_user_client.account_for(
                           username).search_engine.search(subject)[1] > 0,
                       poll_frequency=0.1)

    context.last_subject = subject
コード例 #30
0
    def test_mark_mixed_status_as_read(self):
        input_mail = MailBuilder().with_subject('first').build_input_mail()
        input_mail2 = MailBuilder().with_subject('second').build_input_mail()

        yield self.add_mail_to_inbox(input_mail)
        mail2 = yield self.add_mail_to_inbox(input_mail2)
        yield self.mark_many_as_read([mail2.ident])

        mails = yield self.get_mails_by_tag('inbox')

        read_mails = filter(lambda x: 'read' in x.status, mails)
        unread_mails = filter(lambda x: 'read' not in x.status, mails)
        self.assertEquals(1, len(unread_mails))
        self.assertEquals(1, len(read_mails))

        yield self.mark_many_as_read([mails[0].ident, mails[1].ident])

        mails = yield self.get_mails_by_tag('inbox')

        self.assertIn('read', mails[0].status)
        self.assertIn('read', mails[1].status)
コード例 #31
0
    def test_deduplication_on_same_mail_address_using_largest(self):
        input_mail = MailBuilder().with_tags(['important']).with_from('*****@*****.**').build_input_mail()

        formatted_input_mail = MailBuilder().with_tags(['important'])
        formatted_input_mail.with_to('Recipient Principal <*****@*****.**>')
        formatted_input_mail.with_cc('Recipient Copied <*****@*****.**>')
        formatted_input_mail.with_bcc('Recipient Carbon <*****@*****.**>')
        formatted_input_mail = formatted_input_mail.build_input_mail()

        yield self.add_mail_to_inbox(input_mail)
        yield self.add_mail_to_inbox(formatted_input_mail)

        contacts = yield self.get_contacts(query='Recipient')

        self.assertEquals(4, len(contacts))
        self.assertTrue('Recipient Copied <*****@*****.**>' in contacts)
        self.assertTrue('Recipient Carbon <*****@*****.**>' in contacts)
コード例 #32
0
    def test_deduplication_on_same_mail_address_using_largest(self):
        input_mail = MailBuilder().with_tags(['important']).build_input_mail()

        formatted_input_mail = MailBuilder().with_tags(['important'])
        formatted_input_mail.with_to('Recipient Principal <*****@*****.**>')
        formatted_input_mail.with_cc('Recipient Copied <*****@*****.**>')
        formatted_input_mail.with_bcc('Recipient Carbon <*****@*****.**>')
        formatted_input_mail = formatted_input_mail.build_input_mail()

        self.add_mail_to_inbox(input_mail)
        self.add_mail_to_inbox(formatted_input_mail)

        d = self.get_contacts(query='Recipient')

        def _assert(contacts):
            self.assertEquals(3, len(contacts))
            self.assertTrue('Recipient Principal <*****@*****.**>' in contacts)
            self.assertTrue('Recipient Copied <*****@*****.**>' in contacts)
            self.assertTrue('Recipient Carbon <*****@*****.**>' in contacts)
        d.addCallback(_assert)
        return d