mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
This should allow Pull Requests to properly run all non-integration tests.
Squashed commit of the following:
commit a03e2a6592234e089d1fe9adc360b1e33a0c4b57
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 22:57:27 2015 -0700
Removing a dummy empty variable.
commit cd5964ab59
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 22:52:52 2015 -0700
Removing unused import.
commit 39b67b8562
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 22:52:35 2015 -0700
Use TestCase.skipTest.
commit 63d6dad73e
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 22:44:16 2015 -0700
Testing something out to make sure integration tests will fail.
commit 51f0cf44bf
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 22:38:50 2015 -0700
Adding unittest2 to requirements so we can skip tests on Python 2.6.
commit 3cc035f58b
Author: Adam Coddington <me@adamcoddington.net>
Date: Tue Jul 21 20:56:04 2015 -0700
Try skipping integration tests if not all environment variables are available.
70 lines
2 KiB
Python
70 lines
2 KiB
Python
import os
|
|
import uuid
|
|
|
|
from six.moves.urllib import parse
|
|
|
|
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.get('EMAIL_IMAP_SERVER')
|
|
)
|
|
|
|
required_settings = [
|
|
self.test_imap_server,
|
|
self.test_account,
|
|
self.test_password,
|
|
self.test_smtp_server,
|
|
self.test_from_email,
|
|
]
|
|
if not all(required_settings):
|
|
self.skipTest(
|
|
"Integration tests are not available without having "
|
|
"the the following environment variables set: "
|
|
"EMAIL_ACCOUNT, EMAIL_PASSWORD, EMAIL_SMTP_SERVER, "
|
|
"EMAIL_IMAP_SERVER."
|
|
)
|
|
|
|
self.mailbox = Mailbox.objects.create(
|
|
name='Integration Test Imap',
|
|
uri=self.get_connection_string()
|
|
)
|
|
self.arbitrary_identifier = str(uuid.uuid4())
|
|
|
|
def get_connection_string(self):
|
|
return "imap+ssl://{account}:{password}@{server}".format(
|
|
account=parse.quote(self.test_account),
|
|
password=parse.quote(self.test_password),
|
|
server=self.test_imap_server,
|
|
)
|
|
|
|
def test_get_imap_message(self):
|
|
text_content = 'This is some content'
|
|
msg = EmailMultiAlternatives(
|
|
self.arbitrary_identifier,
|
|
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
|
|
)
|
|
|
|
self.assertEqual(1, len(messages))
|
|
self.assertEqual(messages[0].subject, self.arbitrary_identifier)
|
|
self.assertEqual(messages[0].text, text_content)
|