Basic resource.prop for ID attributes (message)

This patch set updates all message objects to use basic
properties for ID attributes. In particular, the following changes
were made:
  - Use basic *_id properties for ID attributes
  - Clarify documentation for ID attributes

Change-Id: I8edfdf57e0411f01c41145f58182be9a8e5a47b0
Partial-Bug: #1461200
This commit is contained in:
Richard Theis 2016-02-18 09:12:16 -06:00
parent 1dfcedaee2
commit f938857a4d
4 changed files with 39 additions and 30 deletions

View File

@ -29,17 +29,17 @@ class Claim(resource.Resource):
allow_retrieve = False
allow_delete = False
#: A UUID for each client instance. The UUID must be submitted in its
#: A ID for each client instance. The ID must be submitted in its
#: canonical form (for example, 3381af92-2b9e-11e3-b191-71861300734c).
#: The client generates this UUID once. The client UUID persists between
#: restarts of the client so the client should reuse that same UUID.
#: All message-related operations require the use of the client UUID in
#: The client generates this ID once. The client ID persists between
#: restarts of the client so the client should reuse that same ID.
#: All message-related operations require the use of the client ID in
#: the headers to ensure that messages are not echoed back to the client
#: that posted them, unless the client explicitly requests this.
client = None
client_id = None
#: The queue this Claim belongs to.
queue = None
#: The name of the queue this Claim belongs to.
queue_name = None
#: Specifies the number of Messages to return.
limit = None
@ -54,8 +54,8 @@ class Claim(resource.Resource):
@classmethod
def claim_messages(cls, session, claim):
"""Create a remote resource from this instance."""
url = cls._get_url({'queue_name': claim.queue})
headers = {'Client-ID': claim.client}
url = cls._get_url({'queue_name': claim.queue_name})
headers = {'Client-ID': claim.client_id}
params = {'limit': claim.limit} if claim.limit else None
body = []
@ -77,7 +77,9 @@ class Claim(resource.Resource):
for message_attrs in body:
yield message.Message.new(
client=claim.client, queue=claim.queue, **message_attrs)
client_id=claim.client_id,
queue_name=claim.queue_name,
**message_attrs)
class ClaimEncoder(json.JSONEncoder):

View File

@ -29,17 +29,17 @@ class Message(resource.Resource):
allow_retrieve = False
allow_delete = False
#: A UUID for each client instance. The UUID must be submitted in its
#: A ID for each client instance. The ID must be submitted in its
#: canonical form (for example, 3381af92-2b9e-11e3-b191-71861300734c).
#: The client generates this UUID once. The client UUID persists between
#: restarts of the client so the client should reuse that same UUID.
#: All message-related operations require the use of the client UUID in
#: The client generates this ID once. The client ID persists between
#: restarts of the client so the client should reuse that same ID.
#: All message-related operations require the use of the client ID in
#: the headers to ensure that messages are not echoed back to the client
#: that posted them, unless the client explicitly requests this.
client = None
client_id = None
#: The queue this Message belongs to.
queue = None
#: The name of the queue this Message belongs to.
queue_name = None
#: A relative href that references this Message.
href = resource.prop("href")
@ -61,13 +61,13 @@ class Message(resource.Resource):
raise ValueError('messages cannot be empty')
for i, message in enumerate(messages, -1):
if message.queue != messages[i].queue:
if message.queue_name != messages[i].queue_name:
raise ValueError('All queues in messages must be equal')
if message.client != messages[i].client:
if message.client_id != messages[i].client_id:
raise ValueError('All clients in messages must be equal')
url = cls._get_url({'queue_name': messages[0].queue})
headers = {'Client-ID': messages[0].client}
url = cls._get_url({'queue_name': messages[0].queue_name})
headers = {'Client-ID': messages[0].client_id}
resp = session.post(url, endpoint_filter=cls.service, headers=headers,
data=json.dumps(messages, cls=MessageEncoder))
@ -96,7 +96,7 @@ class Message(resource.Resource):
def delete_by_id(cls, session, message, path_args=None):
url = cls._strip_version(message.href)
headers = {
'Client-ID': message.client,
'Client-ID': message.client_id,
'Accept': '',
}
session.delete(url, endpoint_filter=cls.service, headers=headers)

View File

@ -40,9 +40,12 @@ class TestClaim(testtools.TestCase):
self.assertFalse(sot.allow_list)
def test_make_it(self):
sot = claim.Claim.new(client=CLIENT, queue=QUEUE, limit=LIMIT, **FAKE)
self.assertEqual(CLIENT, sot.client)
self.assertEqual(QUEUE, sot.queue)
sot = claim.Claim.new(client_id=CLIENT,
queue_name=QUEUE,
limit=LIMIT,
**FAKE)
self.assertEqual(CLIENT, sot.client_id)
self.assertEqual(QUEUE, sot.queue_name)
self.assertEqual(LIMIT, sot.limit)
self.assertEqual(FAKE['ttl'], sot.ttl)
self.assertEqual(FAKE['grace'], sot.grace)
@ -55,7 +58,7 @@ class TestClaim(testtools.TestCase):
sess.post = mock.Mock(return_value=obj)
sot = claim.Claim()
c = claim.Claim.new(client=CLIENT, queue=QUEUE, **FAKE)
c = claim.Claim.new(client_id=CLIENT, queue_name=QUEUE, **FAKE)
list(sot.claim_messages(sess, c))
url = '/queues/%s/claims' % QUEUE
@ -73,7 +76,7 @@ class TestClaim(testtools.TestCase):
sot = claim.Claim()
messages = list(sot.claim_messages(
sess, claim.Claim.new(client=CLIENT, queue=QUEUE, **FAKE)))
sess, claim.Claim.new(client_id=CLIENT, queue_name=QUEUE, **FAKE)))
self.assertEqual(0, len(messages))
@ -87,6 +90,8 @@ class TestClaim(testtools.TestCase):
try:
list(sot.claim_messages(
sess, claim.Claim.new(client=CLIENT, queue=QUEUE, **FAKE)))
sess, claim.Claim.new(client_id=CLIENT,
queue_name=QUEUE,
**FAKE)))
except exceptions.InvalidResponse as e:
self.assertEqual(400, e.response.status_code)

View File

@ -55,7 +55,7 @@ class TestMessage(testtools.TestCase):
sess.post = mock.Mock(return_value=obj)
sot = message.Message()
msg = message.Message.new(client=CLIENT, queue=QUEUE, **FAKE)
msg = message.Message.new(client_id=CLIENT, queue_name=QUEUE, **FAKE)
sot.create_messages(sess, [msg])
url = '/queues/%s/messages' % QUEUE
@ -75,7 +75,9 @@ class TestMessage(testtools.TestCase):
sot = message.Message()
sot.delete_by_id(
sess, message.Message.new(client=CLIENT, queue=QUEUE, **FAKE_HREF))
sess, message.Message.new(client_id=CLIENT,
queue_name=QUEUE,
**FAKE_HREF))
url = '/queues/%s/messages/1234' % QUEUE
sess.delete.assert_called_with(