Merge "Do not catch ConflictError on subscription create"

This commit is contained in:
Jenkins 2016-02-24 01:40:08 +00:00 committed by Gerrit Code Review
commit a566cda540
2 changed files with 23 additions and 10 deletions

View File

@ -14,7 +14,6 @@
# limitations under the License.
from zaqarclient.queues.v2 import core
from zaqarclient.transport import errors
class Subscription(object):
@ -45,16 +44,12 @@ class Subscription(object):
'ttl': self.ttl,
'options': self.options
}
try:
subscription = core.subscription_create(trans, req,
self.queue_name,
subscription_data)
if subscription and 'subscription_id' in subscription:
self.id = subscription['subscription_id']
except errors.ConflictError:
# ConflictError means the subscription already exists.
print('The subscriber has been existed already.')
if self.id:
sub = core.subscription_get(trans, req, self.queue_name, self.id)

View File

@ -46,6 +46,19 @@ class QueuesV2SubscriptionUnitTest(base.QueuesTestBase):
self.assertEqual(3600, subscription.ttl)
self.assertEqual('fake_id', subscription.id)
def test_subscription_create_duplicate_throws_conflicterror(self):
subscription_data = {'subscriber': 'http://trigger.me',
'ttl': 3600}
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
create_resp = response.Response(None, None, status_code=409)
send_method.return_value = create_resp
self.assertRaises(errors.ConflictError, self.client.subscription,
'beijing', **subscription_data)
def test_subscription_update(self):
subscription_data = {'subscriber': 'http://trigger.me',
'ttl': 3600}
@ -187,6 +200,11 @@ class QueuesV2SubscriptionFunctionalTest(base.QueuesTestBase):
self.assertEqual('http://trigger.he', self.subscription_2.subscriber)
self.assertEqual(7200, self.subscription_2.ttl)
def test_subscription_create_duplicate_throws_conflicterror(self):
subscription_data_1 = {'subscriber': 'http://trigger.me', 'ttl': 3600}
self.assertRaises(errors.ConflictError, self.client.subscription,
'beijing', **subscription_data_1)
def test_subscription_update(self):
sub = self.client.subscription(self.queue_name, auto_create=False,
**{'id': self.subscription_1.id})