forked from mirror/django-mailbox
Fixing test discovery, adding functionality allowing one to restict
message gathering (via the IMAP transport) to only messages matching a specified subject. Fixes #49.
This commit is contained in:
parent
634f2f4b26
commit
abad769fd6
4 changed files with 76 additions and 15 deletions
|
|
@ -2,3 +2,4 @@ from .test_mailbox import *
|
|||
from .test_message_flattening import *
|
||||
from .test_process_email import *
|
||||
from .test_transports import *
|
||||
from .test_integration_imap import *
|
||||
|
|
|
|||
|
|
@ -1,15 +1,21 @@
|
|||
import os
|
||||
import urllib
|
||||
import uuid
|
||||
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
|
||||
from django_mailbox.models import Mailbox
|
||||
from django_mailbox.tests.base import EmailMessageTestCase
|
||||
|
||||
|
||||
__all__ = ['TestImap']
|
||||
|
||||
|
||||
class TestImap(EmailMessageTestCase):
|
||||
def setUp(self):
|
||||
super(TestImap, self).setUp()
|
||||
self.test_imap_server = (
|
||||
os.environ['EMAIL_IMAP_SERVER']
|
||||
)
|
||||
|
|
@ -17,19 +23,25 @@ class TestImap(EmailMessageTestCase):
|
|||
name='Integration Test Imap',
|
||||
uri=self.get_connection_string()
|
||||
)
|
||||
self.arbitrary_identifier = str(uuid.uuid4())
|
||||
settings.DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT = (
|
||||
self.arbitrary_identifier
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
settings.DJANGO_MAILBOX_INTEGRATION_TESTING_SUBJECT = None
|
||||
|
||||
def get_connection_string(self):
|
||||
return "imap+ssl://{account}:{password}@{server}".format(
|
||||
account=urllib.quote(self.test_account),
|
||||
password=urllib.quote(self.test_password),
|
||||
account=parse.quote(self.test_account),
|
||||
password=parse.quote(self.test_password),
|
||||
server=self.test_imap_server,
|
||||
)
|
||||
|
||||
def test_get_imap_message(self):
|
||||
arbitrary_identifier = uuid.uuid4()
|
||||
text_content = 'This is some content'
|
||||
msg = EmailMultiAlternatives(
|
||||
arbitrary_identifier,
|
||||
self.arbitrary_identifier,
|
||||
text_content,
|
||||
self.test_from_email,
|
||||
[
|
||||
|
|
@ -38,8 +50,8 @@ class TestImap(EmailMessageTestCase):
|
|||
)
|
||||
msg.send()
|
||||
|
||||
messages = self.get_new_messages()
|
||||
messages = self._get_new_messages(self.mailbox)
|
||||
|
||||
self.assertEqual(1, len(messages))
|
||||
self.assertEqual(messages[0].subject, arbitrary_identifier)
|
||||
self.assertEqual(messages[0].subject, self.arbitrary_identifier)
|
||||
self.assertEqual(messages[0].text, text_content)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,49 @@
|
|||
import mock
|
||||
import six
|
||||
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from django_mailbox.tests.base import EmailMessageTestCase, get_email_as_text
|
||||
from django_mailbox.transports import ImapTransport, Pop3Transport
|
||||
|
||||
FAKE_UID_SEARCH_ANSWER = ('OK', ['18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44'])
|
||||
FAKE_UID_FETCH_SIZES = ('OK', ['1 (UID 18 RFC822.SIZE 58070000000)', '2 (UID 19 RFC822.SIZE 2593)'])
|
||||
FAKE_UID_FETCH_MSG = ('OK', [('1 (UID 18 RFC822 {5807}', get_email_as_text('generic_message.eml') ),])
|
||||
FAKE_UID_COPY_MSG = ('OK', ['[COPYUID 1 2 2] (Success)'])
|
||||
FAKE_LIST_ARCHIVE_FOLDERS_ANSWERS = ('OK', ['(\\HasNoChildren \\All) "/" "[Gmail]/All Mail"'])
|
||||
FAKE_UID_SEARCH_ANSWER = (
|
||||
'OK',
|
||||
[
|
||||
six.b(
|
||||
'18 19 20 21 22 23 24 25 26 27 28 29 '
|
||||
'30 31 32 33 34 35 36 37 38 39 40 41 42 43 44'
|
||||
)
|
||||
]
|
||||
)
|
||||
FAKE_UID_FETCH_SIZES = (
|
||||
'OK',
|
||||
[
|
||||
six.b('1 (UID 18 RFC822.SIZE 58070000000)'),
|
||||
six.b('2 (UID 19 RFC822.SIZE 2593)')
|
||||
]
|
||||
)
|
||||
FAKE_UID_FETCH_MSG = (
|
||||
'OK',
|
||||
[
|
||||
(
|
||||
six.b('1 (UID 18 RFC822 {5807}'),
|
||||
get_email_as_text('generic_message.eml')
|
||||
),
|
||||
]
|
||||
)
|
||||
FAKE_UID_COPY_MSG = (
|
||||
'OK',
|
||||
[
|
||||
six.b('[COPYUID 1 2 2] (Success)')
|
||||
]
|
||||
)
|
||||
FAKE_LIST_ARCHIVE_FOLDERS_ANSWERS = (
|
||||
'OK',
|
||||
[
|
||||
six.b('(\\HasNoChildren \\All) "/" "[Gmail]/All Mail"')
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
class IMAPTestCase(EmailMessageTestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue