示例#1
0
    def describe_xml(self):
        """Return Describe process element
        """

        doc = E.Input(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        doc.attrib['minOccurs'] = str(self.min_occurs)
        doc.attrib['maxOccurs'] = str(self.max_occurs)

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        if self.supported_formats is not None:
            default_format_el = self.supported_formats[0].describe_xml()
            supported_format_elements = [f.describe_xml() for f in self.supported_formats]
            doc.append(
                E.ComplexData(
                    E.Default(default_format_el),
                    E.Supported(*supported_format_elements)
                )
            )

        return doc
示例#2
0
    def describe_xml(self):
        doc = E.Output(OWS.Identifier(self.identifier), OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        literal_data_doc = E.LiteralOutput()

        if self.data_type:
            data_type = OWS.DataType(self.data_type)
            data_type.attrib['{%s}reference' %
                             NAMESPACES['ows']] = OGCTYPE[self.data_type]
            literal_data_doc.append(data_type)

        if self.uoms:
            default_uom_element = self.uom.describe_xml()
            supported_uom_elements = [u.describe_xml() for u in self.uoms]

            literal_data_doc.append(
                E.UOMs(E.Default(default_uom_element),
                       E.Supported(*supported_uom_elements)))

        doc.append(literal_data_doc)

        return doc
示例#3
0
 def test_post_two_args(self):
     request_doc = WPS.DescribeProcess(OWS.Identifier('hello'),
                                       OWS.Identifier('ping'),
                                       version='1.0.0')
     resp = self.client.post_xml(doc=request_doc)
     result = get_describe_result(self, resp)
     assert [pr.identifier for pr in result] == ['hello', 'ping']
示例#4
0
    def describe_xml(self):
        """ Return describe XML
        """
        input_elements = [i.describe_xml() for i in self.inputs]
        output_elements = [i.describe_xml() for i in self.outputs]

        doc = E.ProcessDescription(OWS.Identifier(self.identifier),
                                   OWS.Title(self.title))
        doc.attrib[
            '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.version
        doc.attrib['storeSupported'] = 'true'
        doc.attrib['statusSupported'] = 'true'

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        for p in self.profile:
            doc.append(WPS.Profile(p))

        if input_elements:
            doc.append(E.DataInputs(*input_elements))

        doc.append(E.ProcessOutputs(*output_elements))

        return doc
示例#5
0
    def describe_xml(self):
        """
        :return: describeprocess response xml element
        """
        doc = E.Input(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        doc.attrib['minOccurs'] = str(self.min_occurs)
        doc.attrib['maxOccurs'] = str(self.max_occurs)

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        bbox_data_doc = E.BoundingBoxData()
        doc.append(bbox_data_doc)

        default_doc = E.Default()
        default_doc.append(E.CRS(self.crss[0]))

        supported_doc = E.Supported()
        for c in self.crss:
            supported_doc.append(E.CRS(c))

        bbox_data_doc.append(default_doc)
        bbox_data_doc.append(supported_doc)

        return doc
示例#6
0
    def execute_xml_lineage(self):
        doc = WPS.Output(OWS.Identifier(self.identifier),
                         OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        return doc
示例#7
0
 def _process_failed(self):
     return WPS.Status(WPS.ProcessFailed(
         WPS.ExceptionReport(
             OWS.Exception(OWS.ExceptionText(self.message),
                           exceptionCode='NoApplicableCode',
                           locater='None'))),
                       creationTime=time.strftime('%Y-%m-%dT%H:%M:%SZ',
                                                  time.localtime()))
    def test_post_bad_version(self):
        acceptedVersions_doc = OWS.AcceptVersions(OWS.Version('2001-123'))
        request_doc = WPS.GetCapabilities(acceptedVersions_doc)
        resp = self.client.post_xml(doc=request_doc)
        exception = resp.xpath('/ows:ExceptionReport' '/ows:Exception')

        assert resp.status_code == 400
        assert exception[0].attrib[
            'exceptionCode'] == 'VersionNegotiationFailed'
示例#9
0
 def test_post_with_string_input(self):
     request_doc = WPS.Execute(OWS.Identifier('greeter'),
                               WPS.DataInputs(
                                   WPS.Input(
                                       OWS.Identifier('name'),
                                       WPS.Data(WPS.LiteralData('foo')))),
                               version='1.0.0')
     resp = self.client.post_xml(doc=request_doc)
     assert_response_success(resp)
     assert get_output(resp.xml) == {'message': "Hello foo!"}
示例#10
0
def test_two_strings():
    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(OWS.Identifier('name1'),
                      WPS.Data(WPS.LiteralData('foo'))),
            WPS.Input(OWS.Identifier('name2'),
                      WPS.Data(WPS.LiteralData('bar')))))
    rv = get_inputs_from_xml(request_doc)
    assert rv['name1'][0]['data'] == 'foo'
    assert rv['name2'][0]['data'] == 'bar'
示例#11
0
def test_complex_input():
    the_data = E.TheData("hello world")
    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(
                OWS.Identifier('name'),
                WPS.Data(WPS.ComplexData(the_data, mimeType='text/foobar')))))
    rv = get_inputs_from_xml(request_doc)
    assert rv['name'][0]['mimeType'] == 'text/foobar'
    rv_doc = lxml.etree.parse(StringIO(rv['name'][0]['data'])).getroot()
    assert rv_doc.tag == 'TheData'
    assert rv_doc.text == 'hello world'
示例#12
0
def test_one_string():
    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(OWS.Identifier('name'),
                      WPS.Data(WPS.LiteralData('foo'))),
            WPS.Input(OWS.Identifier('name'),
                      WPS.Data(WPS.LiteralData('bar')))))
    rv = get_inputs_from_xml(request_doc)
    assert 'name' in rv
    assert len(rv['name']) == 2
    assert rv['name'][0]['data'] == 'foo'
    assert rv['name'][1]['data'] == 'bar'
