Created
September 1, 2011 13:49
-
-
Save andreafrancia/1186208 to your computer and use it in GitHub Desktop.
Bug: PyWPS does not escape properly ExceptionText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import sys | |
sys.path.append("./pywps-svn") | |
import pywps | |
import pywps.config | |
pywps.config.loadConfiguration('tests/pywps-no-logging.cfg') | |
class TestWps(unittest.TestCase): | |
def test_what_happen_on_process_errors(self): | |
wps = pywps.Pywps(pywps.METHOD_GET) | |
wps.parseRequest(execute_of('proc_name')) | |
response = wps.performRequest( | |
processes=a_failing_process( | |
name='proc_name', | |
exception_message='<<to-be-escaped>>')) | |
exception_text = extract_exception_text(response) | |
self.assertEquals( | |
'Failed to execute WPS process [proc_name]: <<to-be-escaped>>', | |
exception_text) | |
self.assertNotEquals( | |
'Failed to execute WPS process [proc_name]: <<to-be-escaped>>', | |
exception_text) | |
def extract_exception_text(response): | |
import re | |
pattern=re.compile('<ows:ExceptionText>(.*)</ows:ExceptionText>') | |
if pattern.search(response): | |
exception_text = pattern.search(response).group(1) | |
return exception_text | |
else: | |
assert False, "ExceptionText not found in response:\n%s" % response | |
def execute_of(process): | |
return ('service=WPS' | |
'&version=1.0.0' | |
'&request=Execute' | |
'&identifier=%s' % process) | |
from pywps.Process import WPSProcess | |
def a_failing_process(name,exception_message): | |
class Process(WPSProcess): | |
def execute(self): | |
raise RuntimeError(exception_message) | |
return [Process(name)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment