1010# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1111# License for the specific language governing permissions and limitations
1212# under the License.
13- #
13+
14+ from openstack .block_storage .v3 import backup as _backup
15+ from openstack .test import fakes as sdk_fakes
1416
1517from openstackclient .tests .unit .volume .v2 import fakes as volume_fakes
1618from openstackclient .volume .v2 import backup_record
1719
1820
19- class TestBackupRecord (volume_fakes .TestVolume ):
20- def setUp (self ):
21- super ().setUp ()
22-
23- self .backups_mock = self .volume_client .backups
24- self .backups_mock .reset_mock ()
25-
26-
27- class TestBackupRecordExport (TestBackupRecord ):
28- new_backup = volume_fakes .create_one_backup (
29- attrs = {'volume_id' : 'a54708a2-0388-4476-a909-09579f885c25' },
21+ class TestBackupRecordExport (volume_fakes .TestVolume ):
22+ fake_backup = sdk_fakes .generate_fake_resource (
23+ _backup .Backup ,
24+ volume_id = 'a54708a2-0388-4476-a909-09579f885c25' ,
3025 )
31- new_record = volume_fakes .create_backup_record ()
26+ fake_record = {
27+ 'backup-record' : {
28+ 'backup_service' : 'cinder.backup.drivers.swift.SwiftBackupDriver' ,
29+ 'backup_url' : 'eyJzdGF0dXMiOiAiYXZh' ,
30+ }
31+ }
3232
3333 def setUp (self ):
3434 super ().setUp ()
3535
36- self .backups_mock . export_record .return_value = self .new_record
37- self .backups_mock . get .return_value = self .new_backup
36+ self .volume_sdk_client . find_backup .return_value = self .fake_backup
37+ self .volume_sdk_client . export_backup .return_value = self .fake_record
3838
39- # Get the command object to mock
4039 self .cmd = backup_record .ExportBackupRecord (self .app , None )
4140
4241 def test_backup_export_table (self ):
43- arglist = [
44- self .new_backup .name ,
45- ]
46- verifylist = [
47- ("backup" , self .new_backup .name ),
48- ]
42+ arglist = [self .fake_backup .name ]
43+ verifylist = [("backup" , self .fake_backup .name )]
4944
5045 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
5146 parsed_args .formatter = 'table'
5247 columns , __ = self .cmd .take_action (parsed_args )
5348
54- self .backups_mock . export_record . assert_called_with (
55- self .new_backup . id ,
49+ self .volume_sdk_client . find_backup . assert_called_once_with (
50+ self .fake_backup . name , ignore_missing = False
5651 )
57-
58- expected_columns = ('Backup Service' , 'Metadata' )
59- self .assertEqual (columns , expected_columns )
52+ self .volume_sdk_client .export_backup .assert_called_once_with (
53+ self .fake_backup
54+ )
55+ self .assertEqual (('Backup Service' , 'Metadata' ), columns )
6056
6157 def test_backup_export_json (self ):
62- arglist = [
63- self .new_backup .name ,
64- ]
65- verifylist = [
66- ("backup" , self .new_backup .name ),
67- ]
58+ arglist = [self .fake_backup .name ]
59+ verifylist = [("backup" , self .fake_backup .name )]
6860
6961 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
7062 parsed_args .formatter = 'json'
7163 columns , __ = self .cmd .take_action (parsed_args )
7264
73- self .backups_mock . export_record . assert_called_with (
74- self .new_backup . id ,
65+ self .volume_sdk_client . find_backup . assert_called_once_with (
66+ self .fake_backup . name , ignore_missing = False
7567 )
76-
77- expected_columns = ('backup_service' , 'backup_url' )
78- self .assertEqual (columns , expected_columns )
68+ self .volume_sdk_client .export_backup .assert_called_once_with (
69+ self .fake_backup
70+ )
71+ self .assertEqual (('backup_service' , 'backup_url' ), columns )
7972
8073
81- class TestBackupRecordImport (TestBackupRecord ):
82- new_backup = volume_fakes .create_one_backup (
83- attrs = {'volume_id' : 'a54708a2-0388-4476-a909-09579f885c25' },
84- )
85- new_import = volume_fakes .import_backup_record ()
74+ class TestBackupRecordImport (volume_fakes .TestVolume ):
75+ fake_import = {
76+ 'backup' : {
77+ 'id' : 'backup.id' ,
78+ 'name' : 'backup.name' ,
79+ },
80+ }
8681
8782 def setUp (self ):
8883 super ().setUp ()
8984
90- self .backups_mock . import_record .return_value = self .new_import
85+ self .volume_sdk_client . import_backup .return_value = self .fake_import
9186
92- # Get the command object to mock
9387 self .cmd = backup_record .ImportBackupRecord (self .app , None )
9488
9589 def test_backup_import (self ):
@@ -108,8 +102,8 @@ def test_backup_import(self):
108102 parsed_args = self .check_parser (self .cmd , arglist , verifylist )
109103 columns , __ = self .cmd .take_action (parsed_args )
110104
111- self .backups_mock . import_record . assert_called_with (
105+ self .volume_sdk_client . import_backup . assert_called_once_with (
112106 "cinder.backup.drivers.swift.SwiftBackupDriver" ,
113107 "fake_backup_record_data" ,
114108 )
115- self .assertEqual (columns , ('backup' ,))
109+ self .assertEqual (('backup' ,), columns )
0 commit comments