def test_thredds(): import lxml.etree client = client_for( Service(processes=[SubsetGridPointProcess()], cfgfiles=CFG_FILE)) fn1 = ( "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/cmip5/MRI/rcp85/fx/atmos/r0i0p0/sftlf/" "sftlf_fx_MRI-CGCM3_rcp85_r0i0p0.nc") fn2 = ( "https://pavics.ouranos.ca/twitcher/ows/proxy/thredds/dodsC/birdhouse/cmip5/MRI/rcp85/fx/atmos/r0i0p0/orog/" "orog_fx_MRI-CGCM3_rcp85_r0i0p0.nc") datainputs = (f"resource=files@xlink:href={fn1};" f"resource=files@xlink:href={fn2};" "lat=45.0;" "lon=150.0;") resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=subset_gridpoint&datainputs={datainputs}" ) assert_response_success(resp) out = get_output(resp.xml) links = get_metalinks(lxml.etree.fromstring(out["ref"].encode())) assert len(links) == 2
def describe_process(self, process): client = client_for(Service(processes=[process])) resp = client.get( '?service=wps&version=1.0.0&Request=DescribeProcess&identifier={}'. format(process.identifier)) [result] = get_describe_result(resp) return result
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 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_wps_subset_c3s_cmip6_metadata(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = f"collection={C3S_CMIP6_MON_TASMIN_COLLECTION}" datainputs += ";time=2010/2010" resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=subset&lineage=true&datainputs={datainputs}" ) # print(resp.data) assert_response_success(resp) m_path = get_output(resp.xml)["output"] assert "meta4" in m_path # parse metalink xml = open(m_path[7:], "r").read() urls = parse_metalink(xml) # print(urls) ds = xr.open_dataset(urls[0][7:], use_cftime=True) # check fill value in bounds assert "_FillValue" not in ds.lat_bnds.encoding assert "_FillValue" not in ds.lon_bnds.encoding assert "_FillValue" not in ds.time_bnds.encoding # check fill value in coordinates assert "_FillValue" not in ds.time.encoding assert "_FillValue" not in ds.lat.encoding assert "_FillValue" not in ds.lon.encoding assert "_FillValue" not in ds.height.encoding # check coordinates in bounds assert "coordinates" not in ds.lat_bnds.encoding assert "coordinates" not in ds.lon_bnds.encoding assert "coordinates" not in ds.time_bnds.encoding
def test_wps_empirical_quantile_mapping(netcdf_sdba_ds, kind, name): client = client_for( Service(processes=[EmpiricalQuantileMappingProcess()], cfgfiles=CFG_FILE)) sdba_ds, u = netcdf_sdba_ds datainputs = ( f"ref=files@xlink:href=file://{sdba_ds[f'qdm_{name}_ref']};" f"hist=files@xlink:href=file://{sdba_ds[f'qdm_{name}_hist']};" f"sim=files@xlink:href=file://{sdba_ds[f'qdm_{name}_hist']};" "group=time;" f"kind={quote_plus(kind)};" "nquantiles=50;" "interp=linear;") resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=empirical_quantile_mapping&datainputs={datainputs}" ) print(resp.response) assert_response_success(resp) out = get_output(resp.xml) p = xr.open_dataset(out["output"][7:])[name] uc = convert_calendar(u, "noleap") middle = ((uc > 1e-2) * (uc < 0.99)).data ref = xr.open_dataset(sdba_ds[f"qdm_{name}_ref"])[name] refc = convert_calendar(ref, "noleap") np.testing.assert_allclose(p[middle], refc[middle], rtol=0.03)
def setUp(self): def pr1(): pass def pr2(): pass self.client = client_for( Service(processes=[ Process( pr1, "pr1", "Process 1", abstract="Process 1", keywords=["kw1a", "kw1b"], metadata=[Metadata("pr1 metadata")], ), Process( pr2, "pr2", "Process 2", keywords=["kw2a"], metadata=[Metadata("pr2 metadata")], ), ]))
def setUp(self): configuration.load_configuration() configuration.CONFIG.set('server', 'language', 'en-US,fr-CA') self.client = client_for( Service(processes=[ Process( lambda: None, "pr1", "Process 1", abstract="Process 1", translations={ "fr-CA": { "title": "Processus 1", "abstract": "Processus 1" } }, ), Process( lambda: None, "pr2", "Process 2", abstract="Process 2", translations={"fr-CA": { "title": "Processus 2" }}, ), ]))
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 setUp(self): def hello(request): pass def ping(request): pass processes = [ Process( hello, 'hello', 'Process Hello', metadata=[ Metadata( 'hello metadata', 'http://example.org/hello', role= 'http://www.opengis.net/spec/wps/2.0/def/process/description/documentation' ) ]), Process(ping, 'ping', 'Process Ping', metadata=[ Metadata('ping metadata', 'http://example.org/ping') ]), ] self.client = client_for(Service(processes=processes))
def test_bbox(self): 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:WGS84BoundingBox/ows:LowerCorner')[0].text) self.assertEqual( ' 16 51 ', xpath_ns( output, './wps:Data/ows:WGS84BoundingBox/ows:UpperCorner')[0].text)
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_subset_c3s_cmip6_collection_only(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = f"collection={C3S_CMIP6_MON_COLLECTION}" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_response_success(resp) assert "meta4" in get_output(resp.xml)["output"]
def test_wps_subset(): client = client_for(Service(processes=[Subset()], cfgfiles=[CFG_FILE])) datainputs = "data_ref=cmip5.output1.MOHC.HadGEM2-ES.rcp85.mon.atmos.Amon.r1i1p1.latest.tas" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_response_success(resp) assert 'output' in get_output(resp.xml)
def test_wps_movieplotter(): client = client_for(Service(processes=[MoviePlotter()])) datainputs = "title=Test Move Plotter" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=movieplotter&datainputs={}" .format(datainputs)) assert_response_success(resp) assert 'movieplotter.gif' in get_output(resp.xml)['output']
def test_wps_subset_cru_ts(load_ceda_test_data): client = client_for(Service(processes=[SubsetCRUTS()], cfgfiles=[PYWPS_CFG])) datainputs = "dataset_version=cru_ts.4.04;variable=wet;time=1951-01-01/2005-12-15;area=1,1,300,89" resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=subset_cru_ts&datainputs={datainputs}" ) assert_response_success(resp) assert "meta4" in get_output(resp.xml)["output"]
def test_wps_subset_no_inv(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest" datainputs += ";time=1860-01-01/1900-12-30" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert resp.status_code == 200
def test_wps_subset_missing_collection(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) # datainputs = "collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest" datainputs = "" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_process_exception(resp, code="MissingParameterValue")
def test_wps_average(): client = client_for(Service(processes=[Average()])) datainputs = "data_ref=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=average&datainputs={}" .format(datainputs)) assert_response_success(resp) assert 'output' in get_output(resp.xml)
def test_get_with_no_inputs(self): client = client_for(Service(processes=[create_ultimate_question()])) resp = client.get( '?service=wps&version=1.0.0&Request=Execute&identifier=ultimate_question' ) assert_response_success(resp) assert get_output(resp.xml) == {'outvalue': '42'}
def test_bad_service_type_with_get(self): client = client_for(Service()) resp = client.get('?service=foo') exception = resp.xpath('/ows:ExceptionReport' '/ows:Exception') assert resp.status_code == 400 assert exception[0].attrib['exceptionCode'] == 'InvalidParameterValue'
def setUp(self): self.config = ConfigParser.RawConfigParser() if os.path.isfile('configtests.cfg'): self.config.read('configtests.cfg') else: self.config.read('flyingpigeon/tests/configtests.cfg') sys.path.append('/'.join(os.getcwd().split('/')[:-1])) from flyingpigeon.processes import AveragerWFSProcess self.client = client_for(Service(processes=[AveragerWFSProcess()]))
def test_wps_subset_cmip6_original_files(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=CMIP6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.rlds.gr.v20180803" datainputs += ";time=1860-01-01/1900-12-30;original_files=1" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_response_success(resp) assert "meta4" in get_output(resp.xml)["output"]
def test_wps_subset_time_invariant_dataset(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=c3s-cmip6.ScenarioMIP.IPSL.IPSL-CM6A-LR.ssp119.r1i1p1f1.fx.mrsofc.gr.v20190410" datainputs += ";area=1,1,300,89" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_response_success(resp) assert "meta4" in get_output(resp.xml)["output"]
def test_wps_subset_with_time(): client = client_for(Service(processes=[Subset()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest" datainputs += ";time=1860-01-01/1900-12-30" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset&datainputs={}" .format(datainputs)) assert_response_success(resp) assert 'meta4' in get_output(resp.xml)['output']
def test_wps_correlate_field(): client = client_for(Service(processes=[CorrelateField()])) datainputs = "netcdf_field=cru_ts3.22.1901.2013.pre.dat.nc;" datainputs += "netcdf_timeseries=nino3.nc;months=1:12;averaging_method=ave;lag=3;time_frequency=mon" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=correlate_field&datainputs={}".format( datainputs)) assert_response_success(resp) assert get_output(resp.xml) == {'data': '', 'success': 'False'}
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_average_no_dim(): client = client_for( Service(processes=[AverageByDimension()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=c3s-cmip6.ScenarioMIP.INM.INM-CM5-0.ssp245.r1i1p1f1.Amon.rlds.gr1.v20190619" resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=average&datainputs={datainputs}" ) # print(resp.data) assert_process_exception(resp, code="MissingParameterValue")
def test_wps_multiple_outputs(): client = client_for(Service(processes=[MultipleOutputs()])) datainputs = "count=2" resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=multiple_outputs&datainputs={}" .format(datainputs)) assert_response_success(resp) out = get_output(resp.xml) assert 'output' in out.keys() assert 'reference' in out.keys()
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_wps_average_time_cmip5(): client = client_for( Service(processes=[AverageByDimension()], cfgfiles=[PYWPS_CFG])) datainputs = "collection=c3s-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest" datainputs += ";dims=time" resp = client.get( f"?service=WPS&request=Execute&version=1.0.0&identifier=average&datainputs={datainputs}" ) assert_response_success(resp) assert "output" in get_output(resp.xml)
def test_wps_orchestrate(): client = client_for( Service(processes=[Orchestrate()], cfgfiles=[PYWPS_CFG])) datainputs = "workflow=@xlink:href=file://{0}".format( resource_file('subset_wf_1.json')) resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=orchestrate&datainputs={}" .format(datainputs)) assert_response_success(resp) assert 'meta4' in get_output(resp.xml)['output']
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 setUp(self): def hello(request): pass def ping(request): pass processes = [ Process(hello, 'hello', 'Process Hello', metadata=[ Metadata('hello metadata', 'http://example.org/hello', role='http://www.opengis.net/spec/wps/2.0/def/process/description/documentation')]), Process(ping, 'ping', 'Process Ping', metadata=[Metadata('ping metadata', 'http://example.org/ping')]), ] self.client = client_for(Service(processes=processes))
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_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_output_response_dataType(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) el = next(resp.xml.iter('{http://www.opengis.net/wps/1.0.0}LiteralData')) assert el.attrib['dataType'] == 'string'
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_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_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_wps_subset_bbox(): client = client_for(Service(processes=[SubsetBboxProcess()], cfgfiles=CFG_FILE)) datainputs = "resource=files@xlink:href={fn};" \ "lat0={lat0};" \ "lon0={lon0};" \ "lat1={lat1};" \ "lon1={lon1};" \ .format(fn=TESTDATA['cmip5_tasmax_2006_nc'], lat0=2., lon0=3., lat1=4., lon1=5.) resp = client.get( "?service=WPS&request=Execute&version=1.0.0&identifier=subset_bbox&datainputs={}".format( datainputs)) print(resp.get_data()) assert_response_success(resp) out = get_output(resp.xml) ds = nc.Dataset(out['output'][7:]) check_bnds(ds['lat_bnds'], 2, 4) check_bnds(ds['lon_bnds'], 3, 5) assert 'metalink' in out
def test_metalink(self): client = client_for(Service(processes=[create_metalink_process()])) resp = client.get('?Request=Execute&identifier=multiple-outputs') assert resp.status_code == 400
def setUp(self): def pr1(): pass def pr2(): pass self.client = client_for(Service(processes=[Process(pr1, 'pr1', 'Process 1', metadata=[Metadata('pr1 metadata')]), Process(pr2, 'pr2', 'Process 2', metadata=[Metadata('pr2 metadata')])]))
def describe_process(self, process): client = client_for(Service(processes=[process])) resp = client.get('?service=wps&version=1.0.0&Request=DescribeProcess&identifier=%s' % process.identifier) [result] = get_describe_result(resp) return result
def test_bad_request_type_with_post(self): client = client_for(Service()) request_doc = WPS.Foo() resp = client.post_xml('', doc=request_doc) assert resp.status_code == 400
def test_missing_process_error(self): client = client_for(Service(processes=[create_ultimate_question()])) resp = client.get('?Request=Execute&identifier=foo') assert resp.status_code == 400
def test_get_with_no_inputs(self): client = client_for(Service(processes=[create_ultimate_question()])) resp = client.get('?service=wps&version=1.0.0&Request=Execute&identifier=ultimate_question') assert_response_success(resp) assert get_output(resp.xml) == {'outvalue': '42'}
def test_bad_http_verb(self): client = client_for(Service()) resp = client.put('') assert resp.status_code == 405 # method not allowed
def setUp(self): def pr1(): pass def pr2(): pass self.client = client_for(Service(processes=[Process(pr1, 'pr1', 'Process 1', abstract='Process 1', keywords=['kw1a','kw1b'], metadata=[Metadata('pr1 metadata')]), Process(pr2, 'pr2', 'Process 2', keywords=['kw2a'], metadata=[Metadata('pr2 metadata')])]))
def setUp(self): self.client = client_for(Service(processes=[]))
def setUp(self): def hello(request): pass def ping(request): pass processes = [Process(hello, 'hello', 'Process Hello'), Process(ping, 'ping', 'Process Ping')] self.client = client_for(Service(processes=processes))
def test_bad_request_type_with_get(self): client = client_for(Service()) resp = client.get('?Request=foo') assert resp.status_code == 400