|
13 | 13 |
|
14 | 14 | import copy |
15 | 15 |
|
| 16 | +import mock |
16 | 17 | from osc_lib import exceptions |
17 | 18 | from requests_mock.contrib import fixture |
| 19 | +import six |
18 | 20 |
|
19 | 21 | from openstackclient.object.v1 import object as object_cmds |
20 | 22 | from openstackclient.tests.unit.object.v1 import fakes as object_fakes |
@@ -202,3 +204,44 @@ def test_object_show(self): |
202 | 204 | 'manifest', |
203 | 205 | ) |
204 | 206 | self.assertEqual(datalist, data) |
| 207 | + |
| 208 | + |
| 209 | +class TestObjectSave(TestObjectAll): |
| 210 | + |
| 211 | + def setUp(self): |
| 212 | + super(TestObjectSave, self).setUp() |
| 213 | + |
| 214 | + # Get the command object to test |
| 215 | + self.cmd = object_cmds.SaveObject(self.app, None) |
| 216 | + |
| 217 | + def test_save_to_stdout(self): |
| 218 | + self.requests_mock.register_uri( |
| 219 | + 'GET', |
| 220 | + object_fakes.ENDPOINT + |
| 221 | + '/' + |
| 222 | + object_fakes.container_name + |
| 223 | + '/' + |
| 224 | + object_fakes.object_name_1, |
| 225 | + status_code=200, |
| 226 | + content=object_fakes.object_1_content |
| 227 | + ) |
| 228 | + |
| 229 | + arglist = [ |
| 230 | + object_fakes.container_name, |
| 231 | + object_fakes.object_name_1, |
| 232 | + '--file', |
| 233 | + '-' |
| 234 | + ] |
| 235 | + |
| 236 | + verifylist = [ |
| 237 | + ('container', object_fakes.container_name), |
| 238 | + ('object', object_fakes.object_name_1), |
| 239 | + ('file', '-'), |
| 240 | + ] |
| 241 | + |
| 242 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 243 | + |
| 244 | + with mock.patch('sys.stdout', new=six.BytesIO()) as fake_stdout: |
| 245 | + self.cmd.take_action(parsed_args) |
| 246 | + |
| 247 | + self.assertEqual(fake_stdout.getvalue(), object_fakes.object_1_content) |
0 commit comments