summaryrefslogtreecommitdiff
path: root/service/test/unit/adapter
diff options
context:
space:
mode:
authormnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 18:24:52 +0100
committermnandri <mnandri@eunglick.corporate.thoughtworks.com>2015-12-18 18:59:29 +0100
commit8b61b34f1ed71c04afbeeb45f08a65d35a18423d (patch)
treeb0afa8b8004f541e952745e57548fc613a043ce9 /service/test/unit/adapter
parentb73185d27fe5d59d64b0759c1efbbcdf89086d11 (diff)
adapting mail controllers POST and PUT to work with attachements
Issue #548
Diffstat (limited to 'service/test/unit/adapter')
-rw-r--r--service/test/unit/adapter/test_mail.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 5c5d4c59..006bde77 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -14,6 +14,9 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+from email.mime.nonmultipart import MIMENonMultipart
+from email.mime.multipart import MIMEMultipart
+
from twisted.trial import unittest
import pixelated.support.date
@@ -50,6 +53,23 @@ def multipart_mail_dict():
}
+def with_attachment_mail_dict():
+ return {
+ 'attachments': [{'content-type': 'text/plain', 'filename': 'ayoyo.txt', 'raw': 'Hamburg Ayoyoyooooo!!!', 'id': 'some_attachment_id'},
+ {'content-type': 'text/html', 'filename': 'hello.html', 'raw': '<p>Hello html Hamburg!</p>', 'id': 'other_attachment_id'}],
+ 'body': [{'content-type': 'plain', 'raw': 'Hello world!'},
+ {'content-type': 'html', 'raw': '<p>Hello html world!</p>'}],
+ 'header': {
+ 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'],
+ 'to': ['to@pixelated.org', 'anotherto@pixelated.org'],
+ 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'],
+ 'subject': 'Oi',
+ },
+ 'ident': '',
+ 'tags': ['sent']
+ }
+
+
class InputMailTest(unittest.TestCase):
def test_to_mime_multipart_should_add_blank_fields(self):
@@ -120,3 +140,17 @@ class InputMailTest(unittest.TestCase):
self.assertRegexpMatches(mime_multipart.as_string(), part_one)
self.assertRegexpMatches(mime_multipart.as_string(), part_two)
+
+ def test_raw_with_attachment_data(self):
+ input_mail = InputMail.from_dict(with_attachment_mail_dict())
+
+ attachment = MIMENonMultipart('text', 'plain', Content_Disposition='attachment; filename=ayoyo.txt')
+ attachment.set_payload('Hello World')
+ mail = MIMEMultipart()
+ mail.attach(attachment)
+
+ part_one = 'Content-Type: text/plain; Content-Disposition="attachment; filename=ayoyo.txt"\nMIME-Version: 1.0\n\nHamburg Ayoyoyooooo!!!'
+ part_two = 'Content-Type: text/html; Content-Disposition="attachment; filename=hello.html"\nMIME-Version: 1.0\n\n<p>Hello html Hamburg!</p>'
+
+ self.assertRegexpMatches(input_mail.raw, part_one)
+ self.assertRegexpMatches(input_mail.raw, part_two)