1
0
Fork 1
mirror of https://github.com/coddingtonbear/django-mailbox.git synced 2026-07-10 06:48:19 +02:00
django-mailbox/django_mailbox/tests/test_integration_imap.py

54 lines
1.5 KiB
Python
Raw Normal View History

2015-04-11 23:42:14 -07:00
import os
import uuid
from six.moves.urllib import parse
2015-04-11 23:42:14 -07:00
from django.core.mail import EmailMultiAlternatives
from django_mailbox.models import Mailbox
from django_mailbox.tests.base import EmailMessageTestCase
__all__ = ['TestImap']
2015-04-11 23:42:14 -07:00
class TestImap(EmailMessageTestCase):
def setUp(self):
super(TestImap, self).setUp()
2015-04-11 23:42:14 -07:00
self.test_imap_server = (
os.environ['EMAIL_IMAP_SERVER']
)
self.mailbox = Mailbox.objects.create(
name='Integration Test Imap',
uri=self.get_connection_string()
)
self.arbitrary_identifier = str(uuid.uuid4())
2015-04-11 23:42:14 -07:00
def get_connection_string(self):
return "imap+ssl://{account}:{password}@{server}".format(
account=parse.quote(self.test_account),
password=parse.quote(self.test_password),
2015-04-11 23:42:14 -07:00
server=self.test_imap_server,
)
def test_get_imap_message(self):
text_content = 'This is some content'
msg = EmailMultiAlternatives(
self.arbitrary_identifier,
2015-04-11 23:42:14 -07:00
text_content,
self.test_from_email,
[
self.test_account,
]
)
msg.send()
messages = self._get_new_messages(
self.mailbox,
condition=lambda m: m['subject'] == self.arbitrary_identifier
)
2015-04-11 23:42:14 -07:00
self.assertEqual(1, len(messages))
self.assertEqual(messages[0].subject, self.arbitrary_identifier)
2015-04-11 23:42:14 -07:00
self.assertEqual(messages[0].text, text_content)