tests: Use correct response type in tests
An instance of 'glanceclient.utils.common.RequestIdProxy' is returned
for most calls to glanceclient. Correct the unit tests to reflect this.
- https://github.com/openstack/python-glanceclient/blob/2.8.0/glanceclient/common/utils.py#L542
- https://github.com/openstack/python-glanceclient/blob/2.8.0/glanceclient/v2/images.py#L199
Change-Id: I1a0a7c80d6ca53d0ac8821b2e63dd43593e6c822
(cherry picked from commit 646264f3b9
)
This commit is contained in:
parent
b535f08085
commit
c3f238e738
|
@ -189,6 +189,11 @@ image_fixtures = {
|
|||
}
|
||||
|
||||
|
||||
def fake_glance_response(data):
|
||||
with mock.patch('glanceclient.common.utils._extract_request_id'):
|
||||
return glanceclient.common.utils.RequestIdProxy([data, None])
|
||||
|
||||
|
||||
class ImageV2(dict):
|
||||
# Wrapper class that is used to comply with dual nature of
|
||||
# warlock objects, that are inherited from dict and have 'schema'
|
||||
|
@ -516,7 +521,8 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
|
||||
def test_download_no_data_no_dest_path_v2(self, show_mock, open_mock):
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = mock.sentinel.image_chunks
|
||||
client.call.return_value = fake_glance_response(
|
||||
mock.sentinel.image_chunks)
|
||||
ctx = mock.sentinel.ctx
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
res = service.download(ctx, mock.sentinel.image_id)
|
||||
|
@ -531,7 +537,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
|
||||
def test_download_data_no_dest_path_v2(self, show_mock, open_mock):
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
data = mock.MagicMock()
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
|
@ -557,7 +563,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
def test_download_no_data_dest_path_v2(self, fsync_mock, show_mock,
|
||||
open_mock):
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
writer = mock.MagicMock()
|
||||
open_mock.return_value = writer
|
||||
|
@ -590,7 +596,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
# #TODO(jaypipes): Fix the aforementioned horrible design of
|
||||
# the download() method.
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
data = mock.MagicMock()
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
|
@ -615,7 +621,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
def test_download_data_dest_path_write_fails_v2(
|
||||
self, show_mock, open_mock):
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
|
||||
|
@ -683,7 +689,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
tran_mod.download.side_effect = Exception
|
||||
get_tran_mock.return_value = tran_mod
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
writer = mock.MagicMock()
|
||||
open_mock.return_value = writer
|
||||
|
@ -736,7 +742,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
|
|||
}
|
||||
get_tran_mock.return_value = None
|
||||
client = mock.MagicMock()
|
||||
client.call.return_value = [1, 2, 3]
|
||||
client.call.return_value = fake_glance_response([1, 2, 3])
|
||||
ctx = mock.sentinel.ctx
|
||||
writer = mock.MagicMock()
|
||||
open_mock.return_value = writer
|
||||
|
@ -799,7 +805,8 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
|
|||
}
|
||||
self.fake_img_data = ['A' * 256, 'B' * 256]
|
||||
self.client = mock.MagicMock()
|
||||
self.client.call.return_value = self.fake_img_data
|
||||
self.client.call.return_value = fake_glance_response(
|
||||
self.fake_img_data)
|
||||
|
||||
@mock.patch('nova.image.glance.LOG')
|
||||
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
|
||||
|
|
Loading…
Reference in New Issue