Adds encapsulation control to the client

https://review.openstack.org/#/c/108795/ adds the requirement
to encapsulate messages in JSON objects in API v1.1

This change adds that control to the Zaqar client maintaining
backwards compatibility with v1

Change-Id: I1723b843320ebcf2722fb4f6fcaaa6e1c63248e9
This commit is contained in:
Victoria Martínez de la Cruz 2014-10-21 14:26:28 -03:00
parent 4e60be59b2
commit 369ac1ebb4
2 changed files with 22 additions and 2 deletions

View File

@ -98,8 +98,25 @@ class TestV1Core(base.TestBase):
result = core.queue_get_stats(self.transport, req, 'test')
self.assertEqual(result, {})
def test_message_post(self):
messages = [{'ttl': 30, 'body': 'Post It!'}]
def test_message_post_one(self):
messages = {'ttl': 30, 'body': 'Post one!'}
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
resp = response.Response(None, '{}')
send_method.return_value = resp
req = request.Request()
core.message_post(self.transport, req, 'test', messages)
self.assertIn('queue_name', req.params)
self.assertEqual(json.loads(req.content),
messages)
def test_message_post_many(self):
messages = [{'ttl': 30, 'body': 'Post one!'},
{'ttl': 30, 'body': 'Post two!'},
{'ttl': 30, 'body': 'Post three!'}, ]
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:

View File

@ -108,6 +108,9 @@ class Queue(object):
if not isinstance(messages, list):
messages = [messages]
if self.client.api_version >= 1.1:
messages = {'messages': messages}
req, trans = self.client._request_and_transport()
# TODO(flaper87): Return a list of messages