示例#13
0
 def describe_xml(self):
     """Return back Element for DescribeProcess response
     """
     doc = None
     if self.allowed_type == ALLOWEDVALUETYPE.VALUE:
         doc = OWS.Value(str(self.value))
     else:
         doc = OWS.Range()
         doc.set('{%s}rangeClosure' % NAMESPACES['ows'], self.range_closure)
         doc.append(OWS.MinimumValue(str(self.minval)))
         doc.append(OWS.MaximumValue(str(self.maxval)))
         if self.spacing:
             doc.append(OWS.Spacing(str(self.spacing)))
     return doc
示例#14
0
def test_complex_input_raw_value():
    the_data = '{ "plot":{ "Version" : "0.1" } }'

    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(
                OWS.Identifier('json'),
                WPS.Data(WPS.ComplexData(the_data,
                                         mimeType='application/json')))))
    rv = get_inputs_from_xml(request_doc)
    assert rv['json'][0]['mimeType'] == 'application/json'
    json_data = json.loads(rv['json'][0]['data'])
    assert json_data['plot']['Version'] == '0.1'
示例#15
0
def test_reference_post_input():
    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(
                OWS.Identifier('name'),
                WPS.Reference(WPS.Body('request body'), {
                    '{http://www.w3.org/1999/xlink}href':
                    'http://foo/bar/service'
                },
                              method='POST'))))
    rv = get_inputs_from_xml(request_doc)
    assert rv['name'][0]['href'] == 'http://foo/bar/service'
    assert rv['name'][0]['method'] == 'POST'
    assert rv['name'][0]['body'] == 'request body'
示例#16
0
def test_complex_input_base64_value():
    the_data = 'eyAicGxvdCI6eyAiVmVyc2lvbiIgOiAiMC4xIiB9IH0='

    request_doc = WPS.Execute(
        OWS.Identifier('foo'),
        WPS.DataInputs(
            WPS.Input(
                OWS.Identifier('json'),
                WPS.Data(
                    WPS.ComplexData(the_data,
                                    encoding='base64',
                                    mimeType='application/json')))))
    rv = get_inputs_from_xml(request_doc)
    assert rv['json'][0]['mimeType'] == 'application/json'
    json_data = json.loads(rv['json'][0]['data'].decode())
    assert json_data['plot']['Version'] == '0.1'
