Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions SoftLayer/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def assert_called_with(self, service, method, **props):
raise AssertionError('%s::%s was not called with given properties: %s'
% (service, method, props))

def assert_no_fail(self, result):
"""Fail when a failing click result has an error"""
if result.exception:
raise result.exception

self.assertEqual(result.exit_code, 0)

def set_mock(self, service, method):
"""Set and return mock on the current client."""
return self.mocks.set_mock(service, method)
Expand Down
6 changes: 3 additions & 3 deletions tests/CLI/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ def test_verbose_max(self):
with mock.patch('logging.getLogger') as log_mock:
result = self.run_command(['-vvv', 'vs', 'list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
log_mock().addHandler.assert_called_with(mock.ANY)
log_mock().setLevel.assert_called_with(logging.DEBUG)

def test_build_client(self):
env = environment.Environment()
result = self.run_command(['vs', 'list'], env=env)

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertIsNotNone(env.client)

def test_diagnostics(self):
result = self.run_command(['-v', 'vs', 'list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertIn('SoftLayer_Account::getVirtualGuests', result.output)
self.assertIn('"execution_time"', result.output)
self.assertIn('"api_calls"', result.output)
Expand Down
8 changes: 4 additions & 4 deletions tests/CLI/modules/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BlockTests(testing.TestCase):
def test_access_list(self):
result = self.run_command(['block', 'access-list', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual([
{
'username': 'joe',
Expand Down Expand Up @@ -58,15 +58,15 @@ def test_volume_cancel(self):
result = self.run_command([
'--really', 'block', 'volume-cancel', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual("", result.output)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
args=(False, True, None))

def test_volume_detail(self):
result = self.run_command(['block', 'volume-detail', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual({
'Username': 'username',
'LUN Id': '2',
Expand All @@ -84,7 +84,7 @@ def test_volume_detail(self):
def test_volume_list(self):
result = self.run_command(['block', 'volume-list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual([
{
'bytes_used': None,
Expand Down
16 changes: 8 additions & 8 deletions tests/CLI/modules/call_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_python_output(self):
'-f nested.property=5432',
'--output-python'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
# NOTE(kmcdonald): Python 3 no longer inserts 'u' before unicode
# string literals but python 2 does. These are stripped out to make
# this test pass on both python versions.
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_options(self):
'-f property=1234',
'-f nested.property=5432'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), 'test')
self.assert_called_with('SoftLayer_Service', 'method',
mask='mask[some.mask]',
Expand All @@ -94,7 +94,7 @@ def test_object(self):

result = self.run_command(['call-api', 'Service', 'method'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
{'string': 'string',
'int': 10,
Expand All @@ -113,7 +113,7 @@ def test_object_table(self):
result = self.run_command(['call-api', 'Service', 'method'],
fmt='table')

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
# NOTE(kmcdonald): Order is not guaranteed
self.assertIn(":........:........:", result.output)
self.assertIn(": name : value :", result.output)
Expand All @@ -130,7 +130,7 @@ def test_object_nested(self):

result = self.run_command(['call-api', 'Service', 'method'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
{'this': {'is': [{'pretty': 'nested'}]}})

Expand All @@ -144,7 +144,7 @@ def test_list(self):

result = self.run_command(['call-api', 'Service', 'method'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'string': 'string',
'int': 10,
Expand All @@ -163,7 +163,7 @@ def test_list_table(self):
result = self.run_command(['call-api', 'Service', 'method'],
fmt='table')

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output,
""":......:......:.......:.....:........:
: Bool : None : float : int : string :
Expand All @@ -179,6 +179,6 @@ def test_parameters(self):
result = self.run_command(['call-api', 'Service', 'method',
'arg1', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Service', 'method',
args=('arg1', '1234'))
14 changes: 7 additions & 7 deletions tests/CLI/modules/cdn_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CdnTests(testing.TestCase):
def test_list_accounts(self):
result = self.run_command(['cdn', 'list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'notes': None,
'created': '2012-06-25T14:05:28-07:00',
Expand All @@ -30,7 +30,7 @@ def test_list_accounts(self):
def test_detail_account(self):
result = self.run_command(['cdn', 'detail', '1245'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
{'notes': None,
'created': '2012-06-25T14:05:28-07:00',
Expand All @@ -43,20 +43,20 @@ def test_load_content(self):
result = self.run_command(['cdn', 'load', '1234',
'http://example.com'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

def test_purge_content(self):
result = self.run_command(['cdn', 'purge', '1234',
'http://example.com'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

def test_list_origins(self):
result = self.run_command(['cdn', 'origin-list', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), [
{'media_type': 'FLASH',
'origin_url': 'http://ams01.objectstorage.softlayer.net:80',
Expand All @@ -71,12 +71,12 @@ def test_add_origin(self):
result = self.run_command(['cdn', 'origin-add', '1234',
'http://example.com'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

def test_remove_origin(self):
result = self.run_command(['cdn', 'origin-remove', '1234',
'http://example.com'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")
4 changes: 2 additions & 2 deletions tests/CLI/modules/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def set_up(self):
def test_show(self):
result = self.run_command(['config', 'show'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
{'Username': 'username',
'API Key': 'api-key',
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_setup(self, input, getpass, confirm_mock):
result = self.run_command(['--config=%s' % config_file.name,
'config', 'setup'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertTrue('Configuration Updated Successfully'
in result.output)
contents = config_file.read().decode("utf-8")
Expand Down
16 changes: 8 additions & 8 deletions tests/CLI/modules/dns_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ class DnsTests(testing.TestCase):
def test_zone_print(self):
result = self.run_command(['dns', 'zone-print', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), "lots of text")

def test_create_zone(self):
result = self.run_command(['dns', 'zone-create', 'example.com'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_delete_zone(self, no_going_back_mock):
no_going_back_mock.return_value = True
result = self.run_command(['dns', 'zone-delete', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

no_going_back_mock.return_value = False
result = self.run_command(['--really', 'dns', 'zone-delete', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
Expand All @@ -53,7 +53,7 @@ def test_delete_zone_abort(self, no_going_back_mock):
def test_list_zones(self):
result = self.run_command(['dns', 'zone-list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'serial': 2014030728,
'updated': '2014-03-07T13:52:31-06:00',
Expand All @@ -63,7 +63,7 @@ def test_list_zones(self):
def test_list_records(self):
result = self.run_command(['dns', 'record-list', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output)[0],
{'record': 'a',
'type': 'CNAME',
Expand All @@ -75,15 +75,15 @@ def test_add_record(self):
result = self.run_command(['dns', 'record-add', '1234', 'hostname',
'A', 'd', '--ttl=100'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_delete_record(self, no_going_back_mock):
no_going_back_mock.return_value = True
result = self.run_command(['dns', 'record-remove', '1234'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
Expand Down
2 changes: 1 addition & 1 deletion tests/CLI/modules/firewall_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FirewallTests(testing.TestCase):
def test_list_firewalls(self):
result = self.run_command(['firewall', 'list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'type': 'VLAN - dedicated',
'server/vlan id': 1,
Expand Down
8 changes: 4 additions & 4 deletions tests/CLI/modules/globalip_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class DnsTests(testing.TestCase):
def test_ip_assign(self):
result = self.run_command(['globalip', 'assign', '1', '127.0.0.1'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_ip_cancel(self, no_going_back_mock):
# Test using --really flag
result = self.run_command(['--really', 'globalip', 'cancel', '1'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

# Test with confirmation
no_going_back_mock.return_value = True
result = self.run_command(['globalip', 'cancel', '1'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

# Test with confirmation and responding negatively
Expand All @@ -45,7 +45,7 @@ def test_ip_cancel(self, no_going_back_mock):
def test_ip_list(self):
result = self.run_command(['globalip', 'list', '--ip-version=v4'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'assigned': 'Yes',
'id': '200',
Expand Down
2 changes: 1 addition & 1 deletion tests/CLI/modules/nas_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RWhoisTests(testing.TestCase):
def test_list_nas(self):
result = self.run_command(['nas', 'list'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'datacenter': 'Dallas',
'server': '127.0.0.1',
Expand Down
4 changes: 2 additions & 2 deletions tests/CLI/modules/object_storage_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ObjectStorageTests(testing.TestCase):
def test_list_accounts(self):
result = self.run_command(['object-storage', 'accounts'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'id': 12345, 'name': 'SLOS12345-1'},
{'id': 12346, 'name': 'SLOS12345-2'}])
Expand All @@ -31,7 +31,7 @@ def test_list_endpoints(self):

result = self.run_command(['object-storage', 'endpoints'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
[{'datacenter': 'dal05',
'private': 'https://dal05/auth/v1.0/',
Expand Down
6 changes: 3 additions & 3 deletions tests/CLI/modules/rwhois_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_edit(self):
'--state=TX',
'--private'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

self.assert_called_with('SoftLayer_Network_Subnet_Rwhois_Data',
Expand All @@ -55,7 +55,7 @@ def test_edit(self):
def test_edit_public(self):
result = self.run_command(['rwhois', 'edit', '--public'])

self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(result.output, "")

self.assert_called_with('SoftLayer_Network_Subnet_Rwhois_Data',
Expand All @@ -77,5 +77,5 @@ def test_show(self):
'Postal Code': 'postalCode',
'State': '-',
'Private Residence': True}
self.assertEqual(result.exit_code, 0)
self.assert_no_fail(result)
self.assertEqual(json.loads(result.output), expected)
Loading