Skip to content
Merged
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
7 changes: 4 additions & 3 deletions SoftLayer/CLI/ticket/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Support tickets."""

import click
import re

from SoftLayer.CLI import formatting


TEMPLATE_MSG = "***** SoftLayer Ticket Content ******"

# https://softlayer.github.io/reference/services/SoftLayer_Ticket_Priority/getPriorities/
Expand All @@ -17,7 +17,7 @@
]


def get_ticket_results(mgr, ticket_id, update_count=1):
def get_ticket_results(mgr, ticket_id, is_json = False, update_count=1):
"""Get output about a ticket.

:param integer id: the ticket ID
Expand Down Expand Up @@ -64,6 +64,7 @@ def get_ticket_results(mgr, ticket_id, update_count=1):

# NOTE(kmcdonald): Windows new-line characters need to be stripped out
wrapped_entry += click.wrap_text(update['entry'].replace('\r', ''))
if is_json and '\n' in wrapped_entry:
wrapped_entry = re.sub(r"(?<!\\)\n", " ", wrapped_entry)
table.add_row(['update %s' % (count_offset + i,), wrapped_entry])

return table
2 changes: 1 addition & 1 deletion SoftLayer/CLI/ticket/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier, p
vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS')
ticket_mgr.attach_virtual_server(created_ticket['id'], vs_id)

env.fout(ticket.get_ticket_results(ticket_mgr, created_ticket['id']))
env.fout(ticket.get_ticket_results(ticket_mgr, False, created_ticket['id']))
5 changes: 4 additions & 1 deletion SoftLayer/CLI/ticket/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
def cli(env, identifier, count):
"""Get details for a ticket."""

is_json = False
if (env.format == 'json'):
is_json = True
mgr = SoftLayer.TicketManager(env.client)

ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
env.fout(ticket.get_ticket_results(mgr, ticket_id, update_count=count))
env.fout(ticket.get_ticket_results(mgr, ticket_id, is_json, update_count=count))
4 changes: 2 additions & 2 deletions docs/cli/hardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Provides some basic functionality to order a server. `slcli order` has a more fu
:show-nested:

.. click:: SoftLayer.CLI.hardware.billing:cli
:prog: hw billing
:prog: hardware billing
:show-nested:


Expand Down Expand Up @@ -111,5 +111,5 @@ This function updates the firmware of a server. If already at the latest version
:show-nested:

.. click:: SoftLayer.CLI.hardware.storage:cli
:prog: hw storage
:prog: hardware storage
:show-nested:
4 changes: 2 additions & 2 deletions docs/cli/users.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Version 5.6.0 introduces the ability to interact with user accounts from the cli
:prog: user delete
:show-nested:

.. click:: SoftLayer.CLI.user.vpn-manual:cli
.. click:: SoftLayer.CLI.user.vpn_manual:cli
:prog: user vpn-manual
:show-nested:

.. click:: SoftLayer.CLI.user.vpn-subnet:cli
.. click:: SoftLayer.CLI.user.vpn_subnet:cli
:prog: user vpn-subnet
:show-nested:

Expand Down
20 changes: 17 additions & 3 deletions tests/CLI/modules/ticket_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SoftLayer.tests.CLI.modules.ticket_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:license: MIT, see LICENSE for more details.
"""
import json
Expand Down Expand Up @@ -43,8 +42,8 @@ def test_detail(self):
'status': 'Closed',
'title': 'Cloud Instance Cancellation - 08/01/13',
'update 1': 'a bot says something',
'update 2': 'By John Smith\nuser says something',
'update 3': 'By emp1 (Employee)\nemployee says something',
'update 2': 'By John Smith user says something',
'update 3': 'By emp1 (Employee) employee says something',
}
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), expected)
Expand Down Expand Up @@ -300,3 +299,18 @@ def test_ticket_update_no_body(self, edit_mock):
result = self.run_command(['ticket', 'update', '100'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing1'},), identifier=100)

def test_ticket_json(self):
result = self.run_command(['--format=json', 'ticket', 'detail', '1'])
expected = {'Case_Number': 'CS123456',
'created': '2013-08-01T14:14:04-07:00',
'edited': '2013-08-01T14:16:47-07:00',
'id': 100,
'priority': 'No Priority',
'status': 'Closed',
'title': 'Cloud Instance Cancellation - 08/01/13',
'update 1': 'a bot says something',
'update 2': 'By John Smith user says something',
'update 3': 'By emp1 (Employee) employee says something'}
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), expected)