From 082a0fb7ff0f6008f7c72e3b9a2bacf1b931bf6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 22 Jul 2016 10:32:08 +0200 Subject: [PATCH] wscalls: don't crash ezt substitution on errors in webservice call (#12701) --- tests/test_admin_pages.py | 26 ++++++++++++++++++++++++++ tests/utilities.py | 6 +++++- wcs/wscalls.py | 6 ++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py index 31ad348..750a9be 100644 --- a/tests/test_admin_pages.py +++ b/tests/test_admin_pages.py @@ -1353,6 +1353,32 @@ def test_form_overwrite(pub): assert FormDef.get(formdef_id).url_name == 'form-test' assert FormDef.get(formdef_id).table_name == 'xxx' +def test_form_comment_with_error_in_wscall(pub): + create_superuser(pub) + NamedWsCall.wipe() + + wscall = NamedWsCall(name='xxx') + wscall.description = 'description' + wscall.request = { + 'url': 'http://remote.example.net/404', + 'request_signature_key': 'xxx', + 'qs_data': {'a': 'b'}, + 'method': 'POST', + 'post_data': {'c': 'd'}, + } + wscall.store() + + FormDef.wipe() + formdef = FormDef() + formdef.name = 'form title' + formdef.fields = [fields.CommentField(id='1', + label='x [webservice.xxx.foobar] x', type='comment')] + formdef.store() + + app = login(get_app(pub)) + resp = app.get('/backoffice/forms/%s/' % formdef.id) + assert 'x [webservice.xxx.foobar] x' in resp.body + def test_workflows(pub): app = login(get_app(pub)) app.get('/backoffice/workflows/') diff --git a/tests/utilities.py b/tests/utilities.py index b31b952..d4cf76e 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -8,6 +8,7 @@ import psycopg2 import pytest import shutil import threading +import urlparse from wcs import sql @@ -230,6 +231,9 @@ class HttpRequestsMocking(object): 'headers': headers, 'timeout': timeout}) + scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) + base_url = urlparse.urlunparse((scheme, netloc, path, '', '', '')) + status, data, headers = { 'http://remote.example.net/204': (204, None, None), 'http://remote.example.net/400-json': (400, '{"err": 1, "err_desc": ":("}', None), @@ -239,7 +243,7 @@ class HttpRequestsMocking(object): 'http://remote.example.net/json': (200, '{"foo": "bar"}', None), 'http://remote.example.net/xml': (200, '', {'content-type': 'text/xml'}), - }.get(url, (200, '', {})) + }.get(base_url, (200, '', {})) class FakeResponse(object): def __init__(self, status, data, headers): diff --git a/wcs/wscalls.py b/wcs/wscalls.py index 7f5593d..f2e672b 100644 --- a/wcs/wscalls.py +++ b/wcs/wscalls.py @@ -193,10 +193,12 @@ class NamedWsCall(XmlStorableObject): (response, status, data) = call_webservice(**self.request) return json_loads(data) - class WsCallsSubstitutionProxy(object): def __getattr__(self, attr): - return NamedWsCall.get(attr).call() + try: + return NamedWsCall.get(attr).call() + except ValueError: + raise AttributeError() class WsCallRequestWidget(CompositeWidget): -- 2.8.1