示例#17
0
def test_bbox_input():
    request_doc = WPS.Execute(
        OWS.Identifier('request'),
        WPS.DataInputs(
            WPS.Input(
                OWS.Identifier('bbox'),
                WPS.Data(
                    WPS.BoundingBoxData(OWS.LowerCorner('40 50'),
                                        OWS.UpperCorner('60 70'))))))
    rv = get_inputs_from_xml(request_doc)
    bbox = rv['bbox'][0]
    assert isinstance(bbox, BoundingBox)
    assert bbox.minx == '40'
    assert bbox.miny == '50'
    assert bbox.maxx == '60'
    assert bbox.maxy == '70'
示例#18
0
 def _describe_xml_allowedvalues(self):
     """Return AllowedValues node
     """
     doc = OWS.AllowedValues()
     for value in self.allowed_values:
         doc.append(value.describe_xml())
     return doc
示例#19
0
    def execute_xml(self):
        """Render Execute response XML node

        :return: node
        :rtype: ElementMaker
        """
        node = self._execute_xml_data()

        doc = WPS.Input(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )
        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))
        doc.append(node)

        return doc
示例#20
0
    def execute_xml(self):
        doc = WPS.Output(OWS.Identifier(self.identifier),
                         OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        data_doc = WPS.Data()

        literal_data_doc = WPS.LiteralData(str(self.data))
        literal_data_doc.attrib['dataType'] = OGCTYPE[self.data_type]
        if self.uom:
            literal_data_doc.attrib['uom'] = self.uom.execute_attribute()
        data_doc.append(literal_data_doc)

        doc.append(data_doc)

        return doc
示例#21
0
    def capabilities_xml(self):
        """ Return capabilities XML
        """
        doc = WPS.Process(OWS.Identifier(self.identifier),
                          OWS.Title(self.title))
        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))
        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))
        if self.profile:
            doc.append(OWS.Profile(self.profile))
        if self.version != 'None':
            doc.attrib[
                '{http://www.opengis.net/wps/1.0.0}processVersion'] = self.version
        else:
            doc.attrib[
                '{http://www.opengis.net/wps/1.0.0}processVersion'] = 'undefined'

        return doc
