def compare_io(self, name, fn, fmt): """Start the dummy process, post the request and check the response matches the input data.""" # Note that `WPSRequest` calls `get_inputs_from_xml` which converts base64 input to bytes # See `_get_rawvalue_value` client = client_for(Service(processes=[create_fmt_process(name, fn, fmt)])) data = get_data(fn, fmt.encoding) wps = WPSExecution() doc = wps.buildRequest('test-fmt', inputs=[('complex', ComplexDataInput(data, mimeType=fmt.mime_type, encoding=fmt.encoding))], mode='sync') resp = client.post_xml(doc=doc) assert_response_success(resp) wps.parseResponse(resp.xml) out = wps.processOutputs[0].data[0] if 'gml' in fmt.mime_type: xml_orig = etree.tostring(etree.fromstring(data.encode('utf-8'))).decode('utf-8') xml_out = etree.tostring(etree.fromstring(out.decode('utf-8'))).decode('utf-8') # Not equal because the output includes additional namespaces compared to the origin. # self.assertEqual(xml_out, xml_orig) else: self.assertEqual(out.strip(), data.strip())
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/wps:Output') self.assertEqual('outbbox', xpath_ns( output, './ows:Identifier')[0].text) self.assertEqual('15 50', xpath_ns( output, './wps:Data/ows:BoundingBox/ows:LowerCorner')[0].text)
def test_wps_chomsky(): client = client_for(Service(processes=[Chomsky()])) datainputs = "times=10" resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='chomsky', datainputs=datainputs) assert_response_success(resp)
def test_wps_hello(): client = client_for(Service(processes=[SayHello()])) datainputs = "name=LovelySugarBird" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=hello&datainputs={}".format( datainputs)) assert_response_success(resp) assert get_output(resp.xml) == {'output': "Hello LovelySugarBird"}
def test_wps_fetch(): client = client_for(Service(processes=[FetchProcess()])) datainputs = "[email protected]:href={0}".format(TESTDATA['cmip5_tasmax_2006_nc']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='fetch_resources', datainputs=datainputs) assert_response_success(resp)
def test_wps_bbox(): client = client_for(Service(processes=[Box()])) datainputs = "bbox=101,42,110,46" resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='bbox', datainputs=datainputs) assert_response_success(resp)
def test_wps_qa_cfchecker(): client = client_for(Service(processes=[HDHCFChecker()])) datainputs = "[email protected]:href={0};cf_version=auto".format(TESTDATA['noaa_nc_1']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='qa_cfchecker', datainputs=datainputs) assert_response_success(resp)
def test_wps_thredds_download(): client = client_for(Service(processes=[ThreddsDownload()])) datainputs = "[email protected]:href={}".format(TESTDATA['noaa_catalog_1']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='thredds_download', datainputs=datainputs) assert_response_success(resp)
def test_wps_sleep(): client = client_for(Service(processes=[Sleep()])) datainputs = "delay=0.1" resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='sleep', datainputs=datainputs) print(resp.data) assert_response_success(resp)
def test_wps_download(): client = client_for(Service(processes=[Download()])) datainputs = "resource={}".format(TESTDATA['noaa_nc_1']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='download', datainputs=datainputs) assert_response_success(resp)
def test_wps_ncmeta_file(): client = client_for(Service(processes=[NCMeta()])) datainputs = "[email protected]:href={0}".format(NC_FILE_URL) resp = client.get( service='wps', request='execute', version='1.0.0', identifier='ncmeta', datainputs=datainputs) assert_response_success(resp)
def test_wps_spotchecker_file(): client = client_for(Service(processes=[SpotChecker()])) datainputs = "[email protected]:href={0};test=CF-1.6".format(TESTDATA['test_local_nc']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='spotchecker', datainputs=datainputs) assert_response_success(resp)
def test_wps_ncdump_file(): client = client_for(Service(processes=[NCDump()])) datainputs = "[email protected]:href={0};".format(TESTDATA['test_local_nc']) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='ncdump', datainputs=datainputs) assert_response_success(resp)
def test_wps_dummy(): client = client_for(Service(processes=[Dummy()])) datainputs = "input1=10;input2=2" resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='dummyprocess', datainputs=datainputs) assert_response_success(resp) assert get_output(resp.xml) == {'output1': '11', 'output2': '1'}
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 test_wps_wordcount_file(): client = client_for(Service(processes=[WordCounter()])) datainputs = "[email protected]:href=file://{0}".format( resource_file('alice-in-wonderland.txt')) resp = client.get( service='wps', request='execute', version='1.0.0', identifier='wordcounter', datainputs=datainputs) assert_response_success(resp)
def test_wps_poly_centroid_get(): client = client_for(Service(processes=[PolyCentroid(), ], cfgfiles=cfgfiles)) datainputs = "[email protected]:href=file://{0}".format(resource_file('poly.xml')) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='poly_centroid', datainputs=datainputs) assert_response_success(resp) assert get_output(resp.xml) == {'output': "119.59740,-13.57388"}
def test_wps_inout(): client = client_for(Service(processes=[InOut()])) datainputs = "string=onetwothree;int=7;float=2.0;boolean=0;text=some string;[email protected]:href={}" resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='inout', datainputs=datainputs.format(NC_FILE_URL)) assert_response_success(resp) out = get_output(resp.xml) assert out['text'] == 'some string' assert out['dataset'].endswith('.nc')
def test_wps_nonpyid(): d = {'a': 1} client = client_for(Service(processes=[NonPyID()])) datainputs = "input 1=10;input-2={}".format(json.dumps(d)) resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='non.py-id', datainputs=datainputs) assert_response_success(resp) assert get_output(resp.xml) == {'output.1': '11.0', 'output 2': json.dumps(d)}
def test_wps_pointinspection(): client = client_for( Service(processes=[PointinspectionProcess()], cfgfiles=CFG_FILE)) datainputs = datainputs_fmt.format( TESTDATA['cmip5_tasmax_2006_nc'], "2.356138, 48.846450",) resp = client.get( service='wps', request='execute', version='1.0.0', identifier='pointinspection', datainputs=datainputs) assert_response_success(resp)
def test_aggregation(): client = client_for(Service(processes=[ESGSearchProcess()])) datainputs = "url={};search_type={};limit={};offset={};constraints={}".format( 'http://esgf-data.dkrz.de/esg-search', 'Aggregation', '5', '20', 'project:CORDEX,time_frequency:mon,variable:tas,experiment:historical') resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='esgsearch', datainputs=datainputs) assert_response_success(resp)
def test_epsg_based_location(self): """Test whether the EPSG of a mapset corresponds the specified one.""" my_process = grass_epsg_based_location() client = client_for(Service(processes=[my_process])) request_doc = WPS.Execute( OWS.Identifier('my_epsg_based_location'), version='1.0.0' ) resp = client.post_xml(doc=request_doc) assert_response_success(resp)
def test_dataset_query(): client = client_for(Service(processes=[ESGSearchProcess()])) datainputs = "url={};search_type={};limit={};offset={};constraints={};query={}".format( 'http://esgf-data.dkrz.de/esg-search', 'Dataset', '1', '0', 'project:CORDEX', 'geopotential') resp = client.get( service='WPS', request='Execute', version='1.0.0', identifier='esgsearch', datainputs=datainputs) assert_response_success(resp)
def test_wcs(self): try: sys.path.append("/usr/lib/grass64/etc/python/") import grass.script as grass except: self.skipTest("GRASS lib not found") client = client_for(Service(processes=[create_sum_one()])) request_doc = WPS.Execute( OWS.Identifier("sum_one"), WPS.DataInputs(WPS.Input(OWS.Identifier("input"), WPS.Reference(href=wcsResource, mimeType="image/tiff"))), WPS.ProcessOutputs(WPS.Output(OWS.Identifier("output"))), version="1.0.0", ) resp = client.post_xml(doc=request_doc) assert_response_success(resp)
def test_wps_poly_centroid_post(): client = client_for(Service(processes=[PolyCentroid(), ], cfgfiles=cfgfiles)) request_doc = WPS.Execute( OWS.Identifier('poly_centroid'), WPS.DataInputs( WPS.Input( OWS.Identifier('polygon'), WPS.Data(WPS.ComplexData(open(resource_file('poly.xml'), 'r').read())) ) ), version='1.0.0' ) resp = client.post_xml(doc=request_doc) assert_response_success(resp) assert get_output(resp.xml) == {'output': "119.59740,-13.57388"}
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 test_wps_subset_countries(): client = client_for( Service(processes=[SubsetcountryProcess()], cfgfiles=CFG_FILE)) datainputs = datainputs_fmt.format( TESTDATA['cmip5_tasmax_2006_nc'], 'CAN', "True") resp = client.get( service='wps', request='execute', version='1.0.0', identifier='subset_countries', datainputs=datainputs) assert_response_success(resp) # Check output file size is smaller than input. out = get_output(resp.xml) assert 'output' in out.keys()
def test_wfs(self): client = client_for(Service(processes=[create_feature()])) request_doc = WPS.Execute( OWS.Identifier('feature'), WPS.DataInputs( WPS.Input( OWS.Identifier('input'), WPS.Reference( {'{http://www.w3.org/1999/xlink}href': wfsResource}, mimeType=FORMATS.GML.mime_type, encoding='', schema=''))), WPS.ProcessOutputs( WPS.Output( OWS.Identifier('output'))), version='1.0.0' ) resp = client.post_xml(doc=request_doc) assert_response_success(resp)
def test_file_based_location(self): """Test whether the datum of a mapset corresponds the file one.""" my_process = grass_file_based_location() client = client_for(Service(processes=[my_process])) href = 'http://demo.mapserver.org/cgi-bin/wfs?service=WFS&' \ 'version=1.1.0&request=GetFeature&typename=continents&' \ 'maxfeatures=1' request_doc = WPS.Execute( OWS.Identifier('my_file_based_location'), WPS.DataInputs( WPS.Input( OWS.Identifier('input1'), WPS.Reference( {'{http://www.w3.org/1999/xlink}href': href}))), version='1.0.0') resp = client.post_xml(doc=request_doc) assert_response_success(resp)
def test_wps_thredds_workflow(): doc = """ workflow: name: test_thredds_workflow source: thredds: catalog_url: {0} worker: identifier: dummy url: http://localhost:5000/wps resource: dataset inputs: [] """.format(TESTDATA['noaa_catalog_1']) fp = tempfile.NamedTemporaryFile(suffix=".txt") yaml.dump(yaml.load(doc), fp) client = client_for(Service(processes=[DispelWorkflow()])) datainputs = "[email protected]:href=file://{0}".format(fp.name) resp = client.get( service='wps', request='execute', version='1.0.0', identifier='workflow', datainputs=datainputs) assert_response_success(resp)