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 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 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 isSoapFirstChild(self, document): """Return first child of the document, if it is SOAP request, return first child of the body envelope """ # SOAP ?? firstChild = self.getFirstChildNode(document) if Soap.isSoap(firstChild): self.isSoap = True soapCls = Soap.SOAP(firstChild) self.soapVersion = soapCls.getSOAPVersion() firstChild = soapCls.getWPSContent() self.isSoapExecute = soapCls.getSoapExecute() return firstChild
def response(response, targets, soapVersion=None, isSoap=False, isSoapExecute=False, contentType="application/xml", isPromoteStatus=False): """ Print response to files given as input parameter. :param targets: file object or list of file objects. File name, mod_python request or java servlet response :type targets: string or list, :param isSoap: print the response in SOAP envelope :type isSoap: bool :param response: the response object :type response: file or string """ # convert single file to array if type(targets) != type([]): targets = [targets] if isSoap: soap = Soap.SOAP() response = soap.getResponse(response, soapVersion, isSoapExecute, isPromoteStatus) if isinstance(response, Exceptions.WPSException): response = response.__str__() # for each file in file descriptor for f in targets: # consider, if this CGI, mod_python or Java requested output # mod_python here if repr(type(f)) == "<type 'mp_request'>": _printResponseModPython(f, response, contentType) # file object (output, or sys.stdout) elif types.FileType == type(f): _printResponseFile(f, response, contentType) # pywps.Ftp.FTP object elif isinstance(f, pywps.Ftp.FTP): _sendResponseFTP(f, response) logging.debug("Response document successfuly send to ftp server") # java servlet response elif OSNAME == "java": _printResponseJava(f, response, contentType) # close and open again, if it is a file if type(response) == types.FileType: response.close() response = open(response.name, "rb")
def isSoapFirstChild(self,document): """Return first child of the document, if it is SOAP request, return first child of the body envelope """ # SOAP ?? firstChild = self.getFirstChildNode(document) if Soap.isSoap(firstChild): soapCls = Soap.SOAP(firstChild) firstChild = soapCls.getNode(Soap.soap_env_NS[soapCls.nsIndex],"Body") firstChild = self.getFirstChildNode(firstChild) self.isSoap = True return firstChild
def testAsyncProcess(self): """Testing SOAP env in asycn req with normal document""" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) pid = os.getpid() executeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request_ultimatequestion_SOAP.xml")) postpywps.parseRequest(executeSOAPRequestFile) postpywps.performRequest() if (os.getpid() != pid): os._exit(0) 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) #Get status content executeEl = postxmldom.getElementsByTagNameNS( "http://www.opengis.net/wps/1.0.0", "ExecuteResponse") fileName = os.path.basename( executeEl[0].getAttribute("statusLocation")) filePath = pywps.config.getConfigValue("server", "outputPath") + "/" + fileName #check that the status file also has a SOAP envelope time.sleep(2) statusDoc = minidom.parse(filePath) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0 ) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0)
def isSoapFirstChild(self,document): """Return first child of the document, if it is SOAP request, return first child of the body envelope """ # SOAP ?? firstChild = self.getFirstChildNode(document) if Soap.isSoap(firstChild): self.isSoap = True soapCls = Soap.SOAP(firstChild) self.soapVersion=soapCls.getSOAPVersion() firstChild=soapCls.getWPSContent() self.isSoapExecute=soapCls.getSoapExecute() return firstChild
class SchemaTestCase(unittest.TestCase): #The class takes some time to load since it's in here where the schema objects are created and the schema's URL contacted getCapabilitiesRequest = "service=wps&request=getcapabilities" getDescribeProcessRequest = "service=wps&request=describeprocess&version=1.0.0&identifier=bboxprocess,complexprocess,literalprocess,complexRaster,complexVector,ogrbuffer" postExecuteBBOXRequest = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-bbox.xml")) #1 raster + 1 vector output No def of response doc postExecuteComplexInputRequest = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-complexinput-direct.xml")) postExecuteComplexInputOneOutputRequest = open( os.path.join( pywpsPath, "tests", "requests", "wps_execute_request-complexinput-one-output-as-reference.xml")) postExecuteLiteraDataRequest = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request-literalinput-responsedocument.xml")) base_url = "http://schemas.opengis.net/wps/1.0.0/" getCapabilitiesSchemaResponse = "http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd" describeProcessSchemaResponse = "http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd" executeSchemaResponse = "http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd" wsdlSchema = "http://schemas.xmlsoap.org/wsdl/" soap11Schema = "http://schemas.xmlsoap.org/soap/envelope/" soap12Schema = "http://www.w3.org/2003/05/soap-envelope/" parser = etree.XMLParser(no_network=False) def setUp(self): #Silence PyWPS Warning: Usage of.... sys.stderr = open("/dev/null", "w") 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 testAssync(self): """Test assync status document""" self._setFromEnv() pid = os.getpid() 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=true&storeExecuteResponse=true" ) mypywps.performRequest() #Killing the child from os.fork in pywps if (os.getpid() != pid): os._exit(0) #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 time.sleep(2) executeAssyncStatus = etree.parse(open(filePath, "r"), parser=self.parser) self.assertEquals(schemaExecute.assertValid(executeAssyncStatus), None) #Looping waiting for ProcessSucceeded #will loop max 20 times and wait 5 sec #if the assync is taking to long it mught be a problem counter = 0 while counter < 20: executeAssyncStatus = etree.parse(open(filePath, "r"), parser=self.parser) processStatus = executeAssyncStatus.xpath( "//*[local-name()='ProcessAccepted' or local-name()='ProcessStarted' or local-name()='ProcessPaused']" ) self.assertEquals(schemaExecute.assertValid(executeAssyncStatus), None) if len(processStatus) > 0: counter = counter + 1 time.sleep(5) else: break if counter >= 20: self.assertEquals("The assync process is taking to long", None) 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) #POST request should be the same, since the response is generated from the same inputs # But you never know.... #postpywps = pywps.Pywps(pywps.METHOD_POST) #postinputs = postpywps.parseRequest(self.getCapabilitiesRequestFile) #postpywps.performRequest(postinputs) #getCapabilitiesPOST=etree.XML(postpywps.response,self.parser) #self.assertEquals(schemaGetCapabilities.assertValid(getCapabilitiesPOST),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 testExecuteBBOXProcess(self): """Test execute with bbox""" self._setFromEnv() schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) postpywps = pywps.Pywps(pywps.METHOD_POST) postinputs = postpywps.parseRequest(self.postExecuteBBOXRequest) self.postExecuteBBOXRequest.seek(0) postpywps.performRequest(postinputs) executeBBOXPOST = etree.XML(postpywps.response, self.parser) self.assertEquals(schemaExecute.assertValid(executeBBOXPOST), None) def testExecuteComplexInputDirect(self): """Test standard Execute direct output of raster and vector""" #wps_execute_request-complexinput-direct.xml self._setFromEnv() schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) postpywps = pywps.Pywps(pywps.METHOD_POST) postinputs = postpywps.parseRequest( self.postExecuteComplexInputRequest) self.postExecuteComplexInputRequest.seek(0) postpywps.performRequest(postinputs) executeComplexInputPOST = etree.XML(postpywps.response, self.parser) self.assertEquals(schemaExecute.assertValid(executeComplexInputPOST), None) def testExecuteComplexInputOutputDirect(self): """Testing raster and vector I/O""" self._setFromEnv() #Testing simple request with 2 complexdata, one raster another vector schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) postpywps = pywps.Pywps(pywps.METHOD_POST) postinputs = postpywps.parseRequest( self.postExecuteComplexInputRequest) self.postExecuteComplexInputRequest.seek(0) #postinputs = postpywps.parseRequest(self.postExecuteComplexInputOneOutputRequest) postpywps.performRequest(postinputs) executeComplexInputOneOutputPOST = etree.XML(postpywps.response, self.parser) self.assertEquals( schemaExecute.assertValid(executeComplexInputOneOutputPOST), None) def testExecuteComplexInputOneOutputReference(self): """Test lineage and output as reference""" self._setFromEnv() schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) postpywps = pywps.Pywps(pywps.METHOD_POST) postinputs = postpywps.parseRequest( self.postExecuteComplexInputOneOutputRequest) self.postExecuteComplexInputOneOutputRequest.seek(0) postpywps.performRequest(postinputs) executeComplexInputOneOutputPOST = etree.XML(postpywps.response, self.parser) self.assertEquals( schemaExecute.assertValid(executeComplexInputOneOutputPOST), None) def testExecuteLiteraData(self): """Test literaldata lineage and response document""" #Literal data doesnt support reference output, yet self._setFromEnv() schemaDocExecute = etree.XML(urllib.urlopen( self.executeSchemaResponse).read(), parser=self.parser, base_url=self.base_url) schemaExecute = etree.XMLSchema(schemaDocExecute) postpywps = pywps.Pywps(pywps.METHOD_POST) postinputs = postpywps.parseRequest(self.postExecuteLiteraDataRequest) self.postExecuteLiteraDataRequest.seek(0) postpywps.performRequest(postinputs) executeComplexInputOneOutputPOST = etree.XML(postpywps.response, self.parser) self.assertEquals( schemaExecute.assertValid(executeComplexInputOneOutputPOST), None) def testWSDL(self): """Test WSDL output content""" self._setFromEnv() schemaDocWSDL = etree.XML(urllib.urlopen(self.wsdlSchema).read(), parser=self.parser, base_url=self.base_url) schemaWSDL = etree.XMLSchema(schemaDocWSDL) getpywps = pywps.Pywps(pywps.METHOD_GET) inputs = getpywps.parseRequest("WSDL") #print inputs getpywps.performRequest() wsdlDoc = etree.XML(getpywps.response, self.parser) self.assertEquals(schemaWSDL.assertValid(wsdlDoc), None) def testSOAP11(self): """Test SOAP1.1 returned envelope""" #Same as testGetCapabilities is soap_tests self._setFromEnv() schemaDocSOAP = etree.XML(urllib.urlopen(self.soap11Schema).read(), parser=self.parser, base_url=self.base_url) schemaSOAP = etree.XMLSchema(schemaDocSOAP) 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) soapDoc = etree.XML(response, self.parser) self.assertEquals(schemaSOAP.assertValid(soapDoc), None) 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 testSOAP11Fault(self): """Test Fault SOAP1.1""" schemaDocSOAP = etree.XML(urllib.urlopen(self.soap11Schema).read(), parser=self.parser, base_url=self.base_url) schemaSOAP = etree.XMLSchema(schemaDocSOAP) postpywps = pywps.Pywps(pywps.METHOD_POST) exceptionFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_exception_SOAP11.xml")) postpywps.parseRequest(exceptionFile) try: postpywps.performRequest() except pywps.Exceptions.InvalidParameterValue, e: postpywps.response = e.getResponse() 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)
class SOAPSchemaTestCase(unittest.TestCase): #For soap 1.2 -->http://www.w3.org/2003/05/soap-envelope (self.nsIndex=0) #For soap 1.1 -->http://schemas.xmlsoap.org/soap/envelope/ (self.nsIndex=1) soapEnvNS = [ "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/" ] soapEncNS = [ "http://www.w3.org/2003/05/soap-encoding", "http://schemas.xmlsoap.org/soap/encoding/" ] wpsns = "http://www.opengis.net/wps/1.0.0" owsns = "http://www.opengis.net/ows/1.1" def setUp(self): sys.stderr = open("/dev/null", "w") 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 testSOAPVersion(self): """Testing correct wps.parser.soapVersion""" 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.assertEqual(int(postpywps.parser.soapVersion), int(11)) getCapabilitiesSOAP11RequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request_SOAP12.xml")) postpywps.parseRequest(getCapabilitiesSOAP11RequestFile) self.assertEqual(int(postpywps.parser.soapVersion), int(12)) #Non soap getCapabilitiesRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_getcapabilities_request.xml")) postpywps.parseRequest(getCapabilitiesRequestFile) # self.assertTrue(type(postpywps.parser.soapVersion) is types.NoneType) 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 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 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 testDescribeProcessRPC(self): """Testing a complete describeProcess using SOAP1.1, using RPC""" #Note in RPC DescribeProcess is as follows #DescribeProcess(ns0:CodeType[] Identifier, ) #This CodeType is not the best defintion #<ns1:Body><ns0:DescribeProcess><ns0:Identifier xsi:type="ns2:CodeType">ultimatequestionprocess</ns0:Identifier></ns0:DescribeProcess></ns1:Body> self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) describeProcessRPC = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_request_SOAP11RPC.xml")) postpywps.parseRequest(describeProcessRPC) postpywps.performRequest() xmldoc = minidom.parseString(postpywps.response) self.assertTrue( xmldoc.getElementsByTagNameNS(self.wpsns, "ProcessDescriptions") > 0) def testDescribeProcessXML(self): """Testing a complete describeProcess using SOAP1.1 based on WPS XML content""" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) describeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_request_all_SOAP.xml")) postpywps.parseRequest(describeSOAPRequestFile) postpywps.performRequest() xmldoc = minidom.parseString(postpywps.response) self.assertTrue( xmldoc.getElementsByTagNameNS(self.wpsns, "ProcessDescriptions") > 0) def testAsyncProcess(self): """Testing SOAP env in asycn req with normal document""" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) pid = os.getpid() executeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request_ultimatequestion_SOAP.xml")) postpywps.parseRequest(executeSOAPRequestFile) postpywps.performRequest() if (os.getpid() != pid): os._exit(0) 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) #Get status content executeEl = postxmldom.getElementsByTagNameNS( "http://www.opengis.net/wps/1.0.0", "ExecuteResponse") fileName = os.path.basename( executeEl[0].getAttribute("statusLocation")) filePath = pywps.config.getConfigValue("server", "outputPath") + "/" + fileName #check that the status file also has a SOAP envelope time.sleep(2) statusDoc = minidom.parse(filePath) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0 ) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) def testAsyncCompressExecute(self): """Testing async req from compressed SOAP""" #os.fork make the unittest fork, being called again when the process finishes #in the first run the unittest will get the statusURLResult, in the second run it will parse the #response content with answerResult self._setFromEnv() pid = os.getpid() postpywps = pywps.Pywps(pywps.METHOD_POST) executeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request_ultimate_compress_SOAP.xml")) postpywps.parseRequest(executeSOAPRequestFile) 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 responseDoc = minidom.parseString(response) #GetStatus from <statusURLResult> time.sleep(2) #Killing the child from os.fork in pywps if (os.getpid() != pid): os._exit(0) self.assertTrue( responseDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0) self.assertTrue( responseDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) statusEl = responseDoc.getElementsByTagName("statusURLResult") #Check that the statusURLResult is present (compressed soap) self.assertTrue(len(statusEl) > 0) fileName = os.path.basename(statusEl[0].firstChild.toxml()) filePath = pywps.config.getConfigValue("server", "outputPath") + "/" + fileName #check that the new status file also has a SOAP envelope statusDoc = minidom.parse(filePath) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0 ) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) self.assertTrue( statusDoc.getElementsByTagNameNS(self.wpsns, "ExecuteResponse") > 0 ) #loop until we have a result counter = 0 while counter < 20: statusDoc = minidom.parse(filePath) executeEl = statusDoc.getElementsByTagNameNS( self.wpsns, "ExecuteResponse") if len(executeEl) > 0: counter = counter + 1 time.sleep(5) else: break if counter >= 20: self.fail( "The assync process it taking to long, something is wrong") #result should be in compressed SOAP resultDoc = minidom.parse(filePath) self.assertTrue( len(resultDoc.getElementsByTagName("answerResult")) > 0) self.assertEqual( int( resultDoc.getElementsByTagName("answerResult") [0].firstChild.nodeValue), 42) print resultDoc.getElementsByTagName( "answerResult")[0].firstChild.nodeValue def testWSDLGenerator(self): """Testing WSDL generation""" #Major testing in the ultimatequestion process self._setFromEnv() getpywps = pywps.Pywps(pywps.METHOD_GET) inputs = getpywps.parseRequest("WSDL") #print inputs getpywps.performRequest() #print pywps.config.getConfigValue("wps","serveraddress") wsdlDoc = minidom.parseString(getpywps.response) #checking content addressNode = wsdlDoc.getElementsByTagName("address")[0] #check 4 correct server adress self.assertTrue( addressNode.getAttribute("location") == pywps.config.getConfigValue("wps", "serveraddress")) #check for Response/Request in input/output message port = wsdlDoc.getElementsByTagName("portType") inputs = port[0].getElementsByTagName("input") outputs = port[0].getElementsByTagName("output") self.assertTrue("Request" in inputs[0].getAttribute("message")) self.assertTrue("Response" in outputs[0].getAttribute("message")) #check for async+sync creation operation = port[0].getElementsByTagName("operation") self.assertTrue("ExecuteProcessAsync_ultimatequestionprocess" in [item.getAttribute("name") for item in operation]) self.assertTrue("ExecuteProcess_ultimatequestionprocess" in [item.getAttribute("name") for item in operation]) self.assertTrue("ExecuteProcessAsync_literalprocess" in [item.getAttribute("name") for item in operation]) #probably more WSDL content tests are necessary def testSOAP11Fault(self): "Testing WPS exception to SOAP11 fault" #here a silent stderr does not work, the exception is raised and a try will catch it self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) exceptionFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_exception_SOAP11.xml")) postpywps.parseRequest(exceptionFile) try: postpywps.performRequest() except pywps.Exceptions.InvalidParameterValue, e: postpywps.response = e.getResponse() soap = Soap.SOAP() response = soap.getResponse( postpywps.response, soapVersion=postpywps.parser.soapVersion, isSoapExecute=postpywps.parser.isSoapExecute, isPromoteStatus=False) xmlDoc = minidom.parseString(response) #xmlDoc.getElementsByTagNameNS(self.soapEnvNS[1],"Fault") self.assertTrue( len(xmlDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Fault")) > 0) #check for SOAP-ENV:Server as fault code as in WCS2.0 self.assertTrue(len(xmlDoc.getElementsByTagName("faultcode")) > 0) exceptionDoc = xmlDoc.getElementsByTagName("detail")[0] self.assertTrue( len( exceptionDoc.getElementsByTagNameNS(self.owsns, "ExceptionReport")) > 0)
def testAsyncCompressExecute(self): """Testing async req from compressed SOAP""" #os.fork make the unittest fork, being called again when the process finishes #in the first run the unittest will get the statusURLResult, in the second run it will parse the #response content with answerResult self._setFromEnv() pid = os.getpid() postpywps = pywps.Pywps(pywps.METHOD_POST) executeSOAPRequestFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_execute_request_ultimate_compress_SOAP.xml")) postpywps.parseRequest(executeSOAPRequestFile) 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 responseDoc = minidom.parseString(response) #GetStatus from <statusURLResult> time.sleep(2) #Killing the child from os.fork in pywps if (os.getpid() != pid): os._exit(0) self.assertTrue( responseDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0) self.assertTrue( responseDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) statusEl = responseDoc.getElementsByTagName("statusURLResult") #Check that the statusURLResult is present (compressed soap) self.assertTrue(len(statusEl) > 0) fileName = os.path.basename(statusEl[0].firstChild.toxml()) filePath = pywps.config.getConfigValue("server", "outputPath") + "/" + fileName #check that the new status file also has a SOAP envelope statusDoc = minidom.parse(filePath) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Envelope") > 0 ) self.assertTrue( statusDoc.getElementsByTagNameNS(self.soapEnvNS[1], "Body") > 0) self.assertTrue( statusDoc.getElementsByTagNameNS(self.wpsns, "ExecuteResponse") > 0 ) #loop until we have a result counter = 0 while counter < 20: statusDoc = minidom.parse(filePath) executeEl = statusDoc.getElementsByTagNameNS( self.wpsns, "ExecuteResponse") if len(executeEl) > 0: counter = counter + 1 time.sleep(5) else: break if counter >= 20: self.fail( "The assync process it taking to long, something is wrong") #result should be in compressed SOAP resultDoc = minidom.parse(filePath) self.assertTrue( len(resultDoc.getElementsByTagName("answerResult")) > 0) self.assertEqual( int( resultDoc.getElementsByTagName("answerResult") [0].firstChild.nodeValue), 42) print resultDoc.getElementsByTagName( "answerResult")[0].firstChild.nodeValue
def testSOAP12Fault(self): "Testing WPS exception to SOAP12 fault" self._setFromEnv() postpywps = pywps.Pywps(pywps.METHOD_POST) exceptionFile = open( os.path.join(pywpsPath, "tests", "requests", "wps_describeprocess_exception_SOAP12.xml")) postpywps.parseRequest(exceptionFile) try: postpywps.performRequest() except pywps.Exceptions.InvalidParameterValue, e: postpywps.response = e.getResponse() soap = Soap.SOAP() response = soap.getResponse( postpywps.response, soapVersion=postpywps.parser.soapVersion, isSoapExecute=postpywps.parser.isSoapExecute, isPromoteStatus=False) xmlDoc = minidom.parseString(response) self.assertTrue( len(xmlDoc.getElementsByTagNameNS(self.soapEnvNS[0], "Fault")) > 0) #check for SOAP-ENV:Server as fault code as in WCS2.0 self.assertTrue( len(xmlDoc.getElementsByTagNameNS(self.soapEnvNS[0], "Value")) > 0) exceptionDoc = xmlDoc.getElementsByTagNameNS(self.soapEnvNS[0], "Detail")[0] self.assertTrue(