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
9 changes: 3 additions & 6 deletions tests/CLI/helper_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,15 @@ def test_init(self):
class ResolveIdTests(testing.TestCase):

def test_resolve_id_one(self):
resolver = lambda r: [12345]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for changing this from a lambda function?

Copy link
Contributor Author

@erick-sapp erick-sapp May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real reason. The analysis was failing because of it though. Checking the message now, it would have been better to skip the assignment and put the lambda expression as the argument itself. That is normally how the lambda is intended to be used.

Copy link
Contributor Author

@erick-sapp erick-sapp May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have replace the code with lambdas again, but removed the assignment process that it did not like. They are true anonymous functions created within the function calls.

Copy link
Contributor Author

@erick-sapp erick-sapp May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in general, I just didn't want the analysis failing for another section of code.
image

self.assertEqual(helpers.resolve_id(resolver, 'test'), 12345)
self.assertEqual(helpers.resolve_id(lambda r: [12345], 'test'), 12345)

def test_resolve_id_none(self):
resolver = lambda r: []
self.assertRaises(
exceptions.CLIAbort, helpers.resolve_id, resolver, 'test')
exceptions.CLIAbort, helpers.resolve_id, lambda r: [], 'test')

def test_resolve_id_multiple(self):
resolver = lambda r: [12345, 54321]
self.assertRaises(
exceptions.CLIAbort, helpers.resolve_id, resolver, 'test')
exceptions.CLIAbort, helpers.resolve_id, lambda r: [12345, 54321], 'test')


class TestTable(testing.TestCase):
Expand Down
139 changes: 139 additions & 0 deletions tests/CLI/modules/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,127 @@

class VirtTests(testing.TestCase):

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_rescue_vs(self, confirm_mock):
confirm_mock.return_value = True
result = self.run_command(['vs', 'rescue', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_rescue_vs_no_confirm(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['vs', 'rescue', '100'])

self.assertEqual(result.exit_code, 2)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_reboot_vs_default(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'rebootDefault')
mock.return_value = 'true'
confirm_mock.return_value = True
result = self.run_command(['vs', 'reboot', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_reboot_vs_no_confirm(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'rebootDefault')
mock.return_value = 'true'
confirm_mock.return_value = False
result = self.run_command(['vs', 'reboot', '100'])

self.assertEqual(result.exit_code, 2)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_reboot_vs_soft(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'rebootSoft')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'reboot', '--soft', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_reboot_vs_hard(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'rebootHard')
mock.return_value = 'true'
confirm_mock.return_value = True
result = self.run_command(['vs', 'reboot', '--hard', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_power_vs_off_soft(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'powerOffSoft')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'power-off', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_power_off_vs_no_confirm(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'powerOffSoft')
mock.return_value = 'true'
confirm_mock.return_value = False

result = self.run_command(['vs', 'power-off', '100'])

self.assertEqual(result.exit_code, 2)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_power_off_vs_hard(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'powerOff')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'power-off', '--hard', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_power_on_vs(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'powerOn')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'power-on', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_pause_vs(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'pause')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'pause', '100'])

self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_pause_vs_no_confirm(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'pause')
mock.return_value = 'true'
confirm_mock.return_value = False

result = self.run_command(['vs', 'pause', '100'])

self.assertEqual(result.exit_code, 2)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_resume_vs(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'resume')
mock.return_value = 'true'
confirm_mock.return_value = True

result = self.run_command(['vs', 'resume', '100'])

self.assert_no_fail(result)

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

Expand Down Expand Up @@ -662,3 +783,21 @@ def test_going_ready(self, _sleep):
result = self.run_command(['vs', 'ready', '100', '--wait=100'])
self.assert_no_fail(result)
self.assertEqual(result.output, '"READY"\n')

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_reload(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'reloadCurrentOperatingSystemConfguration')
confirm_mock.return_value = True
mock.return_value = 'true'

result = self.run_command(['vs', 'reload', '--postinstall', '100', '--key', '100', '--image', '100', '100'])
self.assert_no_fail(result)

@mock.patch('SoftLayer.CLI.formatting.no_going_back')
def test_reload_no_confirm(self, confirm_mock):
mock = self.set_mock('SoftLayer_Virtual_Guest', 'reloadCurrentOperatingSystemConfiguration')
confirm_mock.return_value = False
mock.return_value = 'false'

result = self.run_command(['vs', 'reload', '--postinstall', '100', '--key', '100', '--image', '100', '100'])
self.assertEqual(result.exit_code, 2)