Merge "Check body type when patching subscription"

This commit is contained in:
Jenkins 2017-02-20 14:42:42 +00:00 committed by Gerrit Code Review
commit d27e784cfa
2 changed files with 13 additions and 0 deletions

View File

@ -364,6 +364,15 @@ class TestSubscriptionsMongoDB(base.V2Base):
headers=self.headers)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
def test_patch_invalid_body(self):
resp = self.simulate_patch(self.subscription_path + '/x',
body='[1]',
headers=self.headers)
self.assertEqual(falcon.HTTP_400, self.srmock.status)
resp_doc = jsonutils.loads(resp[0])
self.assertEqual('Subscriptions must be a dict.',
resp_doc['description'])
def test_delete_works(self):
self._create_subscription()
resp = self.simulate_get(self.subscription_path,

View File

@ -521,6 +521,10 @@ class Validator(object):
if not subscription:
raise ValidationFailed(_(u'No subscription to create.'))
if not isinstance(subscription, dict):
msg = _('Subscriptions must be a dict.')
raise ValidationFailed(msg)
subscriber = subscription.get('subscriber', None)
subscriber_type = None