Skip to content

Commit c3dfc35

Browse files
Merge pull request #1246 from caberos/issue887
fix the issue 887
2 parents 23a748a + 47b03f3 commit c3dfc35

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

SoftLayer/CLI/ticket/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Support tickets."""
22

33
import click
4+
import re
45

56
from SoftLayer.CLI import formatting
67

7-
88
TEMPLATE_MSG = "***** SoftLayer Ticket Content ******"
99

1010
# https://softlayer.github.io/reference/services/SoftLayer_Ticket_Priority/getPriorities/
@@ -17,7 +17,7 @@
1717
]
1818

1919

20-
def get_ticket_results(mgr, ticket_id, update_count=1):
20+
def get_ticket_results(mgr, ticket_id, is_json = False, update_count=1):
2121
"""Get output about a ticket.
2222
2323
:param integer id: the ticket ID
@@ -64,6 +64,7 @@ def get_ticket_results(mgr, ticket_id, update_count=1):
6464

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

SoftLayer/CLI/ticket/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ def cli(env, title, subject_id, body, hardware_identifier, virtual_identifier, p
4545
vs_id = helpers.resolve_id(vs_mgr.resolve_ids, virtual_identifier, 'VS')
4646
ticket_mgr.attach_virtual_server(created_ticket['id'], vs_id)
4747

48-
env.fout(ticket.get_ticket_results(ticket_mgr, created_ticket['id']))
48+
env.fout(ticket.get_ticket_results(ticket_mgr, False, created_ticket['id']))

SoftLayer/CLI/ticket/detail.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
def cli(env, identifier, count):
2121
"""Get details for a ticket."""
2222

23+
is_json = False
24+
if (env.format == 'json'):
25+
is_json = True
2326
mgr = SoftLayer.TicketManager(env.client)
2427

2528
ticket_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'ticket')
26-
env.fout(ticket.get_ticket_results(mgr, ticket_id, update_count=count))
29+
env.fout(ticket.get_ticket_results(mgr, ticket_id, is_json, update_count=count))

docs/cli/hardware.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Provides some basic functionality to order a server. `slcli order` has a more fu
3737
:show-nested:
3838

3939
.. click:: SoftLayer.CLI.hardware.billing:cli
40-
:prog: hw billing
40+
:prog: hardware billing
4141
:show-nested:
4242

4343

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

113113
.. click:: SoftLayer.CLI.hardware.storage:cli
114-
:prog: hw storage
114+
:prog: hardware storage
115115
:show-nested:

docs/cli/users.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Version 5.6.0 introduces the ability to interact with user accounts from the cli
3232
:prog: user delete
3333
:show-nested:
3434

35-
.. click:: SoftLayer.CLI.user.vpn-manual:cli
35+
.. click:: SoftLayer.CLI.user.vpn_manual:cli
3636
:prog: user vpn-manual
3737
:show-nested:
3838

39-
.. click:: SoftLayer.CLI.user.vpn-subnet:cli
39+
.. click:: SoftLayer.CLI.user.vpn_subnet:cli
4040
:prog: user vpn-subnet
4141
:show-nested:
4242

tests/CLI/modules/ticket_tests.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
SoftLayer.tests.CLI.modules.ticket_tests
33
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4-
54
:license: MIT, see LICENSE for more details.
65
"""
76
import json
@@ -43,8 +42,8 @@ def test_detail(self):
4342
'status': 'Closed',
4443
'title': 'Cloud Instance Cancellation - 08/01/13',
4544
'update 1': 'a bot says something',
46-
'update 2': 'By John Smith\nuser says something',
47-
'update 3': 'By emp1 (Employee)\nemployee says something',
45+
'update 2': 'By John Smith user says something',
46+
'update 3': 'By emp1 (Employee) employee says something',
4847
}
4948
self.assert_no_fail(result)
5049
self.assertEqual(json.loads(result.output), expected)
@@ -300,3 +299,18 @@ def test_ticket_update_no_body(self, edit_mock):
300299
result = self.run_command(['ticket', 'update', '100'])
301300
self.assert_no_fail(result)
302301
self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing1'},), identifier=100)
302+
303+
def test_ticket_json(self):
304+
result = self.run_command(['--format=json', 'ticket', 'detail', '1'])
305+
expected = {'Case_Number': 'CS123456',
306+
'created': '2013-08-01T14:14:04-07:00',
307+
'edited': '2013-08-01T14:16:47-07:00',
308+
'id': 100,
309+
'priority': 'No Priority',
310+
'status': 'Closed',
311+
'title': 'Cloud Instance Cancellation - 08/01/13',
312+
'update 1': 'a bot says something',
313+
'update 2': 'By John Smith user says something',
314+
'update 3': 'By emp1 (Employee) employee says something'}
315+
self.assert_no_fail(result)
316+
self.assertEqual(json.loads(result.output), expected)

0 commit comments

Comments
 (0)