示例#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
示例#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)
示例#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
示例#4
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
示例#5
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
示例#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
示例#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
示例#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']
示例#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
示例#10
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'
示例#11
0
    def test_bbox_io(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.0 50.0',
            xpath_ns(output, './ows:BoundingBox/ows:LowerCorner')[0].text)
示例#12
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
示例#13
0
 def _get_geometryTypes(el):
     for metadata_el in xpath_ns(el, './ows:Metadata'):
         if metadata_el.attrib['{http://www.w3.org/1999/xlink}title'] == 'processing:geometryType':
             yield metadata_el.attrib['{http://www.w3.org/1999/xlink}href']