Exemplo n.º 1
0
def test_literal_allowed_values_input():
    """Test all around allowed_values
    """
    literal = LiteralInput(
        'foo',
        'Foo',
        data_type='integer',
        uoms=['metre'],
        allowed_values=(1, 2, (5, 10), (12, 4, 24),
                        AllowedValue(allowed_type=ALLOWEDVALUETYPE.RANGE,
                                     minval=30,
                                     maxval=33,
                                     range_closure='closed-open')))
    doc = literal.describe_xml()

    allowed_values = xpath_ns(doc, './LiteralData/ows:AllowedValues')
    assert len(allowed_values) == 1

    allowed_value = allowed_values[0]

    values = xpath_ns(allowed_value, './ows:Value')
    ranges = xpath_ns(allowed_value, './ows:Range')

    assert len(values) == 2
    assert len(ranges) == 3
Exemplo n.º 2
0
def test_format_class():
    """Test pyqgiswps.formats.Format class
    """
    frmt = Format('mimetype',
                  schema='halloworld',
                  encoding='asdf',
                  validate=validate)

    assert frmt.mime_type == 'mimetype'
    assert frmt.schema == 'halloworld'
    assert frmt.encoding == 'asdf'
    assert frmt.validate('the input', 1)

    describeel = frmt.describe_xml()
    assert 'Format' == describeel.tag
    mimetype = xpath_ns(describeel, '/Format/MimeType')
    encoding = xpath_ns(describeel, '/Format/Encoding')
    schema = xpath_ns(describeel, '/Format/Schema')

    assert mimetype
    assert encoding
    assert schema

    assert mimetype[0].text == 'mimetype'
    assert encoding[0].text == 'asdf'
    assert schema[0].text == 'halloworld'

    frmt2 = get_format('GML')

    assert not frmt.same_as(frmt2)
Exemplo n.º 3
0
def test_bbox_output():
    bbox = BoundingBoxOutput('bbox', 'BBox foo', crss=["EPSG:4326"])
    doc = bbox.describe_xml()
    [outpt] = xpath_ns(doc, '/Output')
    [default_crs] = xpath_ns(doc, './BoundingBoxOutput/Default/CRS')
    supported = xpath_ns(doc, './BoundingBoxOutput/Supported/CRS')
    assert default_crs.text == 'EPSG:4326'
    assert len(supported) == 1
Exemplo n.º 4
0
def get_output(doc):
    output = {}
    for output_el in xpath_ns(
            doc, '/wps:ExecuteResponse'
            '/wps:ProcessOutputs/wps:Output'):
        [identifier_el] = xpath_ns(output_el, './ows:Identifier')
        [value_el] = xpath_ns(output_el, './wps:Data/wps:LiteralData')
        output[identifier_el.text] = value_el.text
    return output
Exemplo n.º 5
0
def test_complex_output():
    complexo = ComplexOutput('complex', 'Complex foo', [Format('GML')])
    doc = complexo.describe_xml()
    [outpt] = xpath_ns(doc, '/Output')
    [default] = xpath_ns(doc, '/Output/ComplexOutput/Default/Format/MimeType')
    supported = xpath_ns(doc,
                         '/Output/ComplexOutput/Supported/Format/MimeType')
    assert default.text == 'application/gml+xml'
    assert len(supported) == 1
Exemplo n.º 6
0
def get_describe_result(self, resp):
    assert resp.status_code == 200, "200 != %s" % resp.status_code
    assert resp.headers['Content-Type'] == 'text/xml;charset=utf-8'
    result = []
    for desc_el in resp.xpath('/wps:ProcessDescriptions/ProcessDescription'):
        [identifier_el] = xpath_ns(desc_el, './ows:Identifier')
        inputs = []
        metadata = []
        for metadata_el in xpath_ns(desc_el, './ows:Metadata'):
            metadata.append(
                metadata_el.attrib['{http://www.w3.org/1999/xlink}title'])
        for input_el in xpath_ns(desc_el, './DataInputs/Input'):
            [input_identifier_el] = xpath_ns(input_el, './ows:Identifier')
            input_identifier = input_identifier_el.text
            literal_data_el_list = xpath_ns(input_el, './LiteralData')
            complex_data_el_list = xpath_ns(input_el, './ComplexData')
            if literal_data_el_list:
                [literal_data_el] = literal_data_el_list
                [data_type_el] = xpath_ns(literal_data_el, './ows:DataType')
                data_type = get_data_type(data_type_el)
                inputs.append((input_identifier, 'literal', data_type))
            elif complex_data_el_list:
                [complex_data_el] = complex_data_el_list
                formats = []
                for format_el in xpath_ns(complex_data_el,
                                          './Supported/Format'):
                    [mimetype_el] = xpath_ns(format_el, './ows:MimeType')
                    formats.append({'mime_type': mimetype_el.text})
                inputs.append((input_identifier, 'complex', formats))
            else:
                raise RuntimeError("Can't parse input description")
        result.append(ProcessDescription(identifier_el.text, inputs, metadata))
    return result
Exemplo n.º 7
0
def test_bbox_input():
    bbox = BoundingBoxInput('bbox',
                            'BBox foo',
                            crss=["EPSG:4326", "EPSG:3035"])
    doc = bbox.describe_xml()
    [inpt] = xpath_ns(doc, '/Input')
    [default_crs] = xpath_ns(doc, './BoundingBoxData/Default/CRS')
    supported = xpath_ns(doc, './BoundingBoxData/Supported/CRS')
    assert inpt.attrib['minOccurs'] == '1'
    assert default_crs.text == 'EPSG:4326'
    assert len(supported) == 2
Exemplo n.º 8
0
def test_complex_input_default_and_supported():
    complex_in = ComplexInput('foo',
                              'Complex foo',
                              supported_formats=[Format('a/b'),
                                                 Format('c/d')])
    doc = complex_in.describe_xml()
    [default_format] = xpath_ns(doc, './ComplexData/Default/Format')
    [default_mime_el] = xpath_ns(default_format, './MimeType')
    assert default_mime_el.text == 'a/b'
    supported_mime_types = []
    for supported_el in xpath_ns(doc, './ComplexData/Supported/Format'):
        [mime_el] = xpath_ns(supported_el, './MimeType')
        supported_mime_types.append(mime_el.text)
    assert supported_mime_types == ['a/b', 'c/d']
Exemplo n.º 9
0
def test_literal_integer_input():
    literal = LiteralInput('foo',
                           'Literal foo',
                           data_type='positiveInteger',
                           uoms=['metre'])
    doc = literal.describe_xml()
    assert doc.tag == E.Input().tag
    [identifier_el] = xpath_ns(doc, './ows:Identifier')
    assert identifier_el.text == 'foo'
    [type_el] = xpath_ns(doc, './LiteralData/ows:DataType')
    assert type_el.text == 'positiveInteger'
    assert type_el.attrib['{%s}reference' %
                          NAMESPACES['ows']] == OGCTYPE['positiveInteger']
    anyvalue = xpath_ns(doc, './LiteralData/ows:AnyValue')
    assert len(anyvalue) == 1
