From e5d718f982e0cd3fc85da00d3abdccce1907e488 Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Wed, 2 Sep 2015 12:35:33 +0200 Subject: Download attachments from mail store instead of querier - Issue #435 - Improved error handling of attachment resource --- .../test/integration/test_retrieve_attachment.py | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'service/test/integration/test_retrieve_attachment.py') diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py index 1cf8006f..e7e8670d 100644 --- a/service/test/integration/test_retrieve_attachment.py +++ b/service/test/integration/test_retrieve_attachment.py @@ -13,6 +13,9 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . +from email.mime.application import MIMEApplication +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText from test.support.integration.soledad_test_base import SoledadTestBase from twisted.internet import defer @@ -22,16 +25,26 @@ class RetrieveAttachmentTest(SoledadTestBase): @defer.inlineCallbacks def test_attachment_content_is_retrieved(self): - ident = 'F4E99C1CEC4D300A4223A96CCABBE0304BDBC31C550A5A03E207A5E4C3C71A22' - attachment_dict = {'content-disposition': 'attachment', - 'content-transfer-encoding': '', - 'type': 'cnt', - 'raw': 'cGVxdWVubyBhbmV4byA6RAo=', - 'phash': ident, - 'content_type': 'text/plain; charset=US-ASCII; name="attachment_pequeno.txt"'} + attachment_id, input_mail = self._create_mail_with_attachment() + yield self.mail_store.add_mail('INBOX', input_mail.as_string()) - yield self.add_document_to_soledad(attachment_dict) + attachment, req = yield self.get_attachment(attachment_id, 'base64') - attachment = yield self.get_attachment(ident, 'base64') + self.assertEqual(200, req.code) + self.assertEquals('pretend to be binary attachment data', attachment) - self.assertEquals('pequeno anexo :D\n', attachment) + def _create_mail_with_attachment(self): + input_mail = MIMEMultipart() + input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8')) + attachment = MIMEApplication('pretend to be binary attachment data') + attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt') + input_mail.attach(attachment) + attachment_id = 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A' + return attachment_id, input_mail + + @defer.inlineCallbacks + def test_attachment_error_returned_if_id_not_found(self): + attachment, req = yield self.get_attachment('invalid attachment id', 'base64') + + self.assertEqual(404, req.code) + self.assertIsNone(attachment) -- cgit v1.2.3