Implements cleaner fake_request.
Implements the fake request to be more flexible. Changes the fake request calls in the tests. fixes bug 1010191 Change-Id: Ic8199b1f8f479ffb3667cead2576c03591e30e43
This commit is contained in:
parent
ba0e3afbb2
commit
c4c69ac15c
@ -33,18 +33,20 @@ USER1 = '54492ba0-f4df-4e4e-be62-27f4d76b29cf'
|
|||||||
USER2 = '0b3b3006-cb76-4517-ae32-51397e22c754'
|
USER2 = '0b3b3006-cb76-4517-ae32-51397e22c754'
|
||||||
|
|
||||||
|
|
||||||
class FakeRequest(wsgi.Request):
|
def get_fake_request(path='', method='POST'):
|
||||||
def __init__(self):
|
req = wsgi.Request.blank(path)
|
||||||
#TODO(bcwaldon): figure out how to fake this out cleanly
|
req.method = method
|
||||||
super(FakeRequest, self).__init__({'REQUEST_METHOD': 'POST'})
|
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'user': USER1,
|
'user': USER1,
|
||||||
'tenant': TENANT1,
|
'tenant': TENANT1,
|
||||||
'roles': [],
|
'roles': [],
|
||||||
'is_admin': False,
|
'is_admin': False,
|
||||||
}
|
}
|
||||||
self.context = glance.common.context.RequestContext(**kwargs)
|
|
||||||
|
req.context = glance.common.context.RequestContext(**kwargs)
|
||||||
|
|
||||||
|
return req
|
||||||
|
|
||||||
|
|
||||||
class FakeDB(object):
|
class FakeDB(object):
|
||||||
|
@ -33,7 +33,7 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
self.controller = image_access.Controller({}, self.db)
|
self.controller = image_access.Controller({}, self.db)
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req, unit_test_utils.UUID1)
|
output = self.controller.index(req, unit_test_utils.UUID1)
|
||||||
expected = [
|
expected = [
|
||||||
{
|
{
|
||||||
@ -52,19 +52,19 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_index_zero_records(self):
|
def test_index_zero_records(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req, unit_test_utils.UUID2)
|
output = self.controller.index(req, unit_test_utils.UUID2)
|
||||||
expected = []
|
expected = []
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_index_nonexistant_image(self):
|
def test_index_nonexistant_image(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
image_id = utils.generate_uuid()
|
image_id = utils.generate_uuid()
|
||||||
self.assertRaises(exception.NotFound,
|
self.assertRaises(exception.NotFound,
|
||||||
self.controller.index, req, image_id)
|
self.controller.index, req, image_id)
|
||||||
|
|
||||||
def test_show(self):
|
def test_show(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
image_id = unit_test_utils.UUID1
|
image_id = unit_test_utils.UUID1
|
||||||
tenant_id = unit_test_utils.TENANT1
|
tenant_id = unit_test_utils.TENANT1
|
||||||
output = self.controller.show(req, image_id, tenant_id)
|
output = self.controller.show(req, image_id, tenant_id)
|
||||||
@ -77,14 +77,14 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_show_nonexistant_image(self):
|
def test_show_nonexistant_image(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
image_id = utils.generate_uuid()
|
image_id = utils.generate_uuid()
|
||||||
tenant_id = unit_test_utils.TENANT1
|
tenant_id = unit_test_utils.TENANT1
|
||||||
self.assertRaises(webob.exc.HTTPNotFound,
|
self.assertRaises(webob.exc.HTTPNotFound,
|
||||||
self.controller.show, req, image_id, tenant_id)
|
self.controller.show, req, image_id, tenant_id)
|
||||||
|
|
||||||
def test_show_nonexistant_tenant(self):
|
def test_show_nonexistant_tenant(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
image_id = unit_test_utils.UUID1
|
image_id = unit_test_utils.UUID1
|
||||||
tenant_id = utils.generate_uuid()
|
tenant_id = utils.generate_uuid()
|
||||||
self.assertRaises(webob.exc.HTTPNotFound,
|
self.assertRaises(webob.exc.HTTPNotFound,
|
||||||
@ -102,7 +102,7 @@ class TestImageAccessController(test_utils.BaseTestCase):
|
|||||||
'can_share': True,
|
'can_share': True,
|
||||||
'deleted': False,
|
'deleted': False,
|
||||||
}
|
}
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.create(req, unit_test_utils.UUID1, fixture)
|
output = self.controller.create(req, unit_test_utils.UUID1, fixture)
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class TestImageAccessDeserializer(test_utils.BaseTestCase):
|
|||||||
'can_share': False,
|
'can_share': False,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps(fixture)
|
request.body = json.dumps(fixture)
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
@ -159,7 +159,7 @@ class TestImageAccessDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
|||||||
'color': 'blue',
|
'color': 'blue',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps(fixture)
|
request.body = json.dumps(fixture)
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
@ -170,7 +170,7 @@ class TestImageAccessDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
|||||||
'can_share': False,
|
'can_share': False,
|
||||||
'color': 'purple',
|
'color': 'purple',
|
||||||
}
|
}
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps(fixture)
|
request.body = json.dumps(fixture)
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.create, request)
|
self.deserializer.create, request)
|
||||||
|
@ -36,40 +36,40 @@ class TestImagesController(base.StoreClearingUnitTest):
|
|||||||
store_api=unit_test_utils.FakeStoreAPI())
|
store_api=unit_test_utils.FakeStoreAPI())
|
||||||
|
|
||||||
def test_download(self):
|
def test_download(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.download(request, unit_test_utils.UUID1)
|
output = self.controller.download(request, unit_test_utils.UUID1)
|
||||||
expected = {'data': 'XXX', 'size': 3}
|
expected = {'data': 'XXX', 'size': 3}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_download_no_data(self):
|
def test_download_no_data(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.download,
|
self.assertRaises(webob.exc.HTTPNotFound, self.controller.download,
|
||||||
request, unit_test_utils.UUID2)
|
request, unit_test_utils.UUID2)
|
||||||
|
|
||||||
def test_download_non_existant_image(self):
|
def test_download_non_existant_image(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.download,
|
self.assertRaises(webob.exc.HTTPNotFound, self.controller.download,
|
||||||
request, utils.generate_uuid())
|
request, utils.generate_uuid())
|
||||||
|
|
||||||
def test_upload_download(self):
|
def test_upload_download(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', 4)
|
self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', 4)
|
||||||
output = self.controller.download(request, unit_test_utils.UUID2)
|
output = self.controller.download(request, unit_test_utils.UUID2)
|
||||||
expected = {'data': 'YYYY', 'size': 4}
|
expected = {'data': 'YYYY', 'size': 4}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_upload_non_existant_image(self):
|
def test_upload_non_existant_image(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.upload,
|
self.assertRaises(webob.exc.HTTPNotFound, self.controller.upload,
|
||||||
request, utils.generate_uuid(), 'YYYY', 4)
|
request, utils.generate_uuid(), 'YYYY', 4)
|
||||||
|
|
||||||
def test_upload_data_exists(self):
|
def test_upload_data_exists(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.assertRaises(webob.exc.HTTPConflict, self.controller.upload,
|
self.assertRaises(webob.exc.HTTPConflict, self.controller.upload,
|
||||||
request, unit_test_utils.UUID1, 'YYYY', 4)
|
request, unit_test_utils.UUID1, 'YYYY', 4)
|
||||||
|
|
||||||
def test_upload_download_no_size(self):
|
def test_upload_download_no_size(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', None)
|
self.controller.upload(request, unit_test_utils.UUID2, 'YYYY', None)
|
||||||
output = self.controller.download(request, unit_test_utils.UUID2)
|
output = self.controller.download(request, unit_test_utils.UUID2)
|
||||||
expected = {'data': 'YYYY', 'size': 4}
|
expected = {'data': 'YYYY', 'size': 4}
|
||||||
@ -83,7 +83,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase):
|
|||||||
self.deserializer = glance.api.v2.image_data.RequestDeserializer()
|
self.deserializer = glance.api.v2.image_data.RequestDeserializer()
|
||||||
|
|
||||||
def test_upload(self):
|
def test_upload(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.headers['Content-Type'] = 'application/octet-stream'
|
request.headers['Content-Type'] = 'application/octet-stream'
|
||||||
request.body = 'YYY'
|
request.body = 'YYY'
|
||||||
request.headers['Content-Length'] = 3
|
request.headers['Content-Length'] = 3
|
||||||
@ -94,7 +94,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_upload_chunked(self):
|
def test_upload_chunked(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.headers['Content-Type'] = 'application/octet-stream'
|
request.headers['Content-Type'] = 'application/octet-stream'
|
||||||
# If we use body_file, webob assumes we want to do a chunked upload,
|
# If we use body_file, webob assumes we want to do a chunked upload,
|
||||||
# ignoring the Content-Length header
|
# ignoring the Content-Length header
|
||||||
@ -106,7 +106,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_upload_chunked_with_content_length(self):
|
def test_upload_chunked_with_content_length(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.headers['Content-Type'] = 'application/octet-stream'
|
request.headers['Content-Type'] = 'application/octet-stream'
|
||||||
request.body_file = StringIO.StringIO('YYY')
|
request.body_file = StringIO.StringIO('YYY')
|
||||||
# The deserializer shouldn't care if the Content-Length is
|
# The deserializer shouldn't care if the Content-Length is
|
||||||
@ -119,7 +119,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_upload_with_incorrect_content_length(self):
|
def test_upload_with_incorrect_content_length(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.headers['Content-Type'] = 'application/octet-stream'
|
request.headers['Content-Type'] = 'application/octet-stream'
|
||||||
# The deserializer shouldn't care if the Content-Length and
|
# The deserializer shouldn't care if the Content-Length and
|
||||||
# actual request body length differ. That job is left up
|
# actual request body length differ. That job is left up
|
||||||
@ -133,7 +133,7 @@ class TestImageDataDeserializer(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_upload_wrong_content_type(self):
|
def test_upload_wrong_content_type(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.headers['Content-Type'] = 'application/json'
|
request.headers['Content-Type'] = 'application/json'
|
||||||
request.body = 'YYYYY'
|
request.body = 'YYYYY'
|
||||||
self.assertRaises(webob.exc.HTTPUnsupportedMediaType,
|
self.assertRaises(webob.exc.HTTPUnsupportedMediaType,
|
||||||
|
@ -31,21 +31,21 @@ class TestImageTagsController(test_utils.BaseTestCase):
|
|||||||
self.controller = glance.api.v2.image_tags.Controller(conf, self.db)
|
self.controller = glance.api.v2.image_tags.Controller(conf, self.db)
|
||||||
|
|
||||||
def test_list_tags(self):
|
def test_list_tags(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
tags = self.controller.index(request, unit_test_utils.UUID1)
|
tags = self.controller.index(request, unit_test_utils.UUID1)
|
||||||
expected = ['ping', 'pong']
|
expected = ['ping', 'pong']
|
||||||
self.assertEqual(expected, tags)
|
self.assertEqual(expected, tags)
|
||||||
|
|
||||||
def test_create_tag(self):
|
def test_create_tag(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.controller.update(request, unit_test_utils.UUID1, 'dink')
|
self.controller.update(request, unit_test_utils.UUID1, 'dink')
|
||||||
|
|
||||||
def test_delete_tag(self):
|
def test_delete_tag(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.controller.delete(request, unit_test_utils.UUID1, 'ping')
|
self.controller.delete(request, unit_test_utils.UUID1, 'ping')
|
||||||
|
|
||||||
def test_delete_tag_not_found(self):
|
def test_delete_tag_not_found(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
|
||||||
request, unit_test_utils.UUID1, 'what')
|
request, unit_test_utils.UUID1, 'what')
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
self.controller = glance.api.v2.images.ImagesController({}, self.db)
|
self.controller = glance.api.v2.images.ImagesController({}, self.db)
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(request)
|
output = self.controller.index(request)
|
||||||
self.assertEqual(2, len(output))
|
self.assertEqual(2, len(output))
|
||||||
self.assertEqual(output[0]['id'], unit_test_utils.UUID1)
|
self.assertEqual(output[0]['id'], unit_test_utils.UUID1)
|
||||||
@ -46,12 +46,12 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_index_zero_images(self):
|
def test_index_zero_images(self):
|
||||||
self.db.reset()
|
self.db.reset()
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(request)
|
output = self.controller.index(request)
|
||||||
self.assertEqual([], output)
|
self.assertEqual([], output)
|
||||||
|
|
||||||
def test_show(self):
|
def test_show(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.show(request, image_id=unit_test_utils.UUID2)
|
output = self.controller.show(request, image_id=unit_test_utils.UUID2)
|
||||||
for key in ['created_at', 'updated_at']:
|
for key in ['created_at', 'updated_at']:
|
||||||
output.pop(key)
|
output.pop(key)
|
||||||
@ -69,11 +69,13 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_show_non_existant(self):
|
def test_show_non_existant(self):
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.show,
|
request = unit_test_utils.get_fake_request()
|
||||||
unit_test_utils.FakeRequest(), image_id=utils.generate_uuid())
|
image_id = utils.generate_uuid()
|
||||||
|
self.assertRaises(webob.exc.HTTPNotFound,
|
||||||
|
self.controller.show, request, image_id)
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image = {'name': 'image-1'}
|
image = {'name': 'image-1'}
|
||||||
output = self.controller.create(request, image)
|
output = self.controller.create(request, image)
|
||||||
for key in ['id', 'created_at', 'updated_at']:
|
for key in ['id', 'created_at', 'updated_at']:
|
||||||
@ -90,13 +92,13 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_with_owner_forbidden(self):
|
def test_create_with_owner_forbidden(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image = {'name': 'image-1', 'owner': utils.generate_uuid()}
|
image = {'name': 'image-1', 'owner': utils.generate_uuid()}
|
||||||
self.assertRaises(webob.exc.HTTPForbidden, self.controller.create,
|
self.assertRaises(webob.exc.HTTPForbidden, self.controller.create,
|
||||||
request, image)
|
request, image)
|
||||||
|
|
||||||
def test_create_public_image_as_admin(self):
|
def test_create_public_image_as_admin(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image = {'name': 'image-1', 'is_public': True}
|
image = {'name': 'image-1', 'is_public': True}
|
||||||
output = self.controller.create(request, image)
|
output = self.controller.create(request, image)
|
||||||
for key in ['id', 'created_at', 'updated_at']:
|
for key in ['id', 'created_at', 'updated_at']:
|
||||||
@ -113,7 +115,7 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image = {'name': 'image-2'}
|
image = {'name': 'image-2'}
|
||||||
output = self.controller.update(request, unit_test_utils.UUID1, image)
|
output = self.controller.update(request, unit_test_utils.UUID1, image)
|
||||||
for key in ['id', 'created_at', 'updated_at']:
|
for key in ['id', 'created_at', 'updated_at']:
|
||||||
@ -130,7 +132,7 @@ class TestImagesController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_update_non_existant(self):
|
def test_update_non_existant(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image = {'name': 'image-2'}
|
image = {'name': 'image-2'}
|
||||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
|
self.assertRaises(webob.exc.HTTPNotFound, self.controller.update,
|
||||||
request, utils.generate_uuid(), image)
|
request, utils.generate_uuid(), image)
|
||||||
@ -145,7 +147,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||||||
{}, schema_api)
|
{}, schema_api)
|
||||||
|
|
||||||
def test_create_with_id(self):
|
def test_create_with_id(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
image_id = utils.generate_uuid()
|
image_id = utils.generate_uuid()
|
||||||
request.body = json.dumps({'id': image_id})
|
request.body = json.dumps({'id': image_id})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
@ -153,21 +155,21 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_with_name(self):
|
def test_create_with_name(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1'})
|
request.body = json.dumps({'name': 'image-1'})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'name': 'image-1', 'properties': {}}}
|
expected = {'image': {'name': 'image-1', 'properties': {}}}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_public(self):
|
def test_create_public(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'visibility': 'public'})
|
request.body = json.dumps({'visibility': 'public'})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'is_public': True, 'properties': {}}}
|
expected = {'image': {'is_public': True, 'properties': {}}}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_private(self):
|
def test_create_private(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'visibility': 'private'})
|
request.body = json.dumps({'visibility': 'private'})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'is_public': False, 'properties': {}}}
|
expected = {'image': {'is_public': False, 'properties': {}}}
|
||||||
@ -175,21 +177,21 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_create_readonly_attributes_ignored(self):
|
def test_create_readonly_attributes_ignored(self):
|
||||||
for key in ['created_at', 'updated_at']:
|
for key in ['created_at', 'updated_at']:
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({key: ISOTIME})
|
request.body = json.dumps({key: ISOTIME})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'properties': {}}}
|
expected = {'image': {'properties': {}}}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_with_tags(self):
|
def test_create_with_tags(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'tags': ['one', 'two']})
|
request.body = json.dumps({'tags': ['one', 'two']})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'tags': ['one', 'two'], 'properties': {}}}
|
expected = {'image': {'tags': ['one', 'two'], 'properties': {}}}
|
||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1', 'visibility': 'public'})
|
request.body = json.dumps({'name': 'image-1', 'visibility': 'public'})
|
||||||
output = self.deserializer.update(request)
|
output = self.deserializer.update(request)
|
||||||
expected = {
|
expected = {
|
||||||
@ -203,7 +205,7 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_update_readonly_attributes_ignored(self):
|
def test_update_readonly_attributes_ignored(self):
|
||||||
for key in ['created_at', 'updated_at']:
|
for key in ['created_at', 'updated_at']:
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({key: ISOTIME})
|
request.body = json.dumps({key: ISOTIME})
|
||||||
output = self.deserializer.update(request)
|
output = self.deserializer.update(request)
|
||||||
expected = {'image': {'properties': {}}}
|
expected = {'image': {'properties': {}}}
|
||||||
@ -227,7 +229,7 @@ class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
|||||||
{}, schema_api)
|
{}, schema_api)
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1', 'pants': 'on'})
|
request.body = json.dumps({'name': 'image-1', 'pants': 'on'})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {
|
expected = {
|
||||||
@ -239,13 +241,13 @@ class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_create_bad_data(self):
|
def test_create_bad_data(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1', 'pants': 'borked'})
|
request.body = json.dumps({'name': 'image-1', 'pants': 'borked'})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.create, request)
|
self.deserializer.create, request)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1', 'pants': 'off'})
|
request.body = json.dumps({'name': 'image-1', 'pants': 'off'})
|
||||||
output = self.deserializer.update(request)
|
output = self.deserializer.update(request)
|
||||||
expected = {
|
expected = {
|
||||||
@ -257,7 +259,7 @@ class TestImagesDeserializerWithExtendedSchema(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_update_bad_data(self):
|
def test_update_bad_data(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'name': 'image-1', 'pants': 'borked'})
|
request.body = json.dumps({'name': 'image-1', 'pants': 'borked'})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.update, request)
|
self.deserializer.update, request)
|
||||||
@ -273,7 +275,7 @@ class TestImagesDeserializerWithAdditionalProperties(test_utils.BaseTestCase):
|
|||||||
{}, schema_api)
|
{}, schema_api)
|
||||||
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'foo': 'bar'})
|
request.body = json.dumps({'foo': 'bar'})
|
||||||
output = self.deserializer.create(request)
|
output = self.deserializer.create(request)
|
||||||
expected = {'image': {'properties': {'foo': 'bar'}}}
|
expected = {'image': {'properties': {'foo': 'bar'}}}
|
||||||
@ -281,25 +283,25 @@ class TestImagesDeserializerWithAdditionalProperties(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
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.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'foo': 'bar'})
|
request.body = json.dumps({'foo': 'bar'})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.create, request)
|
self.deserializer.create, request)
|
||||||
|
|
||||||
def test_create_with_numeric_property(self):
|
def test_create_with_numeric_property(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'abc': 123})
|
request.body = json.dumps({'abc': 123})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.create, request)
|
self.deserializer.create, request)
|
||||||
|
|
||||||
def test_create_with_list_property(self):
|
def test_create_with_list_property(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'foo': ['bar']})
|
request.body = json.dumps({'foo': ['bar']})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.create, request)
|
self.deserializer.create, request)
|
||||||
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'foo': 'bar'})
|
request.body = json.dumps({'foo': 'bar'})
|
||||||
output = self.deserializer.update(request)
|
output = self.deserializer.update(request)
|
||||||
expected = {'image': {'properties': {'foo': 'bar'}}}
|
expected = {'image': {'properties': {'foo': 'bar'}}}
|
||||||
@ -307,7 +309,7 @@ class TestImagesDeserializerWithAdditionalProperties(test_utils.BaseTestCase):
|
|||||||
|
|
||||||
def test_update_with_additional_properties_disallowed(self):
|
def test_update_with_additional_properties_disallowed(self):
|
||||||
self.config(allow_additional_image_properties=False)
|
self.config(allow_additional_image_properties=False)
|
||||||
request = unit_test_utils.FakeRequest()
|
request = unit_test_utils.get_fake_request()
|
||||||
request.body = json.dumps({'foo': 'bar'})
|
request.body = json.dumps({'foo': 'bar'})
|
||||||
self.assertRaises(exception.InvalidObject,
|
self.assertRaises(exception.InvalidObject,
|
||||||
self.deserializer.update, request)
|
self.deserializer.update, request)
|
||||||
|
@ -25,7 +25,7 @@ class TestRootController(test_utils.BaseTestCase):
|
|||||||
self.controller = glance.api.v2.root.RootController()
|
self.controller = glance.api.v2.root.RootController()
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req)
|
output = self.controller.index(req)
|
||||||
expected = {
|
expected = {
|
||||||
'links': [
|
'links': [
|
||||||
|
@ -27,7 +27,7 @@ class TestSchemasController(test_utils.BaseTestCase):
|
|||||||
self.controller = schemas.Controller({}, self.schema_api)
|
self.controller = schemas.Controller({}, self.schema_api)
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.index(req)
|
output = self.controller.index(req)
|
||||||
expected = {'links': [
|
expected = {'links': [
|
||||||
{'rel': 'image', 'href': '/v2/schemas/image'},
|
{'rel': 'image', 'href': '/v2/schemas/image'},
|
||||||
@ -36,11 +36,11 @@ class TestSchemasController(test_utils.BaseTestCase):
|
|||||||
self.assertEqual(expected, output)
|
self.assertEqual(expected, output)
|
||||||
|
|
||||||
def test_image(self):
|
def test_image(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.image(req)
|
output = self.controller.image(req)
|
||||||
self.assertEqual(self.schema_api.get_schema('image'), output)
|
self.assertEqual(self.schema_api.get_schema('image'), output)
|
||||||
|
|
||||||
def test_access(self):
|
def test_access(self):
|
||||||
req = unit_test_utils.FakeRequest()
|
req = unit_test_utils.get_fake_request()
|
||||||
output = self.controller.access(req)
|
output = self.controller.access(req)
|
||||||
self.assertEqual(self.schema_api.get_schema('access'), output)
|
self.assertEqual(self.schema_api.get_schema('access'), output)
|
||||||
|
Loading…
Reference in New Issue
Block a user