Skip to content
Snippets Groups Projects
Commit e2bff680 authored by Robert Habermann's avatar Robert Habermann
Browse files

fix #18 by decoding bytes to str for Attachment.Content

parent 98c54617
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
0.5.x - 2019-xx-yy (unreleased)
--------------------------------
- fix #18: Attachment.create_from_file did not decode "Content"
0.4.1 - 2019-03-09 - Beta
-------------------------
......
......@@ -168,6 +168,11 @@ Update Tickets
u'TicketID': u'1',
u'TicketNumber': u'2010080210123456'}
>>> att = Attachment.create_from_file("./test_data/asd.txt")
>>> client.ticket_update(ticket_id=1, article=my_article, attachments=[att])
{'ArticleID': '7927', 'TicketID': '1', 'TicketNumber': '2010080210123456'}
>>> df = DynamicField("ExternalTicket", "1234")
>>> client.ticket_update(1, dynamic_fields=[df])
{u'TicketID': u'1', u'TicketNumber': u'2010080210123456'}
......
......@@ -360,7 +360,7 @@ class Attachment(object):
content_type = mimetypes.guess_type(file_path)[0]
if not content_type:
content_type = "application/octet-stream"
return Attachment({'Content': base64.b64encode(content),
return Attachment({'Content': base64.b64encode(content).decode('utf-8'),
'ContentType': content_type,
'Filename': os.path.basename(file_path)})
......
......@@ -12,6 +12,8 @@ import unittest2 as unittest
import mock
# from mock import MagicMock, patch
import json
current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(current_path, os.pardir))
......@@ -66,6 +68,9 @@ class AttachmentTests(unittest.TestCase):
self.assertIsInstance(att, Attachment)
self.assertEqual(att.ContentType, "text/plain")
# Catches: TypeError: b'...' is not JSON serializable
self.assertEqual(json.dumps(att.Content), '"InRoaXMgaXMgdGhlIGNvbnRlbnQgb2YgYSBmaWxlISIK"')
def test_attachment_create_from_file_no_file_ext(self):
"""create_from_file test - no file ending -> mime needs to default"""
att = Attachment.create_from_file(os.path.join(current_path, "fixtures/b_file"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment