misc: do not crash on ezt calling undefined webservice (#17787)
This commit is contained in:
parent
fcfda2d576
commit
8e7543ed64
|
@ -1,8 +1,10 @@
|
||||||
import json
|
import json
|
||||||
import mock
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
from StringIO import StringIO
|
||||||
|
|
||||||
from wcs.qommon.http_request import HTTPRequest
|
from wcs.qommon.http_request import HTTPRequest
|
||||||
|
from wcs.qommon.ezt import Template
|
||||||
from wcs.wscalls import NamedWsCall
|
from wcs.wscalls import NamedWsCall
|
||||||
|
|
||||||
from utilities import create_temporary_pub, clean_temporary_pub, http_requests
|
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.request = {'method': 'POST', 'url': 'http://remote.example.net/json'}
|
||||||
wscall.call()
|
wscall.call()
|
||||||
assert http_requests.get_last('body') is None
|
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>'
|
||||||
|
|
|
@ -196,7 +196,7 @@ class WsCallsSubstitutionProxy(object):
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
try:
|
try:
|
||||||
return NamedWsCall.get(attr).call()
|
return NamedWsCall.get(attr).call()
|
||||||
except ValueError:
|
except (KeyError, ValueError):
|
||||||
raise AttributeError()
|
raise AttributeError()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue