Example #1
0
    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())
Example #2
0
def test_wps_ncml():

    client = client_for(Service(processes=[NcMLAgg()], cfgfiles=CFG_FILE))

    resp = client.get(service='wps',
                      request='execute',
                      version='1.0.0',
                      identifier='ncml')

    assert_response_success(resp)

    ex = WPSExecution()
    ex.parseResponse(resp.xml)
    d1, d2, d3 = ex.processOutputs
    ncml = d3.retrieveData()
    assert ncml.strip().startswith("<")
Example #3
0
def execute_process(client,
                    identifier,
                    inputs,
                    output_names=("output_netcdf", )) -> xr.Dataset:
    """Execute a process using the test client, and return the 'output_netcdf' output as an xarray.Dataset"""
    request_doc = WPS.Execute(OWS.Identifier(identifier),
                              WPS.DataInputs(*inputs),
                              version="1.0.0")
    response = client.post_xml(doc=request_doc)
    assert_response_success(response)

    execution = WPSExecution()
    execution.parseResponse(response.xml)

    outputs = get_file_outputs(execution, output_names=output_names)

    return outputs
Example #4
0
def execute_process(client, identifier, inputs,
                    output_names=("output", )) -> xr.Dataset:
    """Execute a process using the test client, and return the 'output_netcdf' output as an xarray.Dataset"""
    request_doc = WPS.Execute(OWS.Identifier(identifier),
                              WPS.DataInputs(*inputs),
                              version="1.0.0")
    response = client.post_xml(doc=request_doc)
    try:
        assert_response_success(response)
    except AssertionError as e:
        exception = response.xpath("//ows:Exception")[0]
        exception_code = exception.get("exceptionCode")
        message = exception[0].text
        output_message = f"{exception_code}: {message}"
        raise ProcessError(output_message) from e

    execution = WPSExecution()
    execution.parseResponse(response.xml)

    outputs = get_outputs(execution, output_names=output_names)

    return outputs