forked from mirror/django-mailbox
Adding basic integration tests.
This commit is contained in:
parent
e5d36cbabf
commit
634f2f4b26
3 changed files with 92 additions and 13 deletions
29
.travis.yml
29
.travis.yml
|
|
@ -1,24 +1,27 @@
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
python:
|
python:
|
||||||
- "2.6"
|
- '2.6'
|
||||||
- "2.7"
|
- '2.7'
|
||||||
- "3.3"
|
- '3.3'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
matrix:
|
||||||
- DJANGO=1.4.14
|
- DJANGO=1.4.14
|
||||||
- DJANGO=1.5.9
|
- DJANGO=1.5.9
|
||||||
- DJANGO=1.6.8
|
- DJANGO=1.6.8
|
||||||
- DJANGO=1.7.1
|
- DJANGO=1.7.1
|
||||||
|
global:
|
||||||
|
- secure: aswHU7pQroGM+GHoYlhXzzk2FYfqxXJORjqXPsbgoHAIu4Bssaj8+YAzIcdy3j9kSt4I8VBpjnn8H/wzQXki75JBZOosQrIeMK018+uR+ZMONBLqDYW/N7EJHLgZt9QXxQNKeZygrD4GN/Dc4gLHGvPQC/RfPuuHcnF0Liaahoo=
|
||||||
|
- secure: RZ6M6984P885GRoyx9n/WCCWGoFAzYpS8sZkXu3e/HK9oPXfaM2IEHjkq03jIC/FcWn/QMtFjOUBqQU94rnqdivFdFkeZHk1WUQgC0hztH3Qhh9zu2PNIrYUDpVD5dJqBpprWbSwFP8yNsJlP9A2RUubTlZblKHuaBhhiuNN+kU=
|
||||||
|
- secure: gsAAl/RaTodLJDHWOuHZWtooa9/psyXBONF7ElZOTki3WvH+KugtjuXn3pXBGbUhvGqd5qfgPqX7WQOFP9KTdkXBbkU20rCHLh3SV8V2vRkGFAFiGPBTFfSA83zFNMvmgEnTww4OzYsfs4wHTEyxBeQkggnB5bXEvqkFVrHBjuQ=
|
||||||
|
- secure: mMa7UUt+CQDB52fGM1T3oRL67OzQzRIc+BQCOqUEUhBV7p5g7Y1Hv6NTdVZTvK16x3DsP+5kFNd1v7rsTFw2qzP3hOxIv2BtMPuSzZdnN85Zd/nGwnztxzj/rqw7TMBaYvIdEZZbpRF/K0p0Xr6LJK2s9UkPXPUaLqly7kNi360=
|
||||||
matrix:
|
matrix:
|
||||||
exclude:
|
exclude:
|
||||||
- env: DJANGO=1.4.14
|
- env: DJANGO=1.4.14
|
||||||
python: "3.3"
|
python: '3.3'
|
||||||
- env: DJANGO=1.7.1
|
- env: DJANGO=1.7.1
|
||||||
python: "2.6"
|
python: '2.6'
|
||||||
install:
|
install:
|
||||||
- pip install -q Django==$DJANGO --use-mirrors
|
- pip install -q Django==$DJANGO --use-mirrors
|
||||||
- pip install -q -e . --use-mirrors
|
- pip install -q -e . --use-mirrors
|
||||||
script:
|
script:
|
||||||
- python setup.py test
|
- python setup.py test
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
import email
|
import email
|
||||||
import os.path
|
import os.path
|
||||||
|
import time
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from django_mailbox import models
|
from django_mailbox import models
|
||||||
from django_mailbox.models import Mailbox, Message
|
from django_mailbox.models import Mailbox, Message
|
||||||
|
|
||||||
|
|
||||||
|
class EmailIntegrationTimeout(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_email_as_text(name):
|
def get_email_as_text(name):
|
||||||
with open(
|
with open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
|
|
@ -32,8 +39,32 @@ class EmailMessageTestCase(TestCase):
|
||||||
self._TEXT_STORED_MIMETYPES = models.TEXT_STORED_MIMETYPES
|
self._TEXT_STORED_MIMETYPES = models.TEXT_STORED_MIMETYPES
|
||||||
|
|
||||||
self.mailbox = Mailbox.objects.create(from_email='from@example.com')
|
self.mailbox = Mailbox.objects.create(from_email='from@example.com')
|
||||||
|
|
||||||
|
self.test_account = os.environ['EMAIL_ACCOUNT']
|
||||||
|
self.test_password = os.environ['EMAIL_PASSWORD']
|
||||||
|
self.test_smtp_server = os.environ['EMAIL_SMTP_SERVER']
|
||||||
|
self.test_from_email = 'nobody@nowhere.com'
|
||||||
|
|
||||||
|
self.maximum_wait_seconds = 60 * 5
|
||||||
|
|
||||||
|
settings.EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
|
settings.EMAIL_HOST = self.test_smtp_server
|
||||||
|
settings.EMAIL_PORT = 587
|
||||||
|
settings.EMAIL_HOST_USER = self.test_account
|
||||||
|
settings.EMAIL_HOST_PASSWORD = self.test_password
|
||||||
|
settings.EMAIL_USE_TLS = True
|
||||||
super(EmailMessageTestCase, self).setUp()
|
super(EmailMessageTestCase, self).setUp()
|
||||||
|
|
||||||
|
def _get_new_messages(self, mailbox):
|
||||||
|
maximum_wait = time.time() + self.maximum_wait_seconds
|
||||||
|
while True:
|
||||||
|
if time.time() > maximum_wait:
|
||||||
|
raise EmailIntegrationTimeout()
|
||||||
|
messages = self.mailbox.get_new_mail()
|
||||||
|
if messages:
|
||||||
|
return messages
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
def _get_email_as_text(self, name):
|
def _get_email_as_text(self, name):
|
||||||
with open(
|
with open(
|
||||||
os.path.join(
|
os.path.join(
|
||||||
|
|
|
||||||
45
django_mailbox/tests/test_integration_imap.py
Normal file
45
django_mailbox/tests/test_integration_imap.py
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
import os
|
||||||
|
import urllib
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.core.mail import EmailMultiAlternatives
|
||||||
|
|
||||||
|
from django_mailbox.models import Mailbox
|
||||||
|
from django_mailbox.tests.base import EmailMessageTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestImap(EmailMessageTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.test_imap_server = (
|
||||||
|
os.environ['EMAIL_IMAP_SERVER']
|
||||||
|
)
|
||||||
|
self.mailbox = Mailbox.objects.create(
|
||||||
|
name='Integration Test Imap',
|
||||||
|
uri=self.get_connection_string()
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_connection_string(self):
|
||||||
|
return "imap+ssl://{account}:{password}@{server}".format(
|
||||||
|
account=urllib.quote(self.test_account),
|
||||||
|
password=urllib.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,
|
||||||
|
text_content,
|
||||||
|
self.test_from_email,
|
||||||
|
[
|
||||||
|
self.test_account,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
msg.send()
|
||||||
|
|
||||||
|
messages = self.get_new_messages()
|
||||||
|
|
||||||
|
self.assertEqual(1, len(messages))
|
||||||
|
self.assertEqual(messages[0].subject, arbitrary_identifier)
|
||||||
|
self.assertEqual(messages[0].text, text_content)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue