예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #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')

        # 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
예제 #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')

        # 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