def describe_xml(self): input_elements = [i.describe_xml() for i in self.inputs] output_elements = [i.describe_xml() for i in self.outputs] doc = E.ProcessDescription(OWS.Identifier(self.identifier), OWS.Title(self.title)) doc.attrib[ '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.version if self.store_supported == 'true': doc.attrib['storeSupported'] = self.store_supported if self.status_supported == 'true': doc.attrib['statusSupported'] = self.status_supported if self.abstract: doc.append(OWS.Abstract(self.abstract)) for m in self.metadata: doc.append(OWS.Metadata({'{http://www.w3.org/1999/xlink}title': m})) for p in self.profile: doc.append(WPS.Profile(p)) if self.wsdl: doc.append( WPS.WSDL({'{http://www.w3.org/1999/xlink}href': self.wsdl})) if input_elements: doc.append(E.DataInputs(*input_elements)) doc.append(E.ProcessOutputs(*output_elements)) return doc
def _execute_xml_data(self): """Return Data node """ doc = WPS.Data() if self.data is None: complex_doc = WPS.ComplexData() else: complex_doc = WPS.ComplexData() try: data_doc = etree.parse(self.file) complex_doc.append(data_doc.getroot()) except Exception: if isinstance(self.data, six.string_types): complex_doc.text = self.data else: complex_doc.text = etree.CDATA(self.base64) if self.data_format: if self.data_format.mime_type: complex_doc.attrib['mimeType'] = self.data_format.mime_type if self.data_format.encoding: complex_doc.attrib['encoding'] = self.data_format.encoding if self.data_format.schema: complex_doc.attrib['schema'] = self.data_format.schema doc.append(complex_doc) return doc
def test_bbox(self): if not PY2: self.skipTest('OWSlib not python 3 compatible') client = client_for(Service(processes=[create_bbox_process()])) request_doc = WPS.Execute(OWS.Identifier('my_bbox_process'), WPS.DataInputs( WPS.Input( OWS.Identifier('mybbox'), WPS.Data( WPS.BoundingBoxData( OWS.LowerCorner('15 50'), OWS.UpperCorner('16 51'), )))), version='1.0.0') resp = client.post_xml(doc=request_doc) assert_response_success(resp) [output ] = xpath_ns(resp.xml, '/wps:ExecuteResponse' '/wps:ProcessOutputs/Output') self.assertEqual('outbbox', xpath_ns(output, './ows:Identifier')[0].text) self.assertEqual( '15 50', xpath_ns(output, './ows:BoundingBox/ows:LowerCorner')[0].text)
def execute_xml(self): doc = WPS.Output( OWS.Identifier(self.identifier), OWS.Title(self.title) ) if self.abstract: doc.append(OWS.Abstract(self.abstract)) if self.keywords: kws = map(OWS.Keyword, self.keywords) doc.append(OWS.Keywords(*kws)) data_doc = WPS.Data() bbox_data_doc = OWS.BoundingBox() bbox_data_doc.attrib['crs'] = self.crs bbox_data_doc.attrib['dimensions'] = str(self.dimensions) bbox_data_doc.append(OWS.LowerCorner('{0[0]} {0[1]}'.format(self.data))) bbox_data_doc.append(OWS.UpperCorner('{0[2]} {0[3]}'.format(self.data))) data_doc.append(bbox_data_doc) doc.append(data_doc) return doc
def _process_failed(self): return WPS.Status(WPS.ProcessFailed( WPS.ExceptionReport( OWS.Exception(OWS.ExceptionText(self.message), exceptionCode='NoApplicableCode', locater='None'))), creationTime=time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime()))
def _process_paused(self): return WPS.Status( WPS.ProcessPaused( self.message, percentCompleted=str(self.status_percentage) ), creationTime=time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime()) )
def test_assync(self): client = client_for(Service(processes=[create_sleep()])) request_doc = WPS.Execute(OWS.Identifier('sleep'), WPS.DataInputs( WPS.Input( OWS.Identifier('seconds'), WPS.Data(WPS.LiteralData("120")))), version="1.0.0") resp = client.post_xml(doc=request_doc) assert_response_accepted(resp)
def test_post_with_string_input(self): client = client_for(Service(processes=[create_greeter()])) request_doc = WPS.Execute(OWS.Identifier('greeter'), WPS.DataInputs( WPS.Input( OWS.Identifier('name'), WPS.Data(WPS.LiteralData('foo')))), version='1.0.0') resp = client.post_xml(doc=request_doc) assert_response_success(resp) assert get_output(resp.xml) == {'message': "Hello foo!"}
def _execute_xml_data(self): """Return Data node """ doc = WPS.Data() literal_doc = WPS.LiteralData(str(self.data)) if self.data_type: literal_doc.attrib['dataType'] = self.data_type if self.uom: literal_doc.attrib['uom'] = self.uom doc.append(literal_doc) return doc
def test_complex_input_raw_value(self): the_data = '{ "plot":{ "Version" : "0.1" } }' request_doc = WPS.Execute( OWS.Identifier('foo'), WPS.DataInputs( WPS.Input( OWS.Identifier('json'), WPS.Data( WPS.ComplexData(the_data, mimeType='application/json'))))) rv = get_inputs_from_xml(request_doc) self.assertEqual(rv['json'][0]['mimeType'], 'application/json') json_data = json.loads(rv['json'][0]['data']) self.assertEqual(json_data['plot']['Version'], '0.1')
def test_complex_input(self): the_data = E.TheData("hello world") request_doc = WPS.Execute( OWS.Identifier('foo'), WPS.DataInputs( WPS.Input( OWS.Identifier('name'), WPS.Data(WPS.ComplexData(the_data, mimeType='text/foobar'))))) rv = get_inputs_from_xml(request_doc) self.assertEqual(rv['name'][0]['mimeType'], 'text/foobar') rv_doc = lxml.etree.parse(StringIO(rv['name'][0]['data'])).getroot() self.assertEqual(rv_doc.tag, 'TheData') self.assertEqual(rv_doc.text, 'hello world')
def _execute_xml_data(self): """Return Data node """ doc = WPS.Data() complex_doc = WPS.ComplexData(self.data) if self.data_format: if self.data_format.mime_type: complex_doc.attrib['mimeType'] = self.data_format.mime_type if self.data_format.encoding: complex_doc.attrib['encoding'] = self.data_format.encoding if self.data_format.schema: complex_doc.attrib['schema'] = self.data_format.schema doc.append(complex_doc) return doc
def test_reference_post_input(self): request_doc = WPS.Execute( OWS.Identifier('foo'), WPS.DataInputs( WPS.Input( OWS.Identifier('name'), WPS.Reference(WPS.Body('request body'), { '{http://www.w3.org/1999/xlink}href': 'http://foo/bar/service' }, method='POST')))) rv = get_inputs_from_xml(request_doc) self.assertEqual(rv['name'][0]['href'], 'http://foo/bar/service') self.assertEqual(rv['name'][0]['method'], 'POST') self.assertEqual(rv['name'][0]['body'], 'request body')
def execute_xml(self): """ :return: execute response element """ doc = WPS.Input( OWS.Identifier(self.identifier), OWS.Title(self.title) ) if self.abstract: doc.append(OWS.Abstract(self.abstract)) bbox_data_doc = OWS.BoundingBox() bbox_data_doc.attrib['crs'] = self.crs bbox_data_doc.attrib['dimensions'] = str(self.dimensions) bbox_data_doc.append( OWS.LowerCorner('{0[0]} {0[1]}'.format(self.data))) bbox_data_doc.append( OWS.UpperCorner('{0[2]} {0[3]}'.format(self.data))) doc.append(bbox_data_doc) return doc
def describe_xml(self): input_elements = [i.describe_xml() for i in self.inputs] output_elements = [i.describe_xml() for i in self.outputs] doc = E.ProcessDescription(OWS.Identifier(self.identifier), OWS.Title(self.title)) doc.attrib[ '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.version if self.store_supported == 'true': doc.attrib['storeSupported'] = self.store_supported if self.status_supported == 'true': doc.attrib['statusSupported'] = self.status_supported if self.abstract: doc.append(OWS.Abstract(self.abstract)) if self.keywords: kws = map(OWS.Keyword, self.keywords) doc.append(OWS.Keywords(*kws)) for m in self.metadata: doc.append(OWS.Metadata(dict(m))) for p in self.profile: doc.append(WPS.Profile(p)) if input_elements: doc.append(E.DataInputs(*input_elements)) doc.append(E.ProcessOutputs(*output_elements)) return doc
def test_post_one_arg(self): request_doc = WPS.DescribeProcess( OWS.Identifier('hello'), version='1.0.0' ) resp = self.client.post_xml(doc=request_doc) assert [pr.identifier for pr in get_describe_result(resp)] == ['hello']
def _execute_xml_reference(self): """Return Reference node """ doc = WPS.Reference() store_type = config.get_config_value('server', 'store_type') self.storage = None if store_type == 'db': db_storage_instance = DbStorage() self.storage = db_storage_instance.get_db_type() else: self.storage = FileStorage() """ to be implemented: elif store_type == 's3' and \ config.get_config_value('s3', 'bucket_name'): self.storage = S3Storage() """ doc.attrib['{http://www.w3.org/1999/xlink}href'] = self.get_url() if self.data_format: if self.data_format.mime_type: doc.attrib['mimeType'] = self.data_format.mime_type if self.data_format.encoding: doc.attrib['encoding'] = self.data_format.encoding if self.data_format.schema: doc.attrib['schema'] = self.data_format.schema return doc
def _execute_xml_reference(self): """Return Reference node """ doc = WPS.Reference() storage_option = config.get_config_value('remote-storage', 'storage_option') if storage_option == 'ftp': self.storage = FTPStorage() elif storage_option == 'dropbox': self.storage = DropboxStorage() elif storage_option == 'googledrive': self.storage = GoogleDriveStorage() else: self.storage = FileStorage() # get_url will create the file and return the url for it doc.attrib['{http://www.w3.org/1999/xlink}href'] = self.get_url() if self.data_format: if self.data_format.mime_type: doc.attrib['mimeType'] = self.data_format.mime_type if self.data_format.encoding: doc.attrib['encoding'] = self.data_format.encoding if self.data_format.schema: doc.attrib['schema'] = self.data_format.schema return doc
def execute_xml(self): """Render Execute response XML node :return: node :rtype: ElementMaker """ node = None if self.as_reference: node = self._execute_xml_reference() else: node = self._execute_xml_data() doc = WPS.Input( OWS.Identifier(self.identifier), OWS.Title(self.title) ) if self.abstract: doc.append(OWS.Abstract(self.abstract)) if self.keywords: kws = map(OWS.Keyword, self.keywords) doc.append(OWS.Keywords(*kws)) doc.append(node) return doc
def test_post_with_no_inputs(self): client = client_for(Service(processes=[create_ultimate_question()])) request_doc = WPS.Execute(OWS.Identifier('ultimate_question'), version='1.0.0') resp = client.post_xml(doc=request_doc) assert_response_success(resp) assert get_output(resp.xml) == {'outvalue': '42'}
def describe(self, identifiers): if not identifiers: raise MissingParameterValue('', 'identifier') identifier_elements = [] # 'all' keyword means all processes if 'all' in (ident.lower() for ident in identifiers): for process in self.processes: try: identifier_elements.append(self.processes[process].describe_xml()) except Exception as e: raise NoApplicableCode(e) else: for identifier in identifiers: try: process = self.processes[identifier] except KeyError: raise InvalidParameterValue("Unknown process %r" % identifier, "identifier") else: try: identifier_elements.append(process.describe_xml()) except Exception as e: raise NoApplicableCode(e) doc = WPS.ProcessDescriptions( *identifier_elements ) doc.attrib['{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'] = 'http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd' doc.attrib['service'] = 'WPS' doc.attrib['version'] = '1.0.0' doc.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = 'en-CA' return xml_response(doc)
def test_post_two_args(self): request_doc = WPS.DescribeProcess(OWS.Identifier('hello'), OWS.Identifier('ping'), version='1.0.0') resp = self.client.post_xml(doc=request_doc) result = get_describe_result(resp) assert [pr.identifier for pr in result] == ['hello', 'ping']
def test_complex_input_base64_value(self): the_data = 'eyAicGxvdCI6eyAiVmVyc2lvbiIgOiAiMC4xIiB9IH0=' request_doc = WPS.Execute( OWS.Identifier('foo'), WPS.DataInputs( WPS.Input( OWS.Identifier('json'), WPS.Data( WPS.ComplexData(the_data, encoding='base64', mimeType='application/json'))))) rv = get_inputs_from_xml(request_doc) self.assertEqual(rv['json'][0]['mimeType'], 'application/json') json_data = json.loads(rv['json'][0]['data'].decode()) self.assertEqual(json_data['plot']['Version'], '0.1')
def _execute_xml_reference(self): """ Decide what storage model to use and return Reference node """ doc = WPS.Reference() # get_url will create the file and return the url for it store_type = config.get_config_value('server', 'store_type') self.storage = None # chooses FileStorage, S3Storage or PgStorage based on a store_type value in cfg file if store_type == 'db' and \ config.get_config_value('db', 'dbname'): # TODO: more databases in config file self.storage = PgStorage() elif store_type == 's3' and \ config.get_config_value('s3', 'bucket_name'): self.storage = S3Storage() else: self.storage = FileStorage() doc.attrib['{http://www.w3.org/1999/xlink}href'] = self.get_url() if self.data_format: if self.data_format.mime_type: doc.attrib['mimeType'] = self.data_format.mime_type if self.data_format.encoding: doc.attrib['encoding'] = self.data_format.encoding if self.data_format.schema: doc.attrib['schema'] = self.data_format.schema return doc
def _execute_xml_reference(self): """Return Reference node """ doc = WPS.Reference() doc.attrib['{http://www.w3.org/1999/xlink}href'] = self.stream if self.method.upper() == 'POST' or self.method.upper() == 'GET': doc.attrib['method'] = self.method.upper() return doc
def _execute_xml_data(self): """Return Data node """ doc = WPS.Data() bbox_data_doc = WPS.BoundingBoxData() if self.crs: bbox_data_doc.attrib['crs'] = self.crs if self.dimensions: bbox_data_doc.attrib['dimensions'] = str(self.dimensions) bbox_data_doc.append( OWS.LowerCorner('{0[0]} {0[1]}'.format(self.data))) bbox_data_doc.append( OWS.UpperCorner('{0[2]} {0[3]}'.format(self.data))) doc.append(bbox_data_doc) return doc
def execute_xml_lineage(self): doc = WPS.Output(OWS.Identifier(self.identifier), OWS.Title(self.title)) if self.abstract: doc.append(OWS.Abstract(self.abstract)) return doc
def test_post_bad_version(self): acceptedVersions_doc = OWS.AcceptVersions(OWS.Version('2001-123')) request_doc = WPS.GetCapabilities(acceptedVersions_doc) resp = self.client.post_xml(doc=request_doc) exception = resp.xpath('/ows:ExceptionReport' '/ows:Exception') assert resp.status_code == 400 assert exception[0].attrib[ 'exceptionCode'] == 'VersionNegotiationFailed'
def test_bbox_input(self): if not PY2: self.skipTest('OWSlib not python 3 compatible') request_doc = WPS.Execute( OWS.Identifier('request'), WPS.DataInputs( WPS.Input( OWS.Identifier('bbox'), WPS.Data( WPS.BoundingBoxData(OWS.LowerCorner('40 50'), OWS.UpperCorner('60 70')))))) rv = get_inputs_from_xml(request_doc) bbox = rv['bbox'][0] assert isinstance(bbox, BoundingBox) assert bbox.minx == '40' assert bbox.miny == '50' assert bbox.maxx == '60' assert bbox.maxy == '70'
def execute_xml(self): doc = WPS.Output(OWS.Identifier(self.identifier), OWS.Title(self.title)) if self.abstract: doc.append(OWS.Abstract(self.abstract)) data_doc = WPS.Data() literal_data_doc = WPS.LiteralData(text_type(self.data)) literal_data_doc.attrib['dataType'] = OGCTYPE[self.data_type] if self.uom: literal_data_doc.attrib['uom'] = self.uom.execute_attribute() data_doc.append(literal_data_doc) doc.append(data_doc) return doc