"""Default JSON request body serialization."""
def default(self, data):
- return jsonutils.dumps(data)
+ return jsonutils.dump_as_bytes(data)
class XMLDictSerializer(DictSerializer):
self.limiter_address = limiter_address
def check_for_delay(self, verb, path, username=None):
- body = jsonutils.dumps({"verb": verb, "path": path})
+ body = jsonutils.dump_as_bytes({"verb": verb, "path": path})
headers = {"Content-Type": "application/json"}
conn = http_client.HTTPConnection(self.limiter_address)
self.limiter_address = limiter_address
def check_for_delay(self, verb, path, username=None):
- body = jsonutils.dumps({"verb": verb, "path": path})
+ body = jsonutils.dump_as_bytes({"verb": verb, "path": path})
headers = {"Content-Type": "application/json"}
conn = http_client.HTTPConnection(self.limiter_address)
"""The volumes snapshots api."""
from oslo_log import log as logging
+from oslo_utils import encodeutils
from oslo_utils import strutils
import webob
from webob import exc
try:
force = strutils.bool_from_string(force, strict=True)
except ValueError as error:
- msg = _("Invalid value for 'force': '%s'") % error.message
+ err_msg = encodeutils.exception_to_unicode(error)
+ msg = _("Invalid value for 'force': '%s'") % err_msg
raise exception.InvalidParameterValue(err=msg)
if force:
class JSONDictSerializerTest(test.TestCase):
def test_json(self):
input_dict = dict(servers=dict(a=(2, 3)))
- expected_json = '{"servers":{"a":[2,3]}}'
+ expected_json = b'{"servers":{"a":[2,3]}}'
serializer = wsgi.JSONDictSerializer()
result = serializer.serialize(input_dict)
- result = result.replace('\n', '').replace(' ', '')
+ result = result.replace(b'\n', b'').replace(b' ', b'')
self.assertEqual(expected_json, result)
def _request_data(self, verb, path):
"""Get data describing a limit request verb/path."""
- return jsonutils.dumps({"verb": verb, "path": path})
+ return jsonutils.dump_as_bytes({"verb": verb, "path": path})
def _request(self, verb, url, username=None):
"""Assert that POSTing to given url triggers given action.
def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
- self._buffer = six.StringIO(response_string)
+ if isinstance(response_string, six.text_type):
+ response_string = response_string.encode('utf-8')
+ self._buffer = six.BytesIO(response_string)
- def makefile(self, _mode, _other):
+ def makefile(self, mode, *args):
"""Returns the socket's internal buffer."""
return self._buffer
delay, error = self.proxy.check_for_delay("GET", "/delayed")
error = error.strip()
- expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
- "made to /delayed every minute.")
+ expected = ("60.00",
+ b"403 Forbidden\n\nOnly 1 GET request(s) can be "
+ b"made to /delayed every minute.")
self.assertEqual(expected, (delay, error))
"absolute": {}}}
output = serializer.serialize(fixture)
- has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
+ has_dec = output.startswith(b"<?xml version='1.0' encoding='UTF-8'?>")
self.assertTrue(has_dec)
def test_index(self):
body = {"metadata": {"key1": "value1",
"key2": "value2",
"key3": "value3"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(body, res_dict)
"key2": "value2",
"key3": "value3",
"KEY4": "value4"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(expected, res_dict)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.create, req, self.req_id, body)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, expected)
self.assertEqual(expected, res_dict)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, body)
self.assertEqual(expected, res_dict)
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, expected)
self.assertEqual(expected, res_dict)
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
res_dict = self.controller.update(req, self.req_id, 'key1', body)
expected = {'meta': {'key1': 'value1'}}
'/v1.1/fake/snapshots/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 260)}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
# test for long key
data = {"metadata": {"a" * 260: "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
self.controller.create, req, self.req_id, data)
# test for long value
data = {"metadata": {"key": "v" * 260}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
self.controller.create, req, self.req_id, data)
# test for empty key.
data = {"metadata": {"": "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.req_id, data)
# Just getting some input data
vtypes = return_volume_types_get_all_types(None)
- text = serializer.serialize({'volume_types': vtypes.values()})
+ text = serializer.serialize({'volume_types': list(vtypes.values())})
tree = etree.fromstring(text)
body = {"metadata": {"key1": "value1",
"key2": "value2",
"key3": "value3", }}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
"key2": "value2",
"key3": "value3",
"KEY4": "value4"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.create, req, self.req_id, body)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 260)}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank('/v1.1/fake/volumes/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
# test for long key
data = {"metadata": {"a" * 260: "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
# test for long value
data = {"metadata": {"key": "v" * 260}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
# test for empty key.
data = {"metadata": {"": "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
def _request_data(self, verb, path):
"""Get data describing a limit request verb/path."""
- return jsonutils.dumps({"verb": verb, "path": path})
+ return jsonutils.dump_as_bytes({"verb": verb, "path": path})
def _request(self, verb, url, username=None):
"""POST request to given url by given username.
def __init__(self, response_string):
"""Initialize new `FakeHttplibSocket`."""
- self._buffer = six.StringIO(response_string)
+ if isinstance(response_string, six.text_type):
+ response_string = response_string.encode('utf-8')
+ self._buffer = six.BytesIO(response_string)
- def makefile(self, _mode, _other):
+ def makefile(self, mode, *args):
"""Returns the socket's internal buffer."""
return self._buffer
delay, error = self.proxy.check_for_delay("GET", "/delayed")
error = error.strip()
- expected = ("60.00", "403 Forbidden\n\nOnly 1 GET request(s) can be "
- "made to /delayed every minute.")
+ expected = ("60.00",
+ b"403 Forbidden\n\nOnly 1 GET request(s) can be "
+ b"made to /delayed every minute.")
self.assertEqual(expected, (delay, error))
"absolute": {}}}
output = serializer.serialize(fixture)
- has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
+ has_dec = output.startswith(b"<?xml version='1.0' encoding='UTF-8'?>")
self.assertTrue(has_dec)
def test_index(self):
body = {"metadata": {"key1": "value1",
"key2": "value2",
"key3": "value3"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(body, res_dict)
"key2": "value2",
"key3": "value3",
"KEY4": "value4"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
res_dict = self.controller.create(req, self.req_id, body)
self.assertEqual(expected, res_dict)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.create, req, self.req_id, body)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, expected)
self.assertEqual(expected, res_dict)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, body)
self.assertEqual(expected, res_dict)
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
res_dict = self.controller.update_all(req, self.req_id, expected)
self.assertEqual(expected, res_dict)
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
res_dict = self.controller.update(req, self.req_id, 'key1', body)
expected = {'meta': {'key1': 'value1'}}
'/v2/fake/snapshots/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 260)}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
# test for long key
data = {"metadata": {"a" * 260: "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
self.controller.create, req, self.req_id, data)
# test for long value
data = {"metadata": {"key": "v" * 260}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
self.controller.create, req, self.req_id, data)
# test for empty key.
data = {"metadata": {"": "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create, req, self.req_id, data)
vol_type_3=stub_volume_type(3)
)
if list_result:
- return result.values()
+ return list(result.values())
return result
# Just getting some input data
vtypes = return_volume_types_get_all_types(None)
- text = serializer.serialize({'volume_types': vtypes.values()})
+ text = serializer.serialize({'volume_types': list(vtypes.values())})
tree = etree.fromstring(text)
body = {"metadata": {"key1": "value1",
"key2": "value2",
"key3": "value3", }}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
body = {"metadata": {"key1": "value1",
"key2": "value2",
"key3": "value3", }}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
"key2": "value2",
"key3": "value3",
"KEY4": "value4"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req.method = 'POST'
req.content_type = "application/json"
body = {"metadata": {"key9": "value9"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.create, req, self.req_id, body)
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
'KEY20': 'value20',
},
}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'meta': {}}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
expected = {'metadata': ['asdf']}
- req.body = jsonutils.dumps(expected)
+ req.body = jsonutils.dump_as_bytes(expected)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update_all, req, self.req_id,
req.method = 'PUT'
req.content_type = "application/json"
body = {'metadata': {'key10': 'value10'}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
self.assertRaises(webob.exc.HTTPNotFound,
self.controller.update_all, req, '100', body)
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank('/v2/fake/volumes/asdf/metadata/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPNotFound,
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {("a" * 260): "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": ("a" * 260)}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
req.environ['cinder.context'] = fake_context
req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT'
body = {"meta": {"key1": "value1", "key2": "value2"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT'
body = {"meta": {"key1": "value1"}}
- req.body = jsonutils.dumps(body)
+ req.body = jsonutils.dump_as_bytes(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
# test for long key
data = {"metadata": {"a" * 260: "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
# test for long value
data = {"metadata": {"key": "v" * 260}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
# test for empty key.
data = {"metadata": {"": "value1"}}
- req.body = jsonutils.dumps(data)
+ req.body = jsonutils.dump_as_bytes(data)
req.environ['cinder.context'] = fake_context
with mock.patch.object(self.controller.volume_api,
cinder.tests.unit.api.test_extensions
cinder.tests.unit.api.test_versions
cinder.tests.unit.api.test_xmlutil
-cinder.tests.unit.api.v2.test_volumes
+cinder.tests.unit.api.v1
+cinder.tests.unit.api.v2
cinder.tests.unit.backup.drivers.test_backup_glusterfs
cinder.tests.unit.backup.drivers.test_backup_nfs
cinder.tests.unit.backup.drivers.test_backup_posix