Exemplo n.º 10
0
        def parse_post_execute():
            """Parse POST Execute request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            language = doc.attrib.get('language')
            wpsrequest.check_and_set_language(language)

            wpsrequest.operation = 'execute'

            identifier = xpath_ns(doc, './ows:Identifier')

            if not identifier:
                raise MissingParameterValue('Process identifier not set',
                                            'Identifier')

            wpsrequest.identifier = identifier[0].text
            wpsrequest.lineage = 'false'
            wpsrequest.store_execute = 'false'
            wpsrequest.status = 'false'
            wpsrequest.inputs = get_inputs_from_xml(doc)
            wpsrequest.outputs = get_output_from_xml(doc)
            wpsrequest.raw = False
            if xpath_ns(doc,
                        '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
                wpsrequest.raw = True
                # executeResponse XML will not be stored
                wpsrequest.store_execute = 'false'

            # check if response document tag has been set then retrieve
            response_document = xpath_ns(
                doc, './wps:ResponseForm/wps:ResponseDocument')
            if len(response_document) > 0:
                wpsrequest.lineage = response_document[0].attrib.get(
                    'lineage', 'false')
                wpsrequest.store_execute = response_document[0].attrib.get(
                    'storeExecuteResponse', 'false')
                # XXX If storeExecuteResponse is set then we enforce
                # the status supports
                wpsrequest.status = wpsrequest.store_execute
                # Set timeout
                timeout = response_document[0].attrib.get('timeout')
                wpsrequest.check_and_set_timeout(timeout)
                # Set expiration
                expire = response_document[0].attrib.get('expire')
                wpsrequest.check_and_set_expiration(expire)
Exemplo n.º 11
0
 def parse_post_getcapabilities():
     """Parse POST GetCapabilities request
     """
     acceptedversions = xpath_ns(
         doc, '/wps:GetCapabilities/ows:AcceptVersions/ows:Version')
     acceptedversions = ','.join(map(lambda v: v.text,
                                     acceptedversions))
     wpsrequest.check_accepted_versions(acceptedversions)
Exemplo n.º 12
0
def test_complex_input_identifier():
    complex_in = ComplexInput('foo',
                              'Complex foo',
                              supported_formats=[Format('bar/baz')])
    doc = complex_in.describe_xml()
    assert doc.tag == E.Input().tag
    [identifier_el] = xpath_ns(doc, './ows:Identifier')
    assert identifier_el.text == 'foo'
Exemplo n.º 13
0
def get_output_from_xml(doc):
    the_output = {}

    if xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:ResponseDocument'):
        for output_el in xpath_ns(
                doc,
                '/wps:Execute/wps:ResponseForm/wps:ResponseDocument/wps:Output'
        ):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['asReference'] = output_el.attrib.get('asReference', 'false')
            the_output[identifier_el.text] = outpt

    elif xpath_ns(doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
        for output_el in xpath_ns(
                doc, '/wps:Execute/wps:ResponseForm/wps:RawDataOutput'):
            [identifier_el] = xpath_ns(output_el, './ows:Identifier')
            outpt = {}
            outpt[identifier_el.text] = ''
            outpt['mimetype'] = output_el.attrib.get('mimeType', '')
            outpt['encoding'] = output_el.attrib.get('encoding', '')
            outpt['schema'] = output_el.attrib.get('schema', '')
            outpt['uom'] = output_el.attrib.get('uom', '')
            the_output[identifier_el.text] = outpt

    return the_output
Exemplo n.º 14
0
    def test_bbox(self):
        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 = self.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)
Exemplo n.º 15
0
        def parse_post_describeprocess():
            """Parse POST DescribeProcess request
            """

            version = doc.attrib.get('version')
            wpsrequest.check_and_set_version(version)

            language = doc.attrib.get('language')
            wpsrequest.check_and_set_language(language)

            wpsrequest.operation = 'describeprocess'
            wpsrequest.identifiers = [
                identifier_el.text
                for identifier_el in xpath_ns(doc, './ows:Identifier')
            ]
Exemplo n.º 16
0
def test_literal_output():
    literal = LiteralOutput('literal', 'Literal foo', uoms=['metre'])
    doc = literal.describe_xml()
    [output] = xpath_ns(doc, '/Output')
    [identifier] = xpath_ns(doc, '/Output/ows:Identifier')
    [data_type] = xpath_ns(doc, '/Output/LiteralOutput/ows:DataType')
    [uoms] = xpath_ns(doc, '/Output/LiteralOutput/UOMs')
    [default_uom] = xpath_ns(uoms, './Default/ows:UOM')
    supported_uoms = xpath_ns(uoms, './Supported/ows:UOM')
    assert output is not None
    assert identifier.text == 'literal'
    assert data_type.attrib['{%s}reference' %
                            NAMESPACES['ows']] == OGCTYPE['string']
    assert uoms is not None
    assert default_uom.text == 'metre'
    assert default_uom.attrib['{%s}reference' %
                              NAMESPACES['ows']] == OGCUNIT['metre']
    assert len(supported_uoms) == 1
Exemplo n.º 17
0
def get_inputs_from_xml(doc):
    the_inputs = {}
    for input_el in xpath_ns(doc, '/wps:Execute/wps:DataInputs/wps:Input'):
        [identifier_el] = xpath_ns(input_el, './ows:Identifier')
        identifier = identifier_el.text

        if identifier not in the_inputs:
            the_inputs[identifier] = []

        literal_data = xpath_ns(input_el, './wps:Data/wps:LiteralData')
        if literal_data:
            value_el = literal_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['data'] = str(value_el.text)
            inpt['uom'] = value_el.attrib.get('uom', '')
            inpt['datatype'] = value_el.attrib.get('datatype', '')
            the_inputs[identifier].append(inpt)
            continue

        complex_data = xpath_ns(input_el, './wps:Data/wps:ComplexData')
        if complex_data:

            complex_data_el = complex_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt['mimeType'] = complex_data_el.attrib.get('mimeType', '')
            inpt['encoding'] = complex_data_el.attrib.get('encoding',
                                                          '').lower()
            inpt['schema'] = complex_data_el.attrib.get('schema', '')
            inpt['method'] = complex_data_el.attrib.get('method', 'GET')
            if len(complex_data_el.getchildren()) > 0:
                value_el = complex_data_el[0]
                inpt['data'] = _get_dataelement_value(value_el)
            else:
                inpt['data'] = _get_rawvalue_value(complex_data_el.text,
                                                   inpt['encoding'])
            the_inputs[identifier].append(inpt)
            continue

        reference_data = xpath_ns(input_el, './wps:Reference')
        if reference_data:
            reference_data_el = reference_data[0]
            inpt = {}
            inpt['identifier'] = identifier_el.text
            inpt[identifier_el.text] = reference_data_el.text
            inpt['href'] = reference_data_el.attrib.get(
                '{http://www.w3.org/1999/xlink}href', '')
            inpt['mimeType'] = reference_data_el.attrib.get('mimeType', '')
            inpt['method'] = reference_data_el.attrib.get('method', 'GET')
            header_element = xpath_ns(reference_data_el, './wps:Header')
            if header_element:
                inpt['header'] = _get_reference_header(header_element)
            body_element = xpath_ns(reference_data_el, './wps:Body')
            if body_element:
                inpt['body'] = _get_reference_body(body_element[0])
            bodyreference_element = xpath_ns(reference_data_el,
                                             './wps:BodyReference')
            if bodyreference_element:
                inpt['bodyreference'] = _get_reference_bodyreference(
                    bodyreference_element[0])
            the_inputs[identifier].append(inpt)
            continue

        bbox_datas = xpath_ns(input_el, './wps:Data/wps:BoundingBoxData')
        if bbox_datas:
            for bbox_data in bbox_datas:
                bbox_data_el = bbox_data
                bbox = BoundingBox(bbox_data_el)
                the_inputs[identifier].append(bbox)
    return the_inputs