@@ -519,16 +519,18 @@ def test_snapshot_list_negative_limit(self):
519519 )
520520
521521
522- class TestVolumeSnapshotSet (TestVolumeSnapshot ):
523- snapshot = volume_fakes .create_one_snapshot ()
524-
522+ class TestVolumeSnapshotSet (volume_fakes .TestVolume ):
525523 def setUp (self ):
526524 super ().setUp ()
527525
528- self .snapshots_mock .get .return_value = self .snapshot
529- self .snapshots_mock .set_metadata .return_value = None
530- self .snapshots_mock .update .return_value = None
531- # Get the command object to mock
526+ self .snapshot = sdk_fakes .generate_fake_resource (
527+ _snapshot .Snapshot , metadata = {'foo' : 'bar' }
528+ )
529+ self .volume_sdk_client .find_snapshot .return_value = self .snapshot
530+ self .volume_sdk_client .delete_snapshot_metadata .return_value = None
531+ self .volume_sdk_client .set_snapshot_metadata .return_value = None
532+ self .volume_sdk_client .update_snapshot .return_value = None
533+
532534 self .cmd = volume_snapshot .SetVolumeSnapshot (self .app , None )
533535
534536 def test_snapshot_set_no_option (self ):
@@ -541,11 +543,14 @@ def test_snapshot_set_no_option(self):
541543 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
542544
543545 result = self .cmd .take_action (parsed_args )
544- self .snapshots_mock .get .assert_called_once_with (parsed_args .snapshot )
545- self .assertNotCalled (self .snapshots_mock .reset_state )
546- self .assertNotCalled (self .snapshots_mock .update )
547- self .assertNotCalled (self .snapshots_mock .set_metadata )
546+
548547 self .assertIsNone (result )
548+ self .volume_sdk_client .find_snapshot .assert_called_once_with (
549+ parsed_args .snapshot , ignore_missing = False
550+ )
551+ self .volume_sdk_client .reset_snapshot_status .assert_not_called ()
552+ self .volume_sdk_client .update_snapshot .assert_not_called ()
553+ self .volume_sdk_client .set_snapshot_metadata .assert_not_called ()
549554
550555 def test_snapshot_set_name_and_property (self ):
551556 arglist = [
@@ -557,26 +562,22 @@ def test_snapshot_set_name_and_property(self):
557562 "foo=foo" ,
558563 self .snapshot .id ,
559564 ]
560- new_property = {"x" : "y" , "foo" : "foo" }
561565 verifylist = [
562566 ("name" , "new_snapshot" ),
563- ("property " , new_property ),
567+ ("properties " , { "x" : "y" , "foo" : "foo" } ),
564568 ("snapshot" , self .snapshot .id ),
565569 ]
566570 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
567571
568572 result = self .cmd .take_action (parsed_args )
569573
570- kwargs = {
571- "name" : "new_snapshot" ,
572- }
573- self .snapshots_mock .update .assert_called_with (
574- self .snapshot .id , ** kwargs
574+ self .assertIsNone (result )
575+ self .volume_sdk_client .update_snapshot .assert_called_with (
576+ self .snapshot .id , name = "new_snapshot"
575577 )
576- self .snapshots_mock . set_metadata .assert_called_with (
577- self .snapshot .id , new_property
578+ self .volume_sdk_client . set_snapshot_metadata .assert_called_with (
579+ self .snapshot .id , x = "y" , foo = "foo"
578580 )
579- self .assertIsNone (result )
580581
581582 def test_snapshot_set_with_no_property (self ):
582583 arglist = [
@@ -590,14 +591,17 @@ def test_snapshot_set_with_no_property(self):
590591 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
591592
592593 result = self .cmd .take_action (parsed_args )
593- self .snapshots_mock .get .assert_called_once_with (parsed_args .snapshot )
594- self .assertNotCalled (self .snapshots_mock .reset_state )
595- self .assertNotCalled (self .snapshots_mock .update )
596- self .assertNotCalled (self .snapshots_mock .set_metadata )
597- self .snapshots_mock .delete_metadata .assert_called_with (
598- self .snapshot .id , ["foo" ]
599- )
594+
600595 self .assertIsNone (result )
596+ self .volume_sdk_client .find_snapshot .assert_called_once_with (
597+ parsed_args .snapshot , ignore_missing = False
598+ )
599+ self .volume_sdk_client .reset_snapshot_status .assert_not_called ()
600+ self .volume_sdk_client .update_snapshot .assert_not_called ()
601+ self .volume_sdk_client .set_snapshot_metadata .assert_not_called ()
602+ self .volume_sdk_client .delete_snapshot_metadata .assert_called_with (
603+ self .snapshot .id , keys = ["foo" ]
604+ )
601605
602606 def test_snapshot_set_with_no_property_and_property (self ):
603607 arglist = [
@@ -608,22 +612,26 @@ def test_snapshot_set_with_no_property_and_property(self):
608612 ]
609613 verifylist = [
610614 ("no_property" , True ),
611- ("property " , {"foo_1" : "bar_1" }),
615+ ("properties " , {"foo_1" : "bar_1" }),
612616 ("snapshot" , self .snapshot .id ),
613617 ]
614618 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
615619
616620 result = self .cmd .take_action (parsed_args )
617- self .snapshots_mock .get .assert_called_once_with (parsed_args .snapshot )
618- self .assertNotCalled (self .snapshots_mock .reset_state )
619- self .assertNotCalled (self .snapshots_mock .update )
620- self .snapshots_mock .delete_metadata .assert_called_with (
621- self .snapshot .id , ["foo" ]
621+
622+ self .assertIsNone (result )
623+ self .volume_sdk_client .find_snapshot .assert_called_once_with (
624+ parsed_args .snapshot , ignore_missing = False
622625 )
623- self .snapshots_mock .set_metadata .assert_called_once_with (
624- self .snapshot .id , {"foo_1" : "bar_1" }
626+ self .volume_sdk_client .reset_snapshot_status .assert_not_called ()
627+ self .volume_sdk_client .update_snapshot .assert_not_called ()
628+ self .volume_sdk_client .delete_snapshot_metadata .assert_called_with (
629+ self .snapshot .id , keys = ["foo" ]
630+ )
631+ self .volume_sdk_client .set_snapshot_metadata .assert_called_once_with (
632+ self .snapshot .id ,
633+ foo_1 = "bar_1" ,
625634 )
626- self .assertIsNone (result )
627635
628636 def test_snapshot_set_state_to_error (self ):
629637 arglist = ["--state" , "error" , self .snapshot .id ]
@@ -632,30 +640,32 @@ def test_snapshot_set_state_to_error(self):
632640
633641 result = self .cmd .take_action (parsed_args )
634642
635- self .snapshots_mock .reset_state .assert_called_with (
643+ self .assertIsNone (result )
644+ self .volume_sdk_client .reset_snapshot_status .assert_called_with (
636645 self .snapshot .id , "error"
637646 )
638- self .assertIsNone (result )
639647
640648 def test_volume_set_state_failed (self ):
641- self .snapshots_mock .reset_state .side_effect = exceptions .CommandError ()
649+ self .volume_sdk_client .reset_snapshot_status .side_effect = (
650+ exceptions .CommandError ()
651+ )
642652 arglist = ['--state' , 'error' , self .snapshot .id ]
643653 verifylist = [('state' , 'error' ), ('snapshot' , self .snapshot .id )]
644654
645655 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
646- try :
647- self .cmd .take_action (parsed_args )
648- self .fail ('CommandError should be raised.' )
649- except exceptions .CommandError as e :
650- self .assertEqual (
651- 'One or more of the set operations failed' , str (e )
652- )
653- self .snapshots_mock .reset_state .assert_called_once_with (
656+
657+ exc = self .assertRaises (
658+ exceptions .CommandError , self .cmd .take_action , parsed_args
659+ )
660+ self .assertEqual ('One or more of the set operations failed' , str (exc ))
661+ self .volume_sdk_client .reset_snapshot_status .assert_called_once_with (
654662 self .snapshot .id , 'error'
655663 )
656664
657665 def test_volume_set_name_and_state_failed (self ):
658- self .snapshots_mock .reset_state .side_effect = exceptions .CommandError ()
666+ self .volume_sdk_client .reset_snapshot_status .side_effect = (
667+ exceptions .CommandError ()
668+ )
659669 arglist = [
660670 '--state' ,
661671 'error' ,
@@ -668,22 +678,19 @@ def test_volume_set_name_and_state_failed(self):
668678 ("name" , "new_snapshot" ),
669679 ('snapshot' , self .snapshot .id ),
670680 ]
671-
672681 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
673- try :
674- self .cmd .take_action (parsed_args )
675- self .fail ('CommandError should be raised.' )
676- except exceptions .CommandError as e :
677- self .assertEqual (
678- 'One or more of the set operations failed' , str (e )
679- )
680- kwargs = {
681- "name" : "new_snapshot" ,
682- }
683- self .snapshots_mock .update .assert_called_once_with (
684- self .snapshot .id , ** kwargs
682+
683+ exc = self .assertRaises (
684+ exceptions .CommandError ,
685+ self .cmd .take_action ,
686+ parsed_args ,
687+ )
688+
689+ self .assertEqual ('One or more of the set operations failed' , str (exc ))
690+ self .volume_sdk_client .update_snapshot .assert_called_once_with (
691+ self .snapshot .id , name = "new_snapshot"
685692 )
686- self .snapshots_mock . reset_state .assert_called_once_with (
693+ self .volume_sdk_client . reset_snapshot_status .assert_called_once_with (
687694 self .snapshot .id , 'error'
688695 )
689696
@@ -732,15 +739,14 @@ def test_snapshot_show(self):
732739 self .assertCountEqual (self .data , data )
733740
734741
735- class TestVolumeSnapshotUnset (TestVolumeSnapshot ):
736- snapshot = volume_fakes .create_one_snapshot ()
737-
742+ class TestVolumeSnapshotUnset (volume_fakes .TestVolume ):
738743 def setUp (self ):
739744 super ().setUp ()
740745
741- self .snapshots_mock .get .return_value = self .snapshot
742- self .snapshots_mock .delete_metadata .return_value = None
743- # Get the command object to mock
746+ self .snapshot = sdk_fakes .generate_fake_resource (_snapshot .Snapshot )
747+ self .volume_sdk_client .find_snapshot .return_value = self .snapshot
748+ self .volume_sdk_client .delete_snapshot_metadata .return_value = None
749+
744750 self .cmd = volume_snapshot .UnsetVolumeSnapshot (self .app , None )
745751
746752 def test_snapshot_unset (self ):
@@ -750,15 +756,15 @@ def test_snapshot_unset(self):
750756 self .snapshot .id ,
751757 ]
752758 verifylist = [
753- ("property " , ["foo" ]),
759+ ("properties " , ["foo" ]),
754760 ("snapshot" , self .snapshot .id ),
755761 ]
756762
757763 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
758764
759765 result = self .cmd .take_action (parsed_args )
760766
761- self .snapshots_mock .delete_metadata .assert_called_with (
762- self .snapshot .id , ["foo" ]
763- )
764767 self .assertIsNone (result )
768+ self .volume_sdk_client .delete_snapshot_metadata .assert_called_with (
769+ self .snapshot .id , keys = ["foo" ]
770+ )
0 commit comments