misc: do not crash on ezt calling undefined webservice (#17787)

This commit is contained in:
Frédéric Péters 2017-07-29 14:27:46 +02:00
parent fcfda2d576
commit 8e7543ed64
2 changed files with 28 additions and 1 deletions

View File

@ -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('<p>[webservice.hello_world.foo]</p>')
output = StringIO()
template.generate(output, variables)
assert output.getvalue() == '<p>bar</p>'
# undefined webservice
template = Template()
template.parse('<p>[webservice.hello.foo]</p>')
output = StringIO()
template.generate(output, variables)
assert output.getvalue() == '<p>[webservice.hello.foo]</p>'

View File

@ -196,7 +196,7 @@ class WsCallsSubstitutionProxy(object):
def __getattr__(self, attr):
try:
return NamedWsCall.get(attr).call()
except ValueError:
except (KeyError, ValueError):
raise AttributeError()