From c1f55e73366da4d6f029cccd96cd282cce422faf Mon Sep 17 00:00:00 2001 From: Daniel Cabero Barrios Date: Tue, 24 Mar 2020 09:15:53 -0400 Subject: [PATCH 1/7] fix the issue 887 --- SoftLayer/CLI/ticket/__init__.py | 8 ++- SoftLayer/CLI/ticket/create.py | 2 +- SoftLayer/CLI/ticket/detail.py | 5 +- tests/CLI/modules/ticket_tests.py | 107 +++++------------------------- 4 files changed, 25 insertions(+), 97 deletions(-) diff --git a/SoftLayer/CLI/ticket/__init__.py b/SoftLayer/CLI/ticket/__init__.py index 9886aa686..b08663322 100644 --- a/SoftLayer/CLI/ticket/__init__.py +++ b/SoftLayer/CLI/ticket/__init__.py @@ -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/ @@ -17,7 +17,7 @@ ] -def get_ticket_results(mgr, ticket_id, update_count=1): +def get_ticket_results(mgr, ticket_id, is_json, update_count=1): """Get output about a ticket. :param integer id: the ticket ID @@ -64,6 +64,8 @@ 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: + if '\n' in wrapped_entry: + wrapped_entry = re.sub(r"(? Date: Tue, 24 Mar 2020 09:50:45 -0400 Subject: [PATCH 2/7] fix the coverage test --- tests/CLI/modules/ticket_tests.py | 97 ++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/tests/CLI/modules/ticket_tests.py b/tests/CLI/modules/ticket_tests.py index 46d957f81..dcfa44968 100644 --- a/tests/CLI/modules/ticket_tests.py +++ b/tests/CLI/modules/ticket_tests.py @@ -1,13 +1,15 @@ """ SoftLayer.tests.CLI.modules.ticket_tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :license: MIT, see LICENSE for more details. """ import json import mock from SoftLayer.CLI import exceptions +from SoftLayer.CLI import formatting +from SoftLayer.CLI import ticket +from SoftLayer.managers import TicketManager from SoftLayer import testing @@ -40,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 user says something', - 'update 3': 'By emp1 (Employee) employee says something', + 'update 2': 'By John Smith\nuser says something', + 'update 3': 'By emp1 (Employee)\nemployee says something', } self.assert_no_fail(result) self.assertEqual(json.loads(result.output), expected) @@ -209,6 +211,95 @@ def test_ticket_upload_no_name(self): "data": b"ticket attached data"},), identifier=1) + def test_ticket_upload(self): + result = self.run_command(['ticket', 'upload', '1', + '--path=tests/resources/attachment_upload', + '--name=a_file_name']) + + self.assert_no_fail(result) + self.assert_called_with('SoftLayer_Ticket', + 'addAttachedFile', + args=({"filename": "a_file_name", + "data": b"ticket attached data"},), + identifier=1) + + def test_init_ticket_results(self): + ticket_mgr = TicketManager(self.client) + ticket_table = ticket.get_ticket_results(ticket_mgr, 100) + self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100) + self.assertIsInstance(ticket_table, formatting.KeyValueTable) + + ticket_object = ticket_table.to_python() + self.assertEqual('No Priority', ticket_object['priority']) + self.assertEqual(100, ticket_object['id']) + + def test_init_ticket_results_asigned_user(self): + mock = self.set_mock('SoftLayer_Ticket', 'getObject') + mock.return_value = { + "serviceProviderResourceId": "CS12345", + "id": 100, + "title": "Simple Title", + "priority": 1, + "assignedUser": { + "firstName": "Test", + "lastName": "User" + }, + "status": { + "name": "Closed" + }, + "createDate": "2013-08-01T14:14:04-07:00", + "lastEditDate": "2013-08-01T14:16:47-07:00", + "updates": [{'entry': 'a bot says something'}] + } + + ticket_mgr = TicketManager(self.client) + ticket_table = ticket.get_ticket_results(ticket_mgr, 100) + self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100) + self.assertIsInstance(ticket_table, formatting.KeyValueTable) + + ticket_object = ticket_table.to_python() + self.assertEqual('Severity 1 - Critical Impact / Service Down', ticket_object['priority']) + self.assertEqual('Test User', ticket_object['user']) + + def test_ticket_summary(self): + mock = self.set_mock('SoftLayer_Account', 'getObject') + mock.return_value = { + 'openTicketCount': 1, + 'closedTicketCount': 2, + 'openBillingTicketCount': 3, + 'openOtherTicketCount': 4, + 'openSalesTicketCount': 5, + 'openSupportTicketCount': 6, + 'openAccountingTicketCount': 7 + } + expected = [ + {'Status': 'Open', + 'count': [ + {'Type': 'Accounting', 'count': 7}, + {'Type': 'Billing', 'count': 3}, + {'Type': 'Sales', 'count': 5}, + {'Type': 'Support', 'count': 6}, + {'Type': 'Other', 'count': 4}, + {'Type': 'Total', 'count': 1}]}, + {'Status': 'Closed', 'count': 2} + ] + result = self.run_command(['ticket', 'summary']) + self.assert_no_fail(result) + self.assert_called_with('SoftLayer_Account', 'getObject') + self.assertEqual(expected, json.loads(result.output)) + + def test_ticket_update(self): + result = self.run_command(['ticket', 'update', '100', '--body=Testing']) + self.assert_no_fail(result) + self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing'},), identifier=100) + + @mock.patch('click.edit') + def test_ticket_update_no_body(self, edit_mock): + edit_mock.return_value = 'Testing1' + 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', From 59b921f41a10ed0ec78e391094e07d06efede89d Mon Sep 17 00:00:00 2001 From: Daniel Cabero Barrios Date: Tue, 24 Mar 2020 10:11:08 -0400 Subject: [PATCH 3/7] fix the coverage test --- tests/CLI/modules/ticket_tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/CLI/modules/ticket_tests.py b/tests/CLI/modules/ticket_tests.py index dcfa44968..a9e305c19 100644 --- a/tests/CLI/modules/ticket_tests.py +++ b/tests/CLI/modules/ticket_tests.py @@ -42,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) @@ -225,7 +225,7 @@ def test_ticket_upload(self): def test_init_ticket_results(self): ticket_mgr = TicketManager(self.client) - ticket_table = ticket.get_ticket_results(ticket_mgr, 100) + ticket_table = ticket.get_ticket_results(ticket_mgr, False,100) self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100) self.assertIsInstance(ticket_table, formatting.KeyValueTable) @@ -253,7 +253,7 @@ def test_init_ticket_results_asigned_user(self): } ticket_mgr = TicketManager(self.client) - ticket_table = ticket.get_ticket_results(ticket_mgr, 100) + ticket_table = ticket.get_ticket_results(ticket_mgr, False, 100) self.assert_called_with('SoftLayer_Ticket', 'getObject', identifier=100) self.assertIsInstance(ticket_table, formatting.KeyValueTable) From f5fd7298eab6d1f2b70b4c7f16c4d4104987a290 Mon Sep 17 00:00:00 2001 From: Daniel Cabero Barrios Date: Wed, 8 Apr 2020 16:42:40 -0400 Subject: [PATCH 4/7] fix the Christopher code review --- SoftLayer/CLI/ticket/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/ticket/__init__.py b/SoftLayer/CLI/ticket/__init__.py index b08663322..ebeee3bb3 100644 --- a/SoftLayer/CLI/ticket/__init__.py +++ b/SoftLayer/CLI/ticket/__init__.py @@ -66,6 +66,6 @@ def get_ticket_results(mgr, ticket_id, is_json, update_count=1): wrapped_entry += click.wrap_text(update['entry'].replace('\r', '')) if is_json: if '\n' in wrapped_entry: - wrapped_entry = re.sub(r"(? Date: Mon, 13 Apr 2020 16:00:54 -0400 Subject: [PATCH 5/7] fix the travis error --- SoftLayer/CLI/ticket/__init__.py | 7 +++---- tests/CLI/modules/ticket_tests.py | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/SoftLayer/CLI/ticket/__init__.py b/SoftLayer/CLI/ticket/__init__.py index ebeee3bb3..a8ffae6e0 100644 --- a/SoftLayer/CLI/ticket/__init__.py +++ b/SoftLayer/CLI/ticket/__init__.py @@ -17,7 +17,7 @@ ] -def get_ticket_results(mgr, ticket_id, is_json, 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 @@ -64,8 +64,7 @@ def get_ticket_results(mgr, ticket_id, is_json, 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: - if '\n' in wrapped_entry: - wrapped_entry = re.sub(r"(? Date: Mon, 13 Apr 2020 16:39:56 -0400 Subject: [PATCH 6/7] fix the travis error --- SoftLayer/CLI/ticket/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SoftLayer/CLI/ticket/__init__.py b/SoftLayer/CLI/ticket/__init__.py index a8ffae6e0..81c248322 100644 --- a/SoftLayer/CLI/ticket/__init__.py +++ b/SoftLayer/CLI/ticket/__init__.py @@ -17,7 +17,7 @@ ] -def get_ticket_results(mgr, ticket_id, is_json=False, 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 From 47b03f304c9873ab0e94d0453175f9be8d658210 Mon Sep 17 00:00:00 2001 From: Daniel Cabero Barrios Date: Tue, 14 Apr 2020 11:22:40 -0400 Subject: [PATCH 7/7] fix the doCheck.py --- docs/cli/hardware.rst | 4 ++-- docs/cli/users.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/cli/hardware.rst b/docs/cli/hardware.rst index cd97c9d0d..0cce23042 100644 --- a/docs/cli/hardware.rst +++ b/docs/cli/hardware.rst @@ -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: @@ -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: diff --git a/docs/cli/users.rst b/docs/cli/users.rst index 21ff1b7b8..feb94e352 100644 --- a/docs/cli/users.rst +++ b/docs/cli/users.rst @@ -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: