Skip to content

Commit 5798373

Browse files
Merge pull request #2072 from softlayer/jayasilan-issue2049
slcli ticket list command with user limit option #2049
2 parents f8db60b + 179b846 commit 5798373

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

SoftLayer/CLI/ticket/list.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1313
@click.option('--open / --closed', 'is_open', default=True,
1414
help="Display only open or closed tickets")
15+
@click.option('--limit', default=100, show_default=True, type=click.INT, help="Result limit")
16+
@click.option("--all", "-a", "all_tickets", is_flag=True, default=False, help="Return all tickets")
1517
@environment.pass_env
16-
def cli(env, is_open):
18+
def cli(env, is_open, limit, all_tickets):
1719
"""List tickets."""
1820
ticket_mgr = SoftLayer.TicketManager(env.client)
1921
table = formatting.Table([
2022
'id', 'Case_Number', 'assigned_user', 'title', 'last_edited', 'status', 'updates', 'priority'
2123
])
2224

23-
tickets = ticket_mgr.list_tickets(open_status=is_open, closed_status=not is_open)
25+
tickets = ticket_mgr.list_tickets(open_status=is_open,
26+
closed_status=not is_open, limit=limit, all_tickets=all_tickets)
27+
2428
for ticket in tickets:
2529
user = formatting.blank()
2630
if ticket.get('assignedUser'):

SoftLayer/managers/ticket.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def __init__(self, client):
2222
self.account = self.client['Account']
2323
self.ticket = self.client['Ticket']
2424

25-
def list_tickets(self, open_status=True, closed_status=True):
25+
def list_tickets(self, open_status=True, closed_status=True, limit=None, all_tickets=False):
2626
"""List all tickets.
2727
2828
:param boolean open_status: include open tickets
2929
:param boolean closed_status: include closed tickets
30+
:param int limit: result limit
3031
"""
3132
mask = """mask[id, serviceProviderResourceId, title, assignedUser[firstName, lastName], priority,
3233
createDate, lastEditDate, accountId, status, updateCount]"""
@@ -39,7 +40,8 @@ def list_tickets(self, open_status=True, closed_status=True):
3940
call = 'getClosedTickets'
4041
else:
4142
raise ValueError("open_status and closed_status cannot both be False")
42-
return self.client.call('Account', call, mask=mask, iter=False, limit=100)
43+
44+
return self.client.call('Account', call, mask=mask, iter=all_tickets, limit=limit)
4345

4446
def list_subjects(self):
4547
"""List all ticket subjects."""

tests/CLI/modules/ticket_tests.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,33 @@ def test_ticket_json(self):
358358
'update 3': 'By emp1 (Employee) employee says something'}
359359
self.assert_no_fail(result)
360360
self.assertEqual(json.loads(result.output), expected)
361+
362+
def test_list_limit(self):
363+
result = self.run_command(['ticket', 'list', '--limit', '1'])
364+
365+
expected = [{
366+
'assigned_user': 'John Smith',
367+
'Case_Number': 'CS123456',
368+
'id': 102,
369+
'last_edited': '2013-08-01',
370+
'priority': 0,
371+
'status': 'Open',
372+
'title': 'Cloud Instance Cancellation - 08/01/13',
373+
'updates': 0}]
374+
self.assert_no_fail(result)
375+
self.assertEqual(expected, json.loads(result.output))
376+
377+
def test_list_all_open(self):
378+
result = self.run_command(['ticket', 'list', '--all'])
379+
380+
expected = [{
381+
'assigned_user': 'John Smith',
382+
'Case_Number': 'CS123456',
383+
'id': 102,
384+
'last_edited': '2013-08-01',
385+
'priority': 0,
386+
'status': 'Open',
387+
'title': 'Cloud Instance Cancellation - 08/01/13',
388+
'updates': 0}]
389+
self.assert_no_fail(result)
390+
self.assertEqual(expected, json.loads(result.output))

0 commit comments

Comments
 (0)