Skip to content

Commit af08140

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
Unit Tests 100% for SoftLayer\CLI\block\snapshot added unit test cases
1 parent 4de8c5a commit af08140

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

tests/CLI/modules/block_tests.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,110 @@ def test_snapshot_cancel(self):
433433
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
434434
args=(False, True, None))
435435

436+
@mock.patch('SoftLayer.BlockStorageManager.set_volume_snapshot_notification')
437+
def test_block_snapshot_set_notify_status(self, set_s_notification):
438+
set_s_notification.return_value = True
439+
result = self.run_command(['block', 'snapshot-set-notification', '1234', '--enable'])
440+
441+
self.assert_no_fail(result)
442+
self.assertEqual('Snapshots space usage threshold warning notification has bee set to'
443+
' True for volume 1234\n', result.output)
444+
445+
def test_block_snapshot_cancel_immediate(self):
446+
result = self.run_command(['--really',
447+
'block', 'snapshot-cancel', '--immediate', '1234'])
448+
449+
self.assert_no_fail(result)
450+
self.assertEqual('Block volume with id 1234 has been marked'
451+
' for immediate snapshot cancellation\n', result.output)
452+
453+
@mock.patch('SoftLayer.BlockStorageManager.cancel_snapshot_space')
454+
def test_block_snapshot_unable_cancel(self, cancel_snapshot_space):
455+
cancel_snapshot_space.return_value = False
456+
result = self.run_command(['--really',
457+
'block', 'snapshot-cancel', '1234'])
458+
459+
self.assert_no_fail(result)
460+
self.assertEqual('Unable to cancel snapshot space for block volume 1234\n', result.output)
461+
462+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
463+
def test_snapshot_cancel_aborted(self, no_going_back):
464+
no_going_back.return_value = False
465+
result = self.run_command(['block', 'snapshot-cancel', '1234'])
466+
self.assertEqual(result.exit_code, 2)
467+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
468+
469+
def test_snapshot_delete(self):
470+
result = self.run_command(['--really',
471+
'block', 'snapshot-delete', '1234'])
472+
self.assert_no_fail(result)
473+
474+
def test_block_snapshot_disable_not_in_schedule_type(self):
475+
result = self.run_command(['block', 'snapshot-disable', '12345678',
476+
'--schedule-type=ABCD'])
477+
self.assertEqual(result.exit_code, 2)
478+
self.assertEqual(result.exception.message, "--schedule-type must be INTERVAL, HOURLY, DAILY, or WEEKLY")
479+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
480+
481+
def test_block_snapshot_enable_not_in_schedule_type(self):
482+
result = self.run_command(['block', 'snapshot-enable', '12345678',
483+
'--schedule-type=ZYXW', '--minute=10',
484+
'--retention-count=5'])
485+
self.assertEqual(result.exit_code, 2)
486+
self.assertEqual(result.exception.message, "--schedule-type must be INTERVAL, HOURLY, DAILY,or WEEKLY,"
487+
" not ZYXW")
488+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
489+
490+
def test_block_snapshot_enable_retention_count(self):
491+
result = self.run_command(['block', 'snapshot-enable', '12345678',
492+
'--schedule-type=INTERVAL', '--minute=-1',
493+
'--retention-count=5'])
494+
self.assertEqual(result.exit_code, 2)
495+
self.assertEqual(result.exception.message, "--minute value must be between 30 and 59")
496+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
497+
498+
def test_block_snapshot_enable_minute(self):
499+
result = self.run_command(['block', 'snapshot-enable', '12345678',
500+
'--schedule-type=HOURLY', '--minute=-1',
501+
'--retention-count=5'])
502+
self.assertEqual(result.exit_code, 2)
503+
self.assertEqual(result.exception.message, "--minute value must be between 0 and 59")
504+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
505+
506+
def test_block_snapshot_enable_hour(self):
507+
result = self.run_command(['block', 'snapshot-enable', '12345678',
508+
'--schedule-type=DAILY', '--hour=-1',
509+
'--retention-count=5'])
510+
self.assertEqual(result.exit_code, 2)
511+
self.assertEqual(result.exception.message, "--hour value must be between 0 and 23")
512+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
513+
514+
def test_block_snapshot_enable_day_of_week(self):
515+
result = self.run_command(['block', 'snapshot-enable', '12345678',
516+
'--schedule-type=WEEKLY', '--day-of-week=EVERDAY',
517+
'--retention-count=5'])
518+
self.assertEqual(result.exit_code, 2)
519+
self.assertEqual(result.exception.message, "--day_of_week value must be a valid day (ex: SUNDAY)")
520+
self.assertIsInstance(result.exception, exceptions.CLIAbort)
521+
522+
def test_snapshot_order_order_iops(self):
523+
result = self.run_command(['block', 'snapshot-order', '1234',
524+
'--size=10', '--tier=0.25', '--iops=1'])
525+
526+
self.assertEqual(result.exit_code, 2)
527+
self.assertEqual(result.exception.message, "Argument Error: Invalid value for '--iops' / '-i': '1' is not one"
528+
" of between 100 and 6000.")
529+
self.assertIsInstance(result.exception, exceptions.ArgumentError)
530+
531+
def test_snapshot_order_order_iops_100(self):
532+
result = self.run_command(['block', 'snapshot-order', '1234',
533+
'--size=10', '--tier=0.25', '--iops=101'])
534+
535+
self.assertEqual(result.exit_code, 2)
536+
self.assertEqual(result.exception.message, "Argument Error: Invalid value for '--iops' / '-i': '101' is not"
537+
" a multiple of 100.")
538+
self.assertIsInstance(result.exception, exceptions.ArgumentError)
539+
436540
def test_snapshot_restore(self):
437541
result = self.run_command(['block', 'snapshot-restore', '12345678',
438542
'--snapshot-id=87654321'])

0 commit comments

Comments
 (0)