Merge "Do not catch ConflictError on subscription create"
This commit is contained in:
commit
a566cda540
@ -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)
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user