Exemplo n.º 1
0
    def test_request_id_proxy(self):
        def test_data(val):
            resp = create_response_obj_with_req_id(REQUEST_ID)
            return val, resp

        # Object of any type except decorator can be passed to test_data
        proxy = utils.RequestIdProxy(test_data(11))
        # Verify that proxy object has a property `request_ids` and it is
        # a list of one request id
        self.assertEqual([REQUEST_ID], proxy.request_ids)
Exemplo n.º 2
0
    def test_save_no_data(self):
        req_id_proxy = glanceclient_utils.RequestIdProxy(
            [None, self.resp]
        )
        self.images_mock.data.return_value = req_id_proxy

        arglist = ['--file', '/path/to/file', self.image.id]

        verifylist = [
            ('file', '/path/to/file'),
            ('image', self.image.id)
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        # Raise SystemExit if no data was provided.
        self.assertRaises(SystemExit, self.cmd.take_action, parsed_args)
Exemplo n.º 3
0
    def test_save_data(self):
        req_id_proxy = glanceclient_utils.RequestIdProxy(
            ['some_data', self.resp]
        )
        self.images_mock.data.return_value = req_id_proxy

        arglist = ['--file', '/path/to/file', self.image.id]

        verifylist = [
            ('file', '/path/to/file'),
            ('image', self.image.id)
        ]
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        with mock.patch('glanceclient.common.utils.save_image') as mocked_save:
            self.cmd.take_action(parsed_args)
            mocked_save.assert_called_once_with(req_id_proxy, '/path/to/file')
Exemplo n.º 4
0
 def test_iter_iterator_display_progress_bar(self):
     size = 100
     # create fake response object to return request-id with iterator
     resp = requests.Response()
     resp.headers['x-openstack-request-id'] = 'req-1234'
     iterator_with_len = utils.IterableWithLength(iter('X' * 100), size)
     requestid_proxy = utils.RequestIdProxy((iterator_with_len, resp))
     saved_stdout = sys.stdout
     try:
         sys.stdout = output = test_utils.FakeTTYStdout()
         # Consume iterator.
         data = list(
             progressbar.VerboseIteratorWrapper(requestid_proxy, size))
         self.assertEqual(['X'] * 100, data)
         self.assertEqual('[%s>] 100%%\n' % ('=' * 29), output.getvalue())
     finally:
         sys.stdout = saved_stdout