mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Adding tests.
This commit is contained in:
parent
19f64256b6
commit
0eb63b44cf
6 changed files with 162 additions and 2 deletions
12
.travis.yml
Normal file
12
.travis.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
language: python
|
||||
python:
|
||||
- "2.6"
|
||||
- "2.7"
|
||||
env:
|
||||
- DJANGO=1.3.1
|
||||
- DJANGO=1.4
|
||||
install:
|
||||
- pip install -q Django==$DJANGO --use-mirrors
|
||||
- pip install -q -e . --use-mirrors
|
||||
script:
|
||||
- python setup.py test
|
||||
36
django_mailbox/runtests.py
Normal file
36
django_mailbox/runtests.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
|
||||
from os.path import dirname, abspath
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
if not settings.configured:
|
||||
settings.configure(
|
||||
DATABASES={
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
},
|
||||
},
|
||||
INSTALLED_APPS=[
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django_mailbox',
|
||||
]
|
||||
)
|
||||
|
||||
from django.test.simple import DjangoTestSuiteRunner
|
||||
|
||||
|
||||
def runtests(*test_args):
|
||||
if not test_args:
|
||||
test_args = ['django_mailbox']
|
||||
parent = dirname(abspath(__file__))
|
||||
sys.path.insert(0, parent)
|
||||
runner = DjangoTestSuiteRunner(verbosity=1, interactive=True)
|
||||
failures = runner.run_tests(test_args)
|
||||
sys.exit(failures)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
runtests(*sys.argv[1:])
|
||||
65
django_mailbox/tests/__init__.py
Normal file
65
django_mailbox/tests/__init__.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import email
|
||||
import os.path
|
||||
import shutil
|
||||
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
|
||||
from django_mailbox.models import Mailbox
|
||||
|
||||
class TestProcessMessage(TestCase):
|
||||
def _get_email_object(self, name):
|
||||
with open(os.path.join(os.path.dirname(__file__), name), 'r') as f:
|
||||
return email.message_from_string(
|
||||
f.read()
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
shutil.rmtree('mailbox_attachments')
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def test_message_without_attachments(self):
|
||||
message = self._get_email_object('generic_message.eml')
|
||||
|
||||
mailbox = Mailbox.objects.create()
|
||||
msg = mailbox.process_incoming_message(message)
|
||||
|
||||
self.assertEqual(
|
||||
msg.mailbox,
|
||||
mailbox
|
||||
)
|
||||
self.assertEqual(msg.subject, 'Message Without Attachment')
|
||||
self.assertEqual(
|
||||
msg.message_id,
|
||||
'<CAMdmm+hGH8Dgn-_0xnXJCd=PhyNAiouOYm5zFP0z-foqTO60zA@mail.gmail.com>'
|
||||
)
|
||||
self.assertEqual(
|
||||
msg.from_header,
|
||||
'Adam Coddington <test@adamcoddington.net>',
|
||||
)
|
||||
self.assertEqual(
|
||||
msg.to_header,
|
||||
'Adam Coddington <test@adamcoddington.net>',
|
||||
)
|
||||
|
||||
def test_message_with_attachments(self):
|
||||
message = self._get_email_object('message_with_attachment.eml')
|
||||
|
||||
mailbox = Mailbox.objects.create()
|
||||
msg = mailbox.process_incoming_message(message)
|
||||
|
||||
expected_count = 1
|
||||
actual_count = msg.attachments.count()
|
||||
|
||||
self.assertEquals(
|
||||
expected_count,
|
||||
actual_count,
|
||||
)
|
||||
|
||||
attachment = msg.attachments.all()[0]
|
||||
self.assertEquals(
|
||||
os.path.basename(attachment.document.name),
|
||||
'heart.png',
|
||||
)
|
||||
14
django_mailbox/tests/generic_message.eml
Normal file
14
django_mailbox/tests/generic_message.eml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
MIME-Version: 1.0
|
||||
Received: by 10.221.0.211 with HTTP; Sun, 20 Jan 2013 11:53:53 -0800 (PST)
|
||||
X-Originating-IP: [24.22.122.177]
|
||||
Date: Sun, 20 Jan 2013 11:53:53 -0800
|
||||
Delivered-To: test@adamcoddington.net
|
||||
Message-ID: <CAMdmm+hGH8Dgn-_0xnXJCd=PhyNAiouOYm5zFP0z-foqTO60zA@mail.gmail.com>
|
||||
Subject: Message Without Attachment
|
||||
From: Adam Coddington <test@adamcoddington.net>
|
||||
To: Adam Coddington <test@adamcoddington.net>
|
||||
Content-Type: text/plain;
|
||||
charset="iso-8859-1"
|
||||
Content-Transfer-Encoding: 7bit
|
||||
|
||||
Hello there.
|
||||
28
django_mailbox/tests/message_with_attachment.eml
Normal file
28
django_mailbox/tests/message_with_attachment.eml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
MIME-Version: 1.0
|
||||
Received: by 10.221.0.211 with HTTP; Sun, 20 Jan 2013 12:07:07 -0800 (PST)
|
||||
X-Originating-IP: [24.22.122.177]
|
||||
Date: Sun, 20 Jan 2013 12:07:07 -0800
|
||||
Delivered-To: test@adamcoddington.net
|
||||
Message-ID: <CAMdmm+jYCgrxrekAxszmDnBjAytcBym-Ec+uM-+HEtzuKy=M_g@mail.gmail.com>
|
||||
Subject: Message With Attachment
|
||||
From: Adam Coddington <test@adamcoddington.net>
|
||||
To: Adam Coddington <test@adamcoddington.net>
|
||||
Content-Type: multipart/mixed; boundary=047d7b33dd729737fe04d3bde348
|
||||
|
||||
--047d7b33dd729737fe04d3bde348
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
|
||||
This message has an attachment.
|
||||
|
||||
--047d7b33dd729737fe04d3bde348
|
||||
Content-Type: image/png; name="heart.png"
|
||||
Content-Disposition: attachment; filename="heart.png"
|
||||
Content-Transfer-Encoding: base64
|
||||
X-Attachment-Id: f_hc6mair60
|
||||
|
||||
iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAFoTx1HAAAAzUlEQVQoz32RWxXDIBBEr4NIQEIl
|
||||
ICESkFAJkRAJSIgEpEQCEqYfu6QUkn7sCcyDGQiSACKSKCAkGwBJwhDwZQNMEiYAIBdQvk7rfaHf
|
||||
AO8NBJwCxTGhtFgTHVNaNaJeWFu44AXEHzKCktc7zZ0vss+bMoHSiM2b9mQoX1eZCgGqnWskY3gi
|
||||
XXAAxb8BqFiUgBNY7k49Tu/kV7UKPsefrjEOT9GmghYzrk9V03pjDGYKj3d0c06dKZkpTboRaD9o
|
||||
B+1m2m81d2Az948xzgdjLaFe95e83AAAAABJRU5ErkJggg==
|
||||
--047d7b33dd729737fe04d3bde348--
|
||||
9
setup.py
9
setup.py
|
|
@ -1,12 +1,17 @@
|
|||
from distutils.core import setup
|
||||
from setuptools import setup
|
||||
|
||||
tests_require=['django']
|
||||
|
||||
setup(
|
||||
name='django-mailbox',
|
||||
version='1.5',
|
||||
version='1.6',
|
||||
url='http://bitbucket.org/latestrevision/django-mailbox/',
|
||||
description='Import mail from POP3, IMAP, local mailboxes or directly from Postfix or Exim4 into your Django application automatically.',
|
||||
author='Adam Coddington',
|
||||
author_email='me@adamcoddington.net',
|
||||
tests_require=tests_require,
|
||||
extras_require={'test': tests_require},
|
||||
test_suite='django_mailbox.runtests.runtests',
|
||||
classifiers=[
|
||||
'Framework :: Django',
|
||||
'Intended Audience :: Developers',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue