def testParseExecuteComplexInputAsReference(self): """Test if Execute request is parsed, complex data inputs, given as reference""" getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-complexinput-as-reference.xml")) getinputs = getpywps.parseRequest( "service=wps&version=1.0.0&request=execute&identifier=complexprocess&datainputs=[rasterin=%s;vectorin=%s]" % (urllib.quote(self.wfsurl), urllib.quote(self.wcsurl))) # print # "service=wps&version=1.0.0&request=execute&identifier=complexprocess&datainputs=[rasterin=%s;vectorin=%s]" # % (urllib.quote(self.wfsurl), urllib.quote(self.wcsurl)) postinputs = postpywps.parseRequest(executeRequestFile) self.assertEquals(getinputs["request"], "execute") self.assertEquals(postinputs["request"], "execute") self.assertTrue("complexprocess" in getinputs["identifier"]) self.assertTrue("complexprocess" in postinputs["identifier"]) #self.assertEquals(getinputs, postinputs) self.assertEquals(getinputs["datainputs"][0]["value"], postinputs["datainputs"][0]["value"]) self.assertEquals(getinputs["datainputs"][1]["value"], postinputs["datainputs"][1]["value"])
def testParseExecuteLiteralInput(self): """Test if Execute request is parsed, literal data inputs, including '@' in GET """ # NOTE: Unittest changed after SVN: 1146 to check for the parsing of # "@" getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-literalinput.xml")) getinputs = getpywps.parseRequest( "service=wps&version=1.0.0&request=execute&identifier=literalprocess&datainputs=[int=1;string=spam%40foo.com@mimetype=text/plain@xlink:href=http%3A//www.w3.org/TR/xmlschema-2/%23string;float=1.1]" ) postinputs = postpywps.parseRequest(executeRequestFile) self.assertEquals(getinputs["request"], "execute") self.assertTrue("literalprocess" in getinputs["identifier"]) self.assertEquals(postinputs["request"], "execute") self.assertTrue("literalprocess" in postinputs["identifier"]) #self.assertEquals(getinputs, postinputs) self.assertEquals(getinputs["datainputs"][0]["value"], postinputs["datainputs"][0]["value"]) self.assertEquals(getinputs["datainputs"][1]["value"], postinputs["datainputs"][1]["value"]) self.assertEquals(getinputs["datainputs"][2]["value"], postinputs["datainputs"][2]["value"]) self.assertTrue(getinputs["datainputs"][0]["value"], 1) self.assertTrue(getinputs["datainputs"][1]["value"], "spam%40foo.com") self.assertTrue(getinputs["datainputs"][2]["value"], "1.1")
def testParseExecuteNoInput(self): """Test if Execute request is parsed, no input given""" getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) getinputs = getpywps.parseRequest( "service=wps&version=1.0.0&request=execute&identifier=noinputprocess" ) executeRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-noinputs.xml")) postinputs = postpywps.parseRequest(executeRequestFile) self.assertEquals(getinputs["request"], "execute") self.assertTrue("noinputprocess" in getinputs["identifier"], "noinputsprocess not found in %s" % getinputs) self.assertEquals(postinputs["request"], "execute") self.assertTrue("noinputprocess" in postinputs["identifier"], "noinputsprocess not found in %s" % postinputs) self.assertEquals( getinputs, postinputs, "Get and Post inputs are not same:\n%s\n%s" % (getinputs, postinputs))
def testQuoteChar(self): """Text exception with escape chars""" from pywps.Process import WPSProcess import re name = "proc_name" exception_message = "<<to-be-escaped>>" wps = pywps.Pywps(pywps.METHOD_GET) wps.parseRequest( 'service=WPS&version=1.0.0&request=Execute&identifier=%s' % name) class Process(WPSProcess): def __init__(self): WPSProcess.__init__(self, identifier=name, title="Testing process") def execute(self): raise RuntimeError(exception_message) response = wps.performRequest(processes=[Process()]) pattern = re.compile('<ows:ExceptionText>(.*)</ows:ExceptionText>') if pattern.search(response): exception_text = pattern.search(response).group(1) else: assert False, "ExceptionText not found in response:\n%s" % 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 testSOAPExecute(self): """Testing Execute SOAP postpywps.parser.isSoapExecute""" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) executeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request_compress_SOAP.xml")) postpywps.parseRequest(executeSOAPRequestFile) # self.assertTrue(postpywps.parser.isSoapExecute) postpywps.performRequest() soap = Soap.SOAP() response = soap.getResponse( postpywps.response, soapVersion=postpywps.parser.soapVersion, isSoapExecute=postpywps.parser.isSoapExecute, isPromoteStatus=False) xmldom = minidom.parseString(response) self.assertTrue( xmldom.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0) self.assertTrue( xmldom.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) self.assertTrue(xmldom.getElementsByTagName("output2Result") > 1) self.assertTrue(xmldom.getElementsByTagName("output1Result") > 1)
def testWSDLStartChar(self): """Testing the flag removal from I/O (WSDL)""" getpywps = pywps.Pywps(pywps.METHOD_GET) getpywps.parseRequest("WSDL") getpywps.performRequest() wsdlDoc = minidom.parseString(getpywps.response) #getting all schema elements schemaEl = wsdlDoc.getElementsByTagName("schema") #getting all nodes called elements elementEl = [ node.firstChild for node in schemaEl if node.firstChild.localName == "element" ] #filter everython so that elements that contain the flag process are picked flagEl = [ node.firstChild for node in elementEl if "flag" in node.getAttributeNode("name").nodeValue ] #secon element fetch this time elements inside process element2El = [node.getElementsByTagName("element") for node in flagEl] #flatting the list element2El = [item2 for item1 in element2El for item2 in item1] #list of strings names = [ node.getAttributeNode("name").nodeValue for node in element2El ] #check for presence of "-" self.assertTrue(len([name for name in names if "-" in name]) == 0)
def testIsSOAP(self): """Testing SOAP detection, wps.parser.isSoap""" #Test using getCapabilities self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesSOAP11RequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP11.xml")) postpywps.parseRequest(getCapabilitiesSOAP11RequestFile) self.assertTrue(postpywps.parser.isSoap) getCapabilitiesSOAP12RequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP12.xml")) postpywps.parseRequest(getCapabilitiesSOAP12RequestFile) # self.assertTrue(postpywps.parser.isSoap) #NonSOAP content getCapabilitiesRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request.xml")) postpywps.parseRequest(getCapabilitiesRequestFile) # self.assertFalse(postpywps.parser.isSoap)
def testGetCapabilitiesXML(self): """Testing a complete getCapabilities using SOAP1.1, based on WPS XMl content""" #tmp.xml:2: element Envelope: Schemas validity error : #Element '{http://schemas.xmlsoap.org/soap/envelope/}Envelope', attribute #'{http://schemas.xmlsoap.org/soap/envelope/}encodingStyle': The attribute #'{http://schemas.xmlsoap.org/soap/envelope/}encodingStyle' is not allowed. self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesSOAP11RequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP11.xml")) postpywps.parseRequest(getCapabilitiesSOAP11RequestFile) postpywps.performRequest() soap = Soap.SOAP() response = soap.getResponse( postpywps.response, soapVersion=postpywps.parser.soapVersion, isSoapExecute=postpywps.parser.isSoapExecute, isPromoteStatus=False) #Check SOAP content in response postxmldom = minidom.parseString(response) self.assertTrue( postxmldom.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0) self.assertTrue( postxmldom.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0)
def handler(req): inputQuery = None if req.method == "GET": inputQuery = req.args else: inputQuery = req if not inputQuery: err = NoApplicableCode("No query string found.") pywps.response.response(err,req) return apache.OK # set PYWPS_CFG and PYWPS_PROCESSES environment variable, which can not # bee seen from mod_python env_vars = req.subprocess_env.copy() if env_vars.has_key("PYWPS_CFG"): os.environ["PYWPS_CFG"] = env_vars["PYWPS_CFG"] if env_vars.has_key("PYWPS_PROCESSES"): os.environ["PYWPS_PROCESSES"] = env_vars["PYWPS_PROCESSES"] # create the WPS object try: wps = pywps.Pywps(req.method) if wps.parseRequest(inputQuery): pywps.debug(wps.inputs) wps.performRequest() pywps.response.response(wps.response, req, wps.parser.isSoap, self.wps.parser.isSoapExecute,contentType = wps.request.contentType) return apache.OK except WPSException,e: pywps.response.response(e, req) return apache.OK
def testGetCapabilitiesRPC(self): """Testing a complete getCapabilities using SOAP1.1, using RPC""" # SUDS SOAP client https://fedorahosted.org/suds/ self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesRPC = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP11RPC.xml")) postpywps.parseRequest(getCapabilitiesRPC) postpywps.performRequest() xmldoc = minidom.parseString(postpywps.response) # no need to generate soap response, just testing to get the # getCapabilities document self.assertTrue( xmldoc.getElementsByTagNameNS(self.wpsns, "Capabilities") > 0) # using some alternative version number getCapabilitiesRPC.seek(0) doc = minidom.parse(getCapabilitiesRPC) doc.getElementsByTagNameNS(self.owsns, 'Version')[0].firstChild.nodeValue = "3.0.0" try: postpywps.parseRequest(StringIO.StringIO(doc.toxml())) #<Exception exceptionCode="VersionNegotiationFailed"> except Exception as e: self.assertTrue("VersionNegotiationFailed" in e.code)
def testGetCapabilities(self): """Test if GetCapabilities request returns a valid XML document""" #Note:schemaGetCapabilities.assertValid(getCapabilitiesDoc) # will dump the location of the error, schemaGetCapabilities.validate(getCapabilitiesDoc) #will give true or false #Note2:Setting the Process class constructor (Process/__init__.py) without a default processVersion value # def __init__(self, identifier,...,profile=[],version=None,...): # Will make the parser to invalidate the request, this is a ways to test if the parser is working ok #DocumentInvalid: Element '{http://www.opengis.net/wps/1.0.0}Process': The attribute '{http://www.opengis.net/wps/1.0.0}processVersion' is required but missing., line 74 #Note3: complexVector has mimeTypes None (application/x-empty) self._setFromEnv() schemaDocGetCap = etree.XML(urllib.urlopen( self.getCapabilitiesSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaGetCapabilities = etree.XMLSchema(schemaDocGetCap) getpywps = pywps.Pywps(pywps.METHOD_GET) getinputs = getpywps.parseRequest(self.getCapabilitiesRequest) getpywps.performRequest(getinputs) getCapabilitiesGET = etree.XML(getpywps.response, self.parser) #Validate GET response self.assertEquals( schemaGetCapabilities.assertValid(getCapabilitiesGET), None)
def test23GetInputReferenceMimeType(self): """mimeType included in reference input, validated and understood""" # USE urllib.quote_lus #'urllib.quote_plus("http://rsg.pml.ac.uk/wps/testdata/single_point.gml") self._setFromEnv() import urllib import tempfile getpywps = pywps.Pywps(pywps.METHOD_GET) # raise exception if sending wrong mimetype inputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=complexVector&datainputs=[indata=%s@method=POST@mimeType=%s]&responsedocument=[outdata=@asreference=true;outdata2=@asreference=true]" % ( self.simplePolyURL, urllib.quote_plus("image/tiff"))) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertTrue(len(xmldom.getElementsByTagNameNS( self.wpsns, "ExceptionReport")) == 1) # Correct mimetype process goes as normal inputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=complexVector&datainputs=[indata=%s@method=POST@mimeType=%s]&responsedocument=[outdata=@asreference=true;outdata2=@asreference=true]" % ( self.simplePolyURL, urllib.quote_plus("text/xml"))) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertTrue( len(xmldom.getElementsByTagNameNS(self.wpsns, "Reference")) > 0) #<wps:Reference href="http://localhost/wpsoutputs/outdata-163877NiZFb" mimeType="text/xml" /> # no mimetype inputs = getpywps.parseRequest( "service=wps&version=1.0.0&request=execute&identifier=complexVector&datainputs=[indata=%s]&responsedocument=[outdata=@asreference=true;outdata2=@asreference=true]" % self.simplePolyURL) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertTrue( len(xmldom.getElementsByTagNameNS(self.wpsns, "Reference")) > 0)
def testT07ParseExecuteComplexInput(self): """Test if Execute with ComplexInput and Output, given directly with input XML request is executed""" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open(os.path.join( pywpsPath, "tests", "requests", "wps_execute_request-complexinput-direct.xml")) postinputs = postpywps.parseRequest(executeRequestFile) postpywps.performRequest(postinputs) postxmldom = minidom.parseString(postpywps.response) # compare the raster files rasterOrig = open(os.path.join( pywpsPath, "tests", "datainputs", "dem.tiff")) rasterOrigData = rasterOrig.read() outputs = postxmldom.getElementsByTagNameNS(self.wpsns, "ComplexData") rasterWpsData = base64.decodestring(outputs[1].firstChild.nodeValue) self.assertTrue(rasterWpsData, rasterOrigData) if os.name != "java": # compare the vector files gmlDriver = ogr.GetDriverByName("GML") origDs = gmlDriver.Open(os.path.join( pywpsPath, "tests", "datainputs", "lakes.gml")) wpsFile = tempfile.mktemp(prefix="pywps-test") wpsFile = open(wpsFile, "w") wpsFile.write(postinputs["datainputs"][1]["value"]) wpsFile.close() wpsDs = gmlDriver.Open(wpsFile.name) wpslayer = wpsDs.GetLayerByIndex(0) origlayer = origDs.GetLayerByIndex(0) self.assertTrue(wpslayer.GetFeatureCount(), origlayer.GetFeatureCount())
def application(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/xml')] inputQuery = None if environ.get("REQUEST_METHOD", '') == "GET": inputQuery = environ.get("QUERY_STRING") elif "wsgi.input" in environ: inputQuery = environ.get('wsgi.input') response = '' try: if not inputQuery: raise NoApplicableCode("No query string found.") # create the WPS object wps = pywps.Pywps(environ["REQUEST_METHOD"], environ.get("PYWPS_CFG")) if wps.parseRequest(inputQuery): pywps.debug(wps.inputs) wps.performRequest(processes=environ.get("PYWPS_PROCESSES")) response_headers = [('Content-type', wps.request.contentType)] response = wps.response except WPSException, e: response = str(e)
def test15ParseExecuteResponseDocumentPOST(self): """Return a response document that only containts the requested ouputs, from an XML request lineage output will also be checked """ self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open(os.path.join( pywpsPath, "tests", "requests", "wps_execute_request-complexinput-one-output-as-reference.xml")) postinputs = postpywps.parseRequest(executeRequestFile) postpywps.performRequest() # The response linage contains URLs with & that will crash the DOM # parser xmldom = minidom.parseString(postpywps.response.replace("&", "%26")) # 1 OutputDefintions only and that is rasterout outputDefNodes = xmldom.getElementsByTagNameNS( self.wpsns, "OutputDefinitions") self.assertEquals(len(outputDefNodes), 1) identifierNodes = outputDefNodes[ 0].getElementsByTagNameNS(self.owsns, "Identifier") self.assertEquals(identifierNodes[0].firstChild.nodeValue, "rasterout") # 1 ProcessOutput only check that is rasterout processOutNodes = xmldom.getElementsByTagNameNS( self.wpsns, "ProcessOutputs") self.assertEquals(len(processOutNodes), 1) identifierNodes = processOutNodes[ 0].getElementsByTagNameNS(self.owsns, "Identifier") self.assertEquals(identifierNodes[0].firstChild.nodeValue, "rasterout")
def test19AssyncSpawned(self): """Spawned async subprocess""" # NOTE: testT00Assync, just checks the status document. If the spawned # failed the status document will retain in ProcessAccepted self._setFromEnv() import time getpywps = pywps.Pywps(pywps.METHOD_GET) getinputs = getpywps.parseRequest( "service=wps&version=1.0.0&request=Execute&identifier=ultimatequestionprocess&storeExecuteResponse=True&status=True") getpywps.performRequest(getinputs) xmldom = minidom.parseString(getpywps.response) executeNode = xmldom.getElementsByTagNameNS( self.wpsns, "ExecuteResponse") # Checking for ExecuteResponse self.assertTrue(len(executeNode) > 0) # building file path baseFile = os.path.basename( executeNode[0].getAttribute("statusLocation")) outputPath = pywps.config.getConfigValue("server", "outputPath") # sleep for a while..... time.sleep(10) statusdom = minidom.parse(open(os.path.join(outputPath, baseFile))) self.assertTrue(bool(statusdom.getElementsByTagNameNS(self.wpsns, "ProcessStarted")) or bool( statusdom.getElementsByTagNameNS(self.wpsns, "ProcessSucceeded")))
def test13ParseExecuteComplexVectorInputsAsReferenceMapServer(self): """Test if PyWPS can return correct WFS and WCS services for output data reference, if mapserver module is not present the test will fail """ self._setFromEnv() import urllib import tempfile getpywps = pywps.Pywps(pywps.METHOD_GET) # Outputs will be generated accordint to the order in responsedocument inputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=complexprocessows&datainputs=[rasterin=%s;vectorin=%s]&responsedocument=[vectorout=@asreference=true;rasterout=@asreference=true]" % ( urllib.quote(self.wcsurl), urllib.quote(self.wfsurl))) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertFalse(len(xmldom.getElementsByTagNameNS( self.wpsns, "ExceptionReport")), 0) # try to get out the Reference elemengt wfsurl = xmldom.getElementsByTagNameNS(self.wpsns, "Reference")[ 0].getAttribute("href") wcsurl = xmldom.getElementsByTagNameNS(self.wpsns, "Reference")[ 1].getAttribute("href") # test, if there are WFS and WCS request strings self.assertTrue(wfsurl.find("WFS") > -1) self.assertTrue(wcsurl.find("WCS") > -1)
def test14ParseExecuteResponseDocumentGET(self): """Return a response document that only containts the requested ouputs """ self._setFromEnv() import urllib getpywps = pywps.Pywps(pywps.METHOD_GET) # 1 output only vectorout inputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=complexprocess&datainputs=[rasterin=%s;vectorin=%s]&responsedocument=[vectorout=@asreference=true]" % ( urllib.quote(self.wcsurl), urllib.quote(self.wfsurl))) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertEquals( len(xmldom.getElementsByTagNameNS(self.wpsns, "Output")), 1) # check that it is vectorout outputNodes = xmldom.getElementsByTagNameNS(self.wpsns, "Output") identifierNodes = outputNodes[ 0].getElementsByTagNameNS(self.owsns, "Identifier") self.assertEquals(identifierNodes[0].firstChild.nodeValue, "vectorout") # all outputs --> blank responseDocument inputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=complexprocess&datainputs=[rasterin=%s;vectorin=%s]&responsedocument=[]" % ( urllib.quote(self.wcsurl), urllib.quote(self.wfsurl))) getpywps.performRequest() xmldom = minidom.parseString(getpywps.response) self.assertEquals( len(xmldom.getElementsByTagNameNS(self.wpsns, "Output")), 2)
def testParseExecuteComplexInputDirectly(self): """Test if Execute request is parsed, complex data inputs, given as """ postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-complexinput-direct.xml")) postinputs = postpywps.parseRequest(executeRequestFile) self.assertEquals(postinputs["request"], "execute") self.assertTrue("complexprocess" in postinputs["identifier"]) rasterOrig = open( os.path.join(pywpsPath, "tests", "datainputs", "dem.tiff")) rasterOrigData = rasterOrig.read() rasterWpsData = base64.decodestring( postinputs["datainputs"][0]["value"]) self.assertEquals(rasterOrigData, rasterWpsData) gmlDriver = ogr.GetDriverByName("GML") origDs = gmlDriver.Open( os.path.join(pywpsPath, "tests", "datainputs", "lakes.gml")) wpsFile = tempfile.mktemp(prefix="pywps-test") wpsFile = open(wpsFile, "w") wpsFile.write(postinputs["datainputs"][1]["value"]) wpsFile.close() wpsDs = gmlDriver.Open(wpsFile.name) wpslayer = wpsDs.GetLayerByIndex(0) origlayer = origDs.GetLayerByIndex(0) self.assertTrue(wpslayer.GetFeatureCount(), origlayer.GetFeatureCount())
def test09ParseExecuteComplexVectorInputs(self): """Test, if pywps can parse complex vector input values, given as reference, output given directly""" self._setFromEnv() import urllib import tempfile gmlFile = tempfile.mktemp(prefix="pywps-test-wfs") gmlFile = open(gmlFile, "w") gmlFile.write(urllib.urlopen(self.wfsurl).read()) gmlFile.close() mypywps = pywps.Pywps(pywps.METHOD_GET) request = "service=wps&request=execute&version=1.0.0&identifier=complexVector&datainputs=[indata=%s]" % ( urllib.quote(self.wfsurl)) inputs = mypywps.parseRequest(request) mypywps.performRequest() xmldom = minidom.parseString(mypywps.response) self.assertFalse(len(xmldom.getElementsByTagNameNS( self.wpsns, "ExceptionReport")), 0) xmldom2 = minidom.parse(gmlFile.name) # try to separte the GML file from the response document outputgml = None for elem in xmldom.getElementsByTagNameNS(self.wpsns, "ComplexData")[0].childNodes: if elem.nodeName == "FeatureCollection": outputgml = elem break # output GML should be the same, as input GML self.assertTrue(xmldom, outputgml)
def application(environ, start_response): status = '200 OK' response_headers = [('Content-type', 'text/xml')] start_response(status, response_headers) inputQuery = None if "REQUEST_METHOD" in environ and environ["REQUEST_METHOD"] == "GET": inputQuery = environ["QUERY_STRING"] elif "wsgi.input" in environ: inputQuery = environ['wsgi.input'] if not inputQuery: err = NoApplicableCode("No query string found.") return [err.getResponse()] # create the WPS object try: wps = pywps.Pywps(environ) if wps.parseRequest(inputQuery): pywps.debug(wps.inputs) wps.performRequest() return wps.response except WPSException, e: return [e]
def testStatusLocation(self): """Test, status=false, storeexecuteresposne=false, statusLocation file should NOT be empty""" self._setFromEnv() schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) mypywps = pywps.Pywps(pywps.METHOD_GET) inputs = mypywps.parseRequest( "service=wps&request=execute&version=1.0.0&identifier=ultimatequestionprocess&status=false&storeExecuteResponse=true" ) mypywps.performRequest() #First parse executeAssyncGET = etree.XML(mypywps.response, self.parser) self.assertEquals(schemaExecute.assertValid(executeAssyncGET), None) #get path to status document fileName = os.path.basename( executeAssyncGET.xpath( "//*[local-name()='ExecuteResponse']/@statusLocation")[0]) filePath = pywps.config.getConfigValue("server", "outputPath") + "/" + fileName self.assertEquals(True, os.path.exists(filePath)) fileOpen = open(filePath) self.assertEquals(fileOpen.read(), mypywps.response)
def testSOAP12(self): """Test SOAP1.2 returned envelope""" self._setFromEnv() schemaDocSOAP = etree.XML(urllib.urlopen(self.soap12Schema).read(), parser=self.parser, base_url=self.base_url) schemaSOAP = etree.XMLSchema(schemaDocSOAP) postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesSOAP12RequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP12.xml")) postpywps.parseRequest(getCapabilitiesSOAP12RequestFile) postpywps.performRequest() soap = Soap.SOAP() response = soap.getResponse( postpywps.response, soapVersion=postpywps.parser.soapVersion, isSoapExecute=postpywps.parser.isSoapExecute, isPromoteStatus=False) soapDoc = etree.XML(response, self.parser) self.assertEquals(schemaSOAP.assertValid(soapDoc), None)
def testDescribeProcess(self): """Test if DescribeProcess requests returns a valid XML document""" #Note: assyncprocess fails since it has no outputs and outputs #Note2:Processes that miss format list (formats) ex: complexVector will have <MimeType>None></MimeType> #element MimeType: Schemas validity error : Element 'MimeType': [facet 'pattern'] # The value 'None' is not accepted by the pattern '(application|audio|image|text|video|message|multipart|model)/.+(;\s*.+=.+)*' #Note3: processes ok: bboxprocess,complexprocess,literalprocess,complexRaster self._setFromEnv() schemaDocDescribe = etree.XML(urllib.urlopen( self.describeProcessSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaDescribeProcess = etree.XMLSchema(schemaDocDescribe) getpywps = pywps.Pywps(pywps.METHOD_GET) getinputs = getpywps.parseRequest(self.getDescribeProcessRequest) getpywps.performRequest(getinputs) describeProcessGET = etree.XML(getpywps.response, self.parser) self.assertEquals( schemaDescribeProcess.assertValid(describeProcessGET), None)
def index(): #start_response(status, response_headers) response_headers = [('Content-type', 'text/xml')] inputQuery = None if request.method == 'GET': inputQuery = str(request.args) print inputQuery elif request.method == 'POST': #inputQuery = environ['wsgi.input'] inputQuery = request.args if not request.args: print pywps.Exceptions err = pywps.Exceptions.NoApplicableCode("No query string found.") resp = make_response(err, 200) resp.headers['mime-type'] = 'text/xml' resp.headers['content-type'] = 'text/xml' return [err.getResponse()] # create the WPS object try: #resp = make_response(err, 200) #resp.headers['mime-type'] = 'text/xml' #resp.headers['content-type'] = 'text/xml' wps = pywps.Pywps(request.method) #if wps.parseRequest(inputQuery): pywps.debug(inputQuery) wps.performRequest() return wps.response except WPSException, e: return [e]
def testParseBBoxInput(self): """Parsing Bounding Box Input""" getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-bbox.xml")) getinputs = getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=bboxprocess&datainputs=[bboxin=%s]" %\ ("-11,-12,13,14")) postinputs = postpywps.parseRequest(executeRequestFile) self.assertTrue("bboxprocess" in getinputs["identifier"]) self.assertTrue("bboxprocess" in postinputs["identifier"]) self.assertEquals(getinputs["datainputs"][0]["value"], "-11,-12,13,14") self.assertEquals(postinputs["datainputs"][0]["value"], [-11, -12, 13, 14])
def testsT12ExecuteBBox(self): """Parsing Bounding Box Input""" getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open(os.path.join( pywpsPath, "tests", "requests", "wps_execute_request-bbox.xml")) getpywps.parseRequest("service=wps&version=1.0.0&request=execute&identifier=bboxprocess&datainputs=[bboxin=%s]" % ("-11,-12,13,14")) postpywps.parseRequest(executeRequestFile) postpywps.performRequest() getpywps.performRequest() postinput = postpywps.request.process.getInput("bboxin") getinput = getpywps.request.process.getInput("bboxin") self.assertEquals(getinput.getValue().coords, postinput.getValue().coords)
def testT11ParseExecuteComplexVectorAndRasterInputsAsReferenceOutpu(self): """Test, if pywps can store complex values as reference""" postpywps = pywps.Pywps(pywps.METHOD_POST) executeRequestFile = open(os.path.join( pywpsPath, "tests", "requests", "wps_execute_request-complexinput-output-as-reference.xml")) postinputs = postpywps.parseRequest(executeRequestFile) postpywps.performRequest()
def testT01PerformGetCapabilities(self): """Test if GetCapabilities request returns Capabilities document""" self._setFromEnv() getpywps = pywps.Pywps(pywps.METHOD_GET) postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesRequestFile = open(os.path.join( pywpsPath, "tests", "requests", "wps_getcapabilities_request.xml")) postinputs = postpywps.parseRequest(getCapabilitiesRequestFile) postpywps.performRequest(postinputs) xmldom = minidom.parseString(postpywps.response) self.assertEquals(xmldom.firstChild.nodeName, "wps:Capabilities") inputs = getpywps.parseRequest(self.getcapabilitiesrequest) getpywps.performRequest(inputs) xmldom = minidom.parseString(getpywps.response) self.assertEquals(xmldom.firstChild.nodeName, "wps:Capabilities")
def testDescribeProcessPOST(self): """DescribeProcess all POST""" postpywps = pywps.Pywps(pywps.METHOD_POST) getCapabilitiesRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_request_all.xml")) postinputs = postpywps.parseRequest(getCapabilitiesRequestFile) postpywps.performRequest(postinputs)