From 8e7543ed64a6d4bd108011342e7d7ec2597c5c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 29 Jul 2017 14:27:46 +0200 Subject: [PATCH] misc: do not crash on ezt calling undefined webservice (#17787) --- tests/test_wscall.py | 27 +++++++++++++++++++++++++++ wcs/wscalls.py | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_wscall.py b/tests/test_wscall.py index b2bf0ba19..67b19b08f 100644 --- a/tests/test_wscall.py +++ b/tests/test_wscall.py @@ -1,8 +1,10 @@ import json import mock import pytest +from StringIO import StringIO from wcs.qommon.http_request import HTTPRequest +from wcs.qommon.ezt import Template from wcs.wscalls import NamedWsCall from utilities import create_temporary_pub, clean_temporary_pub, http_requests @@ -106,3 +108,28 @@ def test_webservice_post_with_no_payload(pub): wscall.request = {'method': 'POST', 'url': 'http://remote.example.net/json'} wscall.call() assert http_requests.get_last('body') is None + +def test_wscall_ezt(pub): + NamedWsCall.wipe() + + wscall = NamedWsCall() + wscall.name = 'Hello world' + wscall.request = {'url': 'http://remote.example.net/json'} + wscall.store() + assert wscall.slug == 'hello_world' + + pub.substitutions.feed(NamedWsCall) + variables = pub.substitutions.get_context_variables() + + template = Template() + template.parse('

[webservice.hello_world.foo]

') + output = StringIO() + template.generate(output, variables) + assert output.getvalue() == '

bar

' + + # undefined webservice + template = Template() + template.parse('

[webservice.hello.foo]

') + output = StringIO() + template.generate(output, variables) + assert output.getvalue() == '

[webservice.hello.foo]

' diff --git a/wcs/wscalls.py b/wcs/wscalls.py index fa83bfaab..b6cbbab51 100644 --- a/wcs/wscalls.py +++ b/wcs/wscalls.py @@ -196,7 +196,7 @@ class WsCallsSubstitutionProxy(object): def __getattr__(self, attr): try: return NamedWsCall.get(attr).call() - except ValueError: + except (KeyError, ValueError): raise AttributeError()