Skip to content

Commit 45030b0

Browse files
#1019 Ticket unit tests
1 parent 3b01180 commit 45030b0

File tree

3 files changed

+108
-17
lines changed

3 files changed

+108
-17
lines changed

SoftLayer/CLI/ticket/list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def cli(env, is_open):
3131
click.wrap_text(ticket['title']),
3232
ticket['lastEditDate'],
3333
ticket['status']['name'],
34-
ticket['updateCount'],
35-
ticket['priority']
34+
ticket.get('updateCount', 0),
35+
ticket.get('priority', 0)
3636
])
3737

3838
env.fout(table)

SoftLayer/managers/ticket.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def create_ticket(self, title=None, body=None, subject=None, priority=None):
7373
'title': title,
7474
}
7575
if priority is not None:
76-
new_ticket['priority'] = priority
76+
new_ticket['priority'] = int(priority)
7777

7878
created_ticket = self.ticket.createStandardTicket(new_ticket, body)
7979
return created_ticket
@@ -86,18 +86,12 @@ def update_ticket(self, ticket_id=None, body=None):
8686
"""
8787
return self.ticket.addUpdate({'entry': body}, id=ticket_id)
8888

89-
def upload_attachment(self, ticket_id=None, file_path=None,
90-
file_name=None):
89+
def upload_attachment(self, ticket_id=None, file_path=None, file_name=None):
9190
"""Upload an attachment to a ticket.
9291
93-
:param integer ticket_id: the id of the ticket to
94-
upload the attachment to
95-
:param string file_path:
96-
The path of the attachment to be uploaded
97-
:param string file_name:
98-
The name of the attachment shown
99-
in the ticket
100-
92+
:param integer ticket_id: the id of the ticket to upload the attachment to
93+
:param string file_path: The path of the attachment to be uploaded
94+
:param string file_name: The name of the attachment shown in the ticket
10195
:returns: dict -- The uploaded attachment
10296
"""
10397
file_content = None

tests/CLI/modules/ticket_tests.py

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import mock
99

1010
from SoftLayer.CLI import exceptions
11+
from SoftLayer.CLI import formatting
12+
from SoftLayer.CLI import ticket
13+
from SoftLayer.managers import TicketManager
1114
from SoftLayer import testing
1215

1316

@@ -20,10 +23,12 @@ def test_list(self):
2023
'assigned_user': 'John Smith',
2124
'id': 102,
2225
'last_edited': '2013-08-01T14:16:47-07:00',
26+
'priority': 0,
2327
'status': 'Open',
24-
'title': 'Cloud Instance Cancellation - 08/01/13'}]
28+
'title': 'Cloud Instance Cancellation - 08/01/13',
29+
'updates': 0}]
2530
self.assert_no_fail(result)
26-
self.assertEqual(json.loads(result.output), expected)
31+
self.assertEqual(expected, json.loads(result.output))
2732

2833
def test_detail(self):
2934
result = self.run_command(['ticket', 'detail', '1'])
@@ -32,6 +37,7 @@ def test_detail(self):
3237
'created': '2013-08-01T14:14:04-07:00',
3338
'edited': '2013-08-01T14:16:47-07:00',
3439
'id': 100,
40+
'priority': 'No Priority',
3541
'status': 'Closed',
3642
'title': 'Cloud Instance Cancellation - 08/01/13',
3743
'update 1': 'a bot says something',
@@ -53,8 +59,23 @@ def test_create(self):
5359
'assignedUserId': 12345,
5460
'title': 'Test'}, 'ticket body')
5561

56-
self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket',
57-
args=args)
62+
self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', args=args)
63+
64+
def test_create_with_priority(self):
65+
result = self.run_command(['ticket', 'create', '--title=Test',
66+
'--subject-id=1000',
67+
'--body=ticket body',
68+
'--priority=1'])
69+
70+
self.assert_no_fail(result)
71+
72+
args = ({'subjectId': 1000,
73+
'contents': 'ticket body',
74+
'assignedUserId': 12345,
75+
'title': 'Test',
76+
'priority': 1}, 'ticket body')
77+
78+
self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', args=args)
5879

5980
def test_create_and_attach(self):
6081
result = self.run_command(['ticket', 'create', '--title=Test',
@@ -204,3 +225,79 @@ def test_ticket_upload(self):
204225
args=({"filename": "a_file_name",
205226
"data": b"ticket attached data"},),
206227
identifier=1)
228+
229+
def test_init_ticket_results(self):
230+
ticket_mgr = TicketManager(self.client)
231+
ticket_table = ticket.get_ticket_results(ticket_mgr, 100)
232+
self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100)
233+
self.assertIsInstance(ticket_table, formatting.KeyValueTable)
234+
235+
ticket_object = ticket_table.to_python()
236+
self.assertEqual('No Priority', ticket_object['priority'])
237+
self.assertEqual(100, ticket_object['id'])
238+
239+
def test_init_ticket_results_asigned_user(self):
240+
mock = self.set_mock('SoftLayer_Ticket', 'getObject')
241+
mock.return_value = {
242+
"id": 100,
243+
"title": "Simple Title",
244+
"priority": 1,
245+
"assignedUser": {
246+
"firstName": "Test",
247+
"lastName": "User"
248+
},
249+
"status": {
250+
"name": "Closed"
251+
},
252+
"createDate": "2013-08-01T14:14:04-07:00",
253+
"lastEditDate": "2013-08-01T14:16:47-07:00",
254+
"updates": [{'entry': 'a bot says something'}]
255+
}
256+
257+
ticket_mgr = TicketManager(self.client)
258+
ticket_table = ticket.get_ticket_results(ticket_mgr, 100)
259+
self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100)
260+
self.assertIsInstance(ticket_table, formatting.KeyValueTable)
261+
262+
ticket_object = ticket_table.to_python()
263+
self.assertEqual('Severity 1 - Critical Impact / Service Down', ticket_object['priority'])
264+
self.assertEqual('Test User', ticket_object['user'])
265+
266+
def test_ticket_summary(self):
267+
mock = self.set_mock('SoftLayer_Account', 'getObject')
268+
mock.return_value = {
269+
'openTicketCount': 1,
270+
'closedTicketCount': 2,
271+
'openBillingTicketCount': 3,
272+
'openOtherTicketCount': 4,
273+
'openSalesTicketCount': 5,
274+
'openSupportTicketCount': 6,
275+
'openAccountingTicketCount': 7
276+
}
277+
expected = [
278+
{'Status': 'Open',
279+
'count': [
280+
{'Type': 'Accounting', 'count': 7},
281+
{'Type': 'Billing', 'count': 3},
282+
{'Type': 'Sales', 'count': 5},
283+
{'Type': 'Support', 'count': 6},
284+
{'Type': 'Other', 'count': 4},
285+
{'Type': 'Total', 'count': 1}]},
286+
{'Status': 'Closed', 'count': 2}
287+
]
288+
result = self.run_command(['ticket', 'summary'])
289+
self.assert_no_fail(result)
290+
self.assert_called_with('SoftLayer_Account', 'getObject')
291+
self.assertEqual(expected, json.loads(result.output))
292+
293+
def test_ticket_update(self):
294+
result = self.run_command(['ticket', 'update', '100', '--body=Testing'])
295+
self.assert_no_fail(result)
296+
self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing'},), identifier=100)
297+
298+
@mock.patch('click.edit')
299+
def test_ticket_update_no_body(self, edit_mock):
300+
edit_mock.return_value = 'Testing1'
301+
result = self.run_command(['ticket', 'update', '100'])
302+
self.assert_no_fail(result)
303+
self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing1'},), identifier=100)

0 commit comments

Comments
 (0)