88import mock
99
1010from SoftLayer .CLI import exceptions
11+ from SoftLayer .CLI import formatting
12+ from SoftLayer .CLI import ticket
13+ from SoftLayer .managers import TicketManager
1114from 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