Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions SoftLayer/managers/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

:license: MIT, see LICENSE for more details.
"""
import base64
from json import dumps

from SoftLayer import utils


Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions tests/CLI/modules/ticket_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down