示例#1
0
 def test_raise(self):
     try:
         Envelope()._raise(RuntimeError, u'ęóąśłżźćń')
     except RuntimeError as exc:
         assert exc.args[0] == encoded(u'ęóąśłżźćń', 'utf-8')
     except:
         raise
     else:
         assert 'RuntimeError not raised'
示例#2
0
 def test_raise(self):
     try:
         Envelope()._raise(RuntimeError, u"ęóąśłżźćń")
     except RuntimeError as exc:
         assert exc.args[0] == encoded(u"ęóąśłżźćń", "utf-8")
     except:
         raise
     else:
         assert "RuntimeError not raised"
示例#3
0
 def test_raise(self):
     try:
         Envelope()._raise(RuntimeError, u'ęóąśłżźćń')
     except RuntimeError as exc:
         assert exc.args[0] == encoded(u'ęóąśłżźćń', 'utf-8')
     except:
         raise
     else:
         assert 'RuntimeError not raised'
示例#4
0
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        assert len(envelope._parts) == 7

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' %\
            os.path.basename(encoded(_something, 'utf-8'))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)
示例#5
0
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        assert len(envelope._parts) == 7

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' %\
            os.path.basename(encoded(_something, 'utf-8'))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)
示例#6
0
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix=".jpg")
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix=".mp3")
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix=".pdf")
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix=".something", prefix=u"ęóąśłżźćń")
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix=".txt")
        envelope.add_attachment(_octet, mimetype="application/octet-stream")

        assert len(envelope._parts) == 7

        assert envelope._parts[0][0] == "text/plain"
        assert envelope._parts[1][0] == "text/html"

        assert envelope._parts[2][0] == "image/jpeg"
        assert envelope._parts[2][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == "audio/mpeg"
        assert envelope._parts[3][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == "application/pdf"
        assert envelope._parts[4][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == "application/octet-stream"
        assert envelope._parts[5][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(
            encoded(_something, "utf-8")
        )

        assert envelope._parts[6][0] == "application/octet-stream"
        assert envelope._parts[6][1]["Content-Disposition"] == 'attachment; filename="%s"' % os.path.basename(_octet)
示例#7
0
    def test_to_mime_message_unicode(self):
        msg = {
            'to_addr': ('*****@*****.**', u'ęóąśłżźćń'),
            'from_addr': ('*****@*****.**', u'ęóąśłżźćń'),
            'subject': u'ęóąśłżźćń',
            'html_body': u'ęóąśłżźćń',
            'text_body': u'ęóąśłżźćń',
            'cc_addr': [
                ('*****@*****.**', u'ęóąśłżźćń')
            ],
            'bcc_addr': [
                ('*****@*****.**', u'ęóąśłżźćń')
            ],
            'headers': {
                'X-Test': u'ęóąśłżźćń'
            },
            'charset': 'utf-8'
        }

        envelope = Envelope(**msg)

        mime_msg = envelope.to_mime_message()
        assert mime_msg is not None

        assert mime_msg['Subject'] == encoded(msg['subject'], 'utf-8')
        assert mime_msg['To'] == encoded(u'ęóąśłżźćń <*****@*****.**>',
                                         'utf-8')
        assert mime_msg['From'] == encoded(u'ęóąśłżźćń <*****@*****.**>',
                                           'utf-8')

        cc_header = u'ęóąśłżźćń <*****@*****.**>'
        assert mime_msg['CC'] == encoded(cc_header, 'utf-8')

        bcc_header = u'ęóąśłżźćń <*****@*****.**>'
        assert mime_msg['BCC'] == encoded(bcc_header, 'utf-8')

        assert mime_msg['X-Test'] == encoded(msg['headers']['X-Test'], 'utf-8')

        mime_msg_parts = [part for part in mime_msg.walk()]
        assert len(mime_msg_parts) == 3
        text_part, html_part = mime_msg_parts[1:]

        assert text_part.get_content_type() == 'text/plain'
        assert text_part.get_payload(decode=True) == msg['text_body'].encode('utf-8')

        assert html_part.get_content_type() == 'text/html'
        assert html_part.get_payload(decode=True) == msg['html_body'].encode('utf-8')
示例#8
0
    def test_to_mime_message_unicode(self):
        msg = {
            'to_addr': ('*****@*****.**', u'ęóąśłżźćń'),
            'from_addr': ('*****@*****.**', u'ęóąśłżźćń'),
            'subject': u'ęóąśłżźćń',
            'html_body': u'ęóąśłżźćń',
            'text_body': u'ęóąśłżźćń',
            'cc_addr': [('*****@*****.**', u'ęóąśłżźćń')],
            'bcc_addr': [('*****@*****.**', u'ęóąśłżźćń')],
            'headers': {
                'X-Test': u'ęóąśłżźćń'
            },
            'charset': 'utf-8'
        }

        envelope = Envelope(**msg)

        mime_msg = envelope.to_mime_message()
        assert mime_msg is not None

        assert mime_msg['Subject'] == encoded(msg['subject'], 'utf-8')
        assert mime_msg['To'] == encoded(u'ęóąśłżźćń <*****@*****.**>',
                                         'utf-8')
        assert mime_msg['From'] == encoded(u'ęóąśłżźćń <*****@*****.**>',
                                           'utf-8')

        cc_header = u'ęóąśłżźćń <*****@*****.**>'
        assert mime_msg['CC'] == encoded(cc_header, 'utf-8')

        bcc_header = u'ęóąśłżźćń <*****@*****.**>'
        assert mime_msg['BCC'] == encoded(bcc_header, 'utf-8')

        assert mime_msg['X-Test'] == encoded(msg['headers']['X-Test'], 'utf-8')

        mime_msg_parts = [part for part in mime_msg.walk()]
        assert len(mime_msg_parts) == 3
        text_part, html_part = mime_msg_parts[1:]

        assert text_part.get_content_type() == 'text/plain'
        assert text_part.get_payload(
            decode=True) == msg['text_body'].encode('utf-8')

        assert html_part.get_content_type() == 'text/html'
        assert html_part.get_payload(
            decode=True) == msg['html_body'].encode('utf-8')
示例#9
0
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        # Attach from string
        envelope.add_attachment('file1.txt', data=LOREM, mimetype='text/plain')

        # Attach from stream
        sio = io.BytesIO(LOREM)
        envelope.add_attachment('file2.txt', data=sio, mimetype='text/plain')

        assert len(envelope._parts) == 9

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' %\
            os.path.basename(encoded(_something, 'utf-8'))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename(_octet)

        assert envelope._parts[7][0] == 'text/plain'
        assert envelope._parts[7][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename('file1.txt')
        assert envelope._parts[7][1].get_payload(decode=True) == LOREM

        assert envelope._parts[8][0] == 'text/plain'
        assert envelope._parts[8][1]['Content-Disposition'] ==\
            'attachment; filename="%s"' % os.path.basename('file2.txt')
        assert envelope._parts[8][1].get_payload(decode=True) == LOREM
示例#10
0
    def test_add_attachment(self):
        msg = self._dummy_message()
        envelope = Envelope(**msg)

        _jpg = self._tempfile(suffix='.jpg')
        envelope.add_attachment(_jpg)

        _mp3 = self._tempfile(suffix='.mp3')
        envelope.add_attachment(_mp3)

        _pdf = self._tempfile(suffix='.pdf')
        envelope.add_attachment(_pdf)

        _something = self._tempfile(suffix='.something', prefix=u'ęóąśłżźćń')
        envelope.add_attachment(_something)

        _octet = self._tempfile(suffix='.txt')
        envelope.add_attachment(_octet, mimetype='application/octet-stream')

        # Attach from string
        envelope.add_attachment('file1.txt', data=LOREM, mimetype='text/plain')

        # Attach from stream
        sio = io.BytesIO(LOREM)
        envelope.add_attachment('file2.txt', data=sio, mimetype='text/plain')

        assert len(envelope._parts) == 9

        assert envelope._parts[0][0] == 'text/plain'
        assert envelope._parts[1][0] == 'text/html'

        assert envelope._parts[2][0] == 'image/jpeg'
        assert envelope._parts[2][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
            os.path.basename(_jpg)

        assert envelope._parts[3][0] == 'audio/mpeg'
        assert envelope._parts[3][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
            os.path.basename(_mp3)

        assert envelope._parts[4][0] == 'application/pdf'
        assert envelope._parts[4][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
            os.path.basename(_pdf)

        assert envelope._parts[5][0] == 'application/octet-stream'
        assert envelope._parts[5][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
            quote(os.path.basename(encoded(_something, 'utf-8')))

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
             os.path.basename(_octet)

        assert envelope._parts[6][0] == 'application/octet-stream'
        assert envelope._parts[6][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
             os.path.basename(_octet)

        assert envelope._parts[7][0] == 'text/plain'
        assert envelope._parts[7][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
             os.path.basename('file1.txt')
        assert envelope._parts[7][1].get_payload(decode=True) == LOREM

        assert envelope._parts[8][0] == 'text/plain'
        assert envelope._parts[8][1]['Content-Disposition'] ==\
            "attachment; filename*=utf-8''%s" %\
             os.path.basename('file2.txt')
        assert envelope._parts[8][1].get_payload(decode=True) == LOREM