|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | + |
| 14 | +from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes |
| 15 | +from openstackclient.volume.v3 import backup_record |
| 16 | + |
| 17 | + |
| 18 | +class TestBackupRecord(volume_fakes.TestVolume): |
| 19 | + def setUp(self): |
| 20 | + super().setUp() |
| 21 | + |
| 22 | + self.backups_mock = self.volume_client.backups |
| 23 | + self.backups_mock.reset_mock() |
| 24 | + |
| 25 | + |
| 26 | +class TestBackupRecordExport(TestBackupRecord): |
| 27 | + new_backup = volume_fakes.create_one_backup( |
| 28 | + attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'}, |
| 29 | + ) |
| 30 | + new_record = volume_fakes.create_backup_record() |
| 31 | + |
| 32 | + def setUp(self): |
| 33 | + super().setUp() |
| 34 | + |
| 35 | + self.backups_mock.export_record.return_value = self.new_record |
| 36 | + self.backups_mock.get.return_value = self.new_backup |
| 37 | + |
| 38 | + # Get the command object to mock |
| 39 | + self.cmd = backup_record.ExportBackupRecord(self.app, None) |
| 40 | + |
| 41 | + def test_backup_export_table(self): |
| 42 | + arglist = [ |
| 43 | + self.new_backup.name, |
| 44 | + ] |
| 45 | + verifylist = [ |
| 46 | + ("backup", self.new_backup.name), |
| 47 | + ] |
| 48 | + |
| 49 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 50 | + parsed_args.formatter = 'table' |
| 51 | + columns, __ = self.cmd.take_action(parsed_args) |
| 52 | + |
| 53 | + self.backups_mock.export_record.assert_called_with( |
| 54 | + self.new_backup.id, |
| 55 | + ) |
| 56 | + |
| 57 | + expected_columns = ('Backup Service', 'Metadata') |
| 58 | + self.assertEqual(columns, expected_columns) |
| 59 | + |
| 60 | + def test_backup_export_json(self): |
| 61 | + arglist = [ |
| 62 | + self.new_backup.name, |
| 63 | + ] |
| 64 | + verifylist = [ |
| 65 | + ("backup", self.new_backup.name), |
| 66 | + ] |
| 67 | + |
| 68 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 69 | + parsed_args.formatter = 'json' |
| 70 | + columns, __ = self.cmd.take_action(parsed_args) |
| 71 | + |
| 72 | + self.backups_mock.export_record.assert_called_with( |
| 73 | + self.new_backup.id, |
| 74 | + ) |
| 75 | + |
| 76 | + expected_columns = ('backup_service', 'backup_url') |
| 77 | + self.assertEqual(columns, expected_columns) |
| 78 | + |
| 79 | + |
| 80 | +class TestBackupRecordImport(TestBackupRecord): |
| 81 | + new_backup = volume_fakes.create_one_backup( |
| 82 | + attrs={'volume_id': 'a54708a2-0388-4476-a909-09579f885c25'}, |
| 83 | + ) |
| 84 | + new_import = volume_fakes.import_backup_record() |
| 85 | + |
| 86 | + def setUp(self): |
| 87 | + super().setUp() |
| 88 | + |
| 89 | + self.backups_mock.import_record.return_value = self.new_import |
| 90 | + |
| 91 | + # Get the command object to mock |
| 92 | + self.cmd = backup_record.ImportBackupRecord(self.app, None) |
| 93 | + |
| 94 | + def test_backup_import(self): |
| 95 | + arglist = [ |
| 96 | + "cinder.backup.drivers.swift.SwiftBackupDriver", |
| 97 | + "fake_backup_record_data", |
| 98 | + ] |
| 99 | + verifylist = [ |
| 100 | + ( |
| 101 | + "backup_service", |
| 102 | + "cinder.backup.drivers.swift.SwiftBackupDriver", |
| 103 | + ), |
| 104 | + ("backup_metadata", "fake_backup_record_data"), |
| 105 | + ] |
| 106 | + |
| 107 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 108 | + columns, __ = self.cmd.take_action(parsed_args) |
| 109 | + |
| 110 | + self.backups_mock.import_record.assert_called_with( |
| 111 | + "cinder.backup.drivers.swift.SwiftBackupDriver", |
| 112 | + "fake_backup_record_data", |
| 113 | + ) |
| 114 | + self.assertEqual(columns, ('backup',)) |
0 commit comments