From 16fdd3ce1ee3d9d207dcae15a222d8ff9bccaba0 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Wed, 29 Apr 2020 18:04:44 -0400 Subject: [PATCH] Fix ticket upload to be able to run with rest and xmlrpc endpoint. --- SoftLayer/managers/ticket.py | 9 +++++++-- tests/CLI/modules/ticket_tests.py | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/SoftLayer/managers/ticket.py b/SoftLayer/managers/ticket.py index 9ff361d4b..951e9e97e 100644 --- a/SoftLayer/managers/ticket.py +++ b/SoftLayer/managers/ticket.py @@ -5,6 +5,9 @@ :license: MIT, see LICENSE for more details. """ +import base64 +from json import dumps + from SoftLayer import utils @@ -92,9 +95,11 @@ def upload_attachment(self, ticket_id=None, file_path=None, file_name=None): :param string file_name: The name of the attachment shown in the ticket :returns: dict -- The uploaded attachment """ - file_content = None with open(file_path, 'rb') as attached_file: - file_content = attached_file.read() + base64_bytes = base64.b64encode(attached_file.read()) + base64_string = base64_bytes.decode('utf-8') + raw_data = {file_path: base64_string} + file_content = dumps(raw_data, indent=2) file_object = { "filename": file_name, diff --git a/tests/CLI/modules/ticket_tests.py b/tests/CLI/modules/ticket_tests.py index 4f8db62a8..3efd438e9 100644 --- a/tests/CLI/modules/ticket_tests.py +++ b/tests/CLI/modules/ticket_tests.py @@ -208,7 +208,8 @@ def test_ticket_upload_no_name(self): self.assert_called_with('SoftLayer_Ticket', 'addAttachedFile', args=({"filename": "attachment_upload", - "data": b"ticket attached data"},), + "data": '{\n "tests/resources/attachment_upload": ' + '"dGlja2V0IGF0dGFjaGVkIGRhdGE="\n}'},), identifier=1) def test_ticket_upload(self): @@ -220,7 +221,8 @@ def test_ticket_upload(self): self.assert_called_with('SoftLayer_Ticket', 'addAttachedFile', args=({"filename": "a_file_name", - "data": b"ticket attached data"},), + "data": '{\n "tests/resources/attachment_upload": ' + '"dGlja2V0IGF0dGFjaGVkIGRhdGE="\n}'},), identifier=1) def test_init_ticket_results(self):