update datasource webhook framework
Add missing argument param in webhook_model Handle the atypical return value from WebhookModel.add_items Change-Id: Ia59d153cdc3b4a5b361c0901c46c50f3407c2133
This commit is contained in:
parent
5c7d690902
commit
20d84d3798
@ -25,10 +25,12 @@ from congress import exception
|
||||
class WebhookModel(base.APIModel):
|
||||
"""Model for handling webhook notifications."""
|
||||
|
||||
def add_item(self, item, id_=None, context=None):
|
||||
def add_item(self, item, params, id_=None, context=None):
|
||||
"""POST webhook notification.
|
||||
|
||||
:param item: The webhook payload
|
||||
:param params: A dict-like object containing parameters
|
||||
from the request query string and body.
|
||||
:param id_: not used in this case; should be None
|
||||
:param context: Key-values providing frame of reference of request
|
||||
"""
|
||||
|
@ -464,19 +464,25 @@ class CollectionHandler(AbstractApiHandler):
|
||||
item = self._parse_json_body(request)
|
||||
context = self._get_context(request)
|
||||
try:
|
||||
id_, item = self.model.add_item(
|
||||
model_return_value = self.model.add_item(
|
||||
item, request.params, id_, context=context)
|
||||
except KeyError as e:
|
||||
LOG.exception("Error occurred")
|
||||
return error_response(httplib.CONFLICT, httplib.CONFLICT,
|
||||
original_msg(e) or 'Element already exists')
|
||||
item['id'] = id_
|
||||
|
||||
return webob.Response(body="%s\n" % json.dumps(item),
|
||||
status=httplib.CREATED,
|
||||
content_type='application/json',
|
||||
location="%s/%s" % (request.path, id_),
|
||||
charset='UTF-8')
|
||||
if model_return_value is None: # webhook request
|
||||
return webob.Response(body={},
|
||||
status=httplib.OK,
|
||||
content_type='application/json',
|
||||
charset='UTF-8')
|
||||
else:
|
||||
id_, item = model_return_value
|
||||
item['id'] = id_
|
||||
return webob.Response(body="%s\n" % json.dumps(item),
|
||||
status=httplib.CREATED,
|
||||
content_type='application/json',
|
||||
location="%s/%s" % (request.path, id_),
|
||||
charset='UTF-8')
|
||||
|
||||
def replace_members(self, request):
|
||||
if not hasattr(self.model, 'replace_items'):
|
||||
|
@ -32,5 +32,5 @@ class TestWebhookModel(base.SqlTestCase):
|
||||
def test_add_item(self):
|
||||
context = {'ds_id': self.data.service_id}
|
||||
payload = {'test_payload': 'test_payload'}
|
||||
self.webhook_model.add_item(item=payload, context=context)
|
||||
self.webhook_model.add_item(payload, {}, context=context)
|
||||
self.assertEqual(self.data.webhook_payload, payload)
|
||||
|
Loading…
Reference in New Issue
Block a user