示例#22
0
    def describe_xml(self):
        """Generate DescribeProcess element
        """
        default_format_el = self.supported_formats[0].describe_xml()
        supported_format_elements = [
            f.describe_xml() for f in self.supported_formats
        ]

        doc = E.Output(OWS.Identifier(self.identifier), OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        doc.append(
            E.ComplexOutput(E.Default(default_format_el),
                            E.Supported(*supported_format_elements)))

        return doc
示例#23
0
    def execute_xml(self):
        """
        :return: execute response element
        """
        doc = WPS.Input(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        bbox_data_doc = OWS.BoundingBox()

        bbox_data_doc.attrib['crs'] = self.crs
        bbox_data_doc.attrib['dimensions'] = str(self.dimensions)

        bbox_data_doc.append(
            OWS.LowerCorner('{0[0]} {0[1]}'.format(self.data)))
        bbox_data_doc.append(
            OWS.UpperCorner('{0[2]} {0[3]}'.format(self.data)))

        doc.append(bbox_data_doc)

        return doc
示例#24
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)
示例#25
0
    def describe_xml(self):
        doc = E.Output(OWS.Identifier(self.identifier), OWS.Title(self.title))

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        bbox_data_doc = E.BoundingBoxOutput()
        doc.append(bbox_data_doc)

        default_doc = E.Default()
        default_doc.append(E.CRS(self.crss[0]))

        supported_doc = E.Supported()
        for c in self.crss:
            supported_doc.append(E.CRS(c))

        bbox_data_doc.append(default_doc)
        bbox_data_doc.append(supported_doc)

        return doc
示例#26
0
    def describe_xml(self):
        """Return DescribeProcess Output element
        """
        doc = E.Input(
            OWS.Identifier(self.identifier),
            OWS.Title(self.title)
        )

        doc.attrib['minOccurs'] = str(self.min_occurs)
        doc.attrib['maxOccurs'] = str(self.max_occurs)

        if self.abstract:
            doc.append(OWS.Abstract(self.abstract))

        for m in self.metadata:
            doc.append(OWS.Metadata(dict(m)))

        literal_data_doc = E.LiteralData()

        if self.data_type:
            data_type = OWS.DataType(self.data_type)
            data_type.attrib['{%s}reference' %
                             NAMESPACES['ows']] = OGCTYPE[self.data_type]
            literal_data_doc.append(data_type)

        if self.uoms:
            default_uom_element = self.uoms[0].describe_xml()
            supported_uom_elements = [u.describe_xml() for u in self.uoms]

            literal_data_doc.append(
                E.UOMs(
                    E.Default(default_uom_element),
                    E.Supported(*supported_uom_elements)
                )
            )

        doc.append(literal_data_doc)

        # TODO: refer to table 29 and 30
        if self.any_value:
            literal_data_doc.append(OWS.AnyValue())
        else:
            literal_data_doc.append(self._describe_xml_allowedvalues())

        if self.default is not None:
            literal_data_doc.append(E.DefaultValue(str(self.default)))

        return doc
示例#27
0
    def describe_xml(self):
        elem = OWS.UOM(self.uom)

        elem.attrib['{%s}reference' % NAMESPACES['ows']] = OGCUNIT[self.uom]

        return elem
示例#28
0
    def get_capabilities(self, wps_request, accesspolicy=None):
        """ Handle getcapbabilities request
        """
        process_elements = [
            p.capabilities_xml() for p in self.processes
            if accesspolicy.allow(p.identifier)
        ]

        doc = WPS.Capabilities()

        doc.attrib['service'] = 'WPS'
        doc.attrib['version'] = '1.0.0'
        doc.attrib['{http://www.w3.org/XML/1998/namespace}lang'] = 'en-US'
        doc.attrib['{http://www.w3.org/2001/XMLSchema-instance}schemaLocation'] = \
            'http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd'
        # TODO: check Table 7 in OGC 05-007r7
        doc.attrib['updateSequence'] = '1'

        metadata = confservice['metadata:main']

        # Service Identification
        service_ident_doc = OWS.ServiceIdentification(
            OWS.Title(metadata.get('identification_title')))

        if metadata.get('identification_abstract'):
            service_ident_doc.append(
                OWS.Abstract(metadata.get('identification_abstract')))

        if metadata.get('identification_keywords'):
            keywords_doc = OWS.Keywords()
            for k in metadata.get('identification_keywords').split(','):
                if k:
                    keywords_doc.append(OWS.Keyword(k))
            service_ident_doc.append(keywords_doc)

        if metadata.get('identification_keywords_type'):
            keywords_type = OWS.Type(
                metadata.get('identification_keywords_type'))
            keywords_type.attrib['codeSpace'] = 'ISOTC211/19115'
            keywords_doc.append(keywords_type)

        service_ident_doc.append(OWS.ServiceType('WPS'))

        # TODO: set proper version support
        service_ident_doc.append(OWS.ServiceTypeVersion('1.0.0'))

        service_ident_doc.append(OWS.Fees(metadata.get('identification_fees')))

        for con in metadata.get('identification_accessconstraints').split(','):
            service_ident_doc.append(OWS.AccessConstraints(con))

        if metadata.get('identification_profile'):
            service_ident_doc.append(
                OWS.Profile(metadata.get('identification_profile')))

        doc.append(service_ident_doc)

        # Service Provider
        service_prov_doc = OWS.ServiceProvider(
            OWS.ProviderName(metadata.get('provider_name')))

        if metadata.get('provider_url'):
            service_prov_doc.append(
                OWS.ProviderSite({
                    '{http://www.w3.org/1999/xlink}href':
                    metadata.get('provider_url')
                }))

        # Service Contact
        service_contact_doc = OWS.ServiceContact()

        # Add Contact information only if a name is set
        if metadata.get('contact_name'):
            service_contact_doc.append(
                OWS.IndividualName(metadata.get('contact_name')))
            if metadata.get('contact_position'):
                service_contact_doc.append(
                    OWS.PositionName(metadata.get('contact_position')))

            contact_info_doc = OWS.ContactInfo()

            phone_doc = OWS.Phone()
            if metadata.get('contact_phone'):
                phone_doc.append(OWS.Voice(metadata.get('contact_phone')))
        # Add Phone if not empty
            if len(phone_doc):
                contact_info_doc.append(phone_doc)

            address_doc = OWS.Address()
            if metadata.get('deliveryPoint'):
                address_doc.append(
                    OWS.DeliveryPoint(metadata.get('contact_address')))
            if metadata.get('city'):
                address_doc.append(OWS.City(metadata.get('contact_city')))
            if metadata.get('contact_stateorprovince'):
                address_doc.append(
                    OWS.AdministrativeArea(
                        metadata.get('contact_stateorprovince')))
            if metadata.get('contact_postalcode'):
                address_doc.append(
                    OWS.PostalCode(metadata.get('contact_postalcode')))
            if metadata.get('contact_country'):
                address_doc.append(OWS.Country(
                    metadata.get('contact_country')))
            if metadata.get('contact_email'):
                address_doc.append(
                    OWS.ElectronicMailAddress(metadata.get('contact_email')))
            # Add Address if not empty
            if len(address_doc):
                contact_info_doc.append(address_doc)

            if metadata.get('contact_url'):
                contact_info_doc.append(
                    OWS.OnlineResource({
                        '{http://www.w3.org/1999/xlink}href':
                        metadata.get('contact_url')
                    }))
            if metadata.get('contact_hours'):
                contact_info_doc.append(
                    OWS.HoursOfService(metadata.get('contact_hours')))
            if metadata.get('contact_instructions'):
                contact_info_doc.append(
                    OWS.ContactInstructions(
                        metadata.get('contact_instructions')))

            # Add Contact information if not empty
            if len(contact_info_doc):
                service_contact_doc.append(contact_info_doc)

            if metadata.get('contact_role'):
                service_contact_doc.append(
                    OWS.Role(metadata.get('contact_role')))

        # Add Service Contact only if ProviderName and PositionName are set
        if len(service_contact_doc):
            service_prov_doc.append(service_contact_doc)

        doc.append(service_prov_doc)

        server_href = {
            '{http://www.w3.org/1999/xlink}href':
            confservice.get('server',
                            'url').format(host_url=wps_request.host_url)
        }

        # Operations Metadata
        operations_metadata_doc = OWS.OperationsMetadata(
            OWS.Operation(OWS.DCP(
                OWS.HTTP(OWS.Get(server_href), OWS.Post(server_href))),
                          name="GetCapabilities"),
            OWS.Operation(OWS.DCP(
                OWS.HTTP(OWS.Get(server_href), OWS.Post(server_href))),
                          name="DescribeProcess"),
            OWS.Operation(OWS.DCP(
                OWS.HTTP(OWS.Get(server_href), OWS.Post(server_href))),
                          name="Execute"))
        doc.append(operations_metadata_doc)

        doc.append(WPS.ProcessOfferings(*process_elements))

        languages = confservice.get('server', 'language').split(',')
        languages_doc = WPS.Languages(WPS.Default(OWS.Language(languages[0])))
        lang_supported_doc = WPS.Supported()
        for l in languages:
            lang_supported_doc.append(OWS.Language(l))
        languages_doc.append(lang_supported_doc)

        doc.append(languages_doc)

        return doc
示例#29
0
 def test_post_with_no_inputs(self):
     request_doc = WPS.Execute(OWS.Identifier('ultimate_question'),
                               version='1.0.0')
     resp = self.client.post_xml(doc=request_doc)
     assert_response_success(resp)
     assert get_output(resp.xml) == {'outvalue': '42'}
示例#30
0
def test_empty():
    request_doc = WPS.Execute(OWS.Identifier('foo'))
    assert get_inputs_from_xml(request_doc) == {}