Mock glance v1 image with object not dict
glance v1 objects are not dict like. They are just regular objects. Making them dictlike triggers an unreal path. This also allows us to remove the _shadeunittest logic line in obj_to_dict. Change-Id: Iae2d926a7d8b899ef842b8cb1e898a38ed17adf7
This commit is contained in:
parent
d72262e207
commit
cf43b98e33
@ -338,9 +338,6 @@ def obj_to_dict(obj):
|
||||
# If we obj_to_dict twice, don't fail, just return the munch
|
||||
# Also, don't try to modify Mock objects - that way lies madness
|
||||
return obj
|
||||
elif hasattr(obj, '_shadeunittest'):
|
||||
# Hook for unittesting
|
||||
instance = munch.Munch()
|
||||
elif hasattr(obj, 'schema') and hasattr(obj, 'validate'):
|
||||
# It's a warlock
|
||||
return warlock_to_dict(obj)
|
||||
|
@ -496,28 +496,30 @@ class TestMemoryCache(base.TestCase):
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
||||
def test_cache_no_cloud_name(self, glance_mock):
|
||||
class FakeImage(dict):
|
||||
id = 1
|
||||
class FakeImage(object):
|
||||
status = 'active'
|
||||
name = 'None Test Image'
|
||||
|
||||
def _shadeunittest(self):
|
||||
pass
|
||||
def __init__(self, id):
|
||||
self.id = id
|
||||
|
||||
fi = FakeImage(id=FakeImage.id, status=FakeImage.status,
|
||||
name=FakeImage.name)
|
||||
fi = FakeImage(id=1)
|
||||
glance_mock.images.list.return_value = [fi]
|
||||
self.cloud.name = None
|
||||
self.assertEqual([fi], [dict(x) for x in self.cloud.list_images()])
|
||||
self.assertEqual(
|
||||
meta.obj_list_to_dict([fi]),
|
||||
self.cloud.list_images())
|
||||
# Now test that the list was cached
|
||||
fi2 = FakeImage(id=2, status=FakeImage.status, name=FakeImage.name)
|
||||
fi2.id = 2
|
||||
fi2 = FakeImage(id=2)
|
||||
glance_mock.images.list.return_value = [fi, fi2]
|
||||
self.assertEqual([fi], [dict(x) for x in self.cloud.list_images()])
|
||||
self.assertEqual(
|
||||
meta.obj_list_to_dict([fi]),
|
||||
self.cloud.list_images())
|
||||
# Invalidation too
|
||||
self.cloud.list_images.invalidate(self.cloud)
|
||||
self.assertEqual(
|
||||
[fi, fi2], [dict(x) for x in self.cloud.list_images()])
|
||||
meta.obj_list_to_dict([fi, fi2]),
|
||||
self.cloud.list_images())
|
||||
|
||||
|
||||
class TestBogusAuth(base.TestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user