"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "glance/tests/unit/v2/test_images_resource.py" between
glance-20.0.0.tar.gz and glance-20.0.1.tar.gz

About: OpenStack Glance (Core Service: Image Service) stores and retrieves virtual machine disk images. OpenStack Compute makes use of this during instance provisioning.
The "Ussuri" series (latest release).

test_images_resource.py  (glance-20.0.0):test_images_resource.py  (glance-20.0.1)
skipping to change at line 136 skipping to change at line 136
return obj return obj
class FakeImage(object): class FakeImage(object):
def __init__(self, id=None, status='active', container_format='ami', def __init__(self, id=None, status='active', container_format='ami',
disk_format='ami', locations=None): disk_format='ami', locations=None):
self.id = id or UUID4 self.id = id or UUID4
self.status = status self.status = status
self.container_format = container_format self.container_format = container_format
self.disk_format = disk_format self.disk_format = disk_format
self.locations = locations self.locations = locations
self.owner = unit_test_utils.TENANT1
class TestImagesController(base.IsolatedUnitTest): class TestImagesController(base.IsolatedUnitTest):
def setUp(self): def setUp(self):
super(TestImagesController, self).setUp() super(TestImagesController, self).setUp()
self.db = unit_test_utils.FakeDB(initialize=False) self.db = unit_test_utils.FakeDB(initialize=False)
self.policy = unit_test_utils.FakePolicyEnforcer() self.policy = unit_test_utils.FakePolicyEnforcer()
self.notifier = unit_test_utils.FakeNotifier() self.notifier = unit_test_utils.FakeNotifier()
self.store = unit_test_utils.FakeStoreAPI() self.store = unit_test_utils.FakeStoreAPI()
for i in range(1, 4): for i in range(1, 4):
skipping to change at line 2940 skipping to change at line 2941
def test_image_import(self): def test_image_import(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
with mock.patch.object( with mock.patch.object(
glance.api.authorization.ImageRepoProxy, 'get') as mock_get: glance.api.authorization.ImageRepoProxy, 'get') as mock_get:
mock_get.return_value = FakeImage(status='uploading') mock_get.return_value = FakeImage(status='uploading')
output = self.controller.import_image( output = self.controller.import_image(
request, UUID4, {'method': {'name': 'glance-direct'}}) request, UUID4, {'method': {'name': 'glance-direct'}})
self.assertEqual(UUID4, output) self.assertEqual(UUID4, output)
def test_image_import_not_allowed(self): @mock.patch.object(glance.domain.TaskFactory, 'new_task')
request = unit_test_utils.get_fake_request() @mock.patch.object(glance.api.authorization.ImageRepoProxy, 'get')
# NOTE(abhishekk): For coverage purpose setting tenant to def test_image_import_not_allowed(self, mock_get, mock_new_task):
# None. It is not expected to do in normal scenarios. # NOTE(danms): FakeImage is owned by utils.TENANT1. Try to do the
request.context.project_id = None # import as TENANT2 and we should get an HTTPForbidden
with mock.patch.object( request = unit_test_utils.get_fake_request(tenant=TENANT2)
glance.api.authorization.ImageRepoProxy, 'get') as mock_get: mock_get.return_value = FakeImage(status='uploading')
mock_get.return_value = FakeImage(status='uploading') self.assertRaises(webob.exc.HTTPForbidden,
self.assertRaises(webob.exc.HTTPForbidden, self.controller.import_image,
self.controller.import_image, request, UUID4, {'method': {'name':
request, UUID4, {'method': {'name': 'glance-direct'}})
'glance-direct'}}) # NOTE(danms): Make sure we failed early and never even created
# a task
mock_new_task.assert_not_called()
def test_delete_encryption_key_no_encryption_key(self): def test_delete_encryption_key_no_encryption_key(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
fake_encryption_key = self.controller._key_manager.store( fake_encryption_key = self.controller._key_manager.store(
request.context, mock.Mock()) request.context, mock.Mock())
image = _domain_fixture( image = _domain_fixture(
UUID2, name='image-2', owner=TENANT2, UUID2, name='image-2', owner=TENANT2,
checksum='ca425b88f047ce8ec45ee90e813ada91', checksum='ca425b88f047ce8ec45ee90e813ada91',
os_hash_algo=FAKEHASHALGO, os_hash_value=MULTIHASH1, os_hash_algo=FAKEHASHALGO, os_hash_value=MULTIHASH1,
created_at=DATETIME, updated_at=DATETIME, size=1024, created_at=DATETIME, updated_at=DATETIME, size=1024,
skipping to change at line 4298 skipping to change at line 4301
self.config(allow_additional_image_properties=False) self.config(allow_additional_image_properties=False)
self.deserializer = glance.api.v2.images.RequestDeserializer() self.deserializer = glance.api.v2.images.RequestDeserializer()
def test_create_with_additional_properties_disallowed(self): def test_create_with_additional_properties_disallowed(self):
self.config(allow_additional_image_properties=False) self.config(allow_additional_image_properties=False)
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
request.body = jsonutils.dump_as_bytes({'foo': 'bar'}) request.body = jsonutils.dump_as_bytes({'foo': 'bar'})
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.create, request) self.deserializer.create, request)
def test_neg_create_with_stores(self):
self.config(allow_additional_image_properties=True)
request = unit_test_utils.get_fake_request()
request.body = jsonutils.dump_as_bytes({'stores': 'test'})
self.assertRaises(webob.exc.HTTPForbidden,
self.deserializer.create, request)
def test_update(self): def test_update(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
request.content_type = 'application/openstack-images-v2.1-json-patch' request.content_type = 'application/openstack-images-v2.1-json-patch'
doc = [{'op': 'add', 'path': '/foo', 'value': 'bar'}] doc = [{'op': 'add', 'path': '/foo', 'value': 'bar'}]
request.body = jsonutils.dump_as_bytes(doc) request.body = jsonutils.dump_as_bytes(doc)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.deserializer.update, request) self.deserializer.update, request)
class TestImagesSerializer(test_utils.BaseTestCase): class TestImagesSerializer(test_utils.BaseTestCase):
skipping to change at line 5228 skipping to change at line 5238
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.import_image, self.controller.import_image,
request, 'invalid_image', request, 'invalid_image',
{'method': {'name': 'glance-direct'}}) {'method': {'name': 'glance-direct'}})
def test_image_import_with_active_image(self): def test_image_import_with_active_image(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller.import_image, self.controller.import_image,
request, UUID1, request, UUID2,
{'method': {'name': 'glance-direct'}}) {'method': {'name': 'glance-direct'}})
def test_delete_from_store_as_non_owner(self): def test_delete_from_store_as_non_owner(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
self.assertRaises(webob.exc.HTTPForbidden, self.assertRaises(webob.exc.HTTPForbidden,
self.controller.delete_from_store, self.controller.delete_from_store,
request, request,
"fast", "fast",
UUID6) UUID6)
skipping to change at line 5416 skipping to change at line 5426
with mock.patch.object( with mock.patch.object(
glance.api.authorization.ImageRepoProxy, 'get') as mock_get: glance.api.authorization.ImageRepoProxy, 'get') as mock_get:
mock_get.return_value = FakeImage(status='uploading') mock_get.return_value = FakeImage(status='uploading')
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
self.controller.import_image, request, UUID1, self.controller.import_image, request, UUID1,
{'method': {'name': 'copy-image'}, {'method': {'name': 'copy-image'},
'stores': ["fast"]}) 'stores': ["fast"]})
def test_copy_image_in_existing_store(self): def test_copy_image_in_existing_store(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request(tenant=TENANT3)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.import_image, request, UUID6, self.controller.import_image, request, UUID6,
{'method': {'name': 'copy-image'}, {'method': {'name': 'copy-image'},
'stores': ["fast"]}) 'stores': ["fast"]})
def test_copy_image_to_other_stores(self): def test_copy_image_to_other_stores(self):
request = unit_test_utils.get_fake_request() request = unit_test_utils.get_fake_request()
locations = {'url': 'file://%s/%s' % (self.test_dir, locations = {'url': 'file://%s/%s' % (self.test_dir,
UUID7), UUID7),
'metadata': {'store': 'fast'}, 'metadata': {'store': 'fast'},
 End of changes. 5 change blocks. 
14 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)