예제 #1
0
 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'}
예제 #2
0
    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/Output')
        self.assertEqual('outbbox',
                         xpath_ns(output, './ows:Identifier')[0].text)
        self.assertEqual(
            '15 50',
            xpath_ns(output, './ows:BoundingBox/ows:LowerCorner')[0].text)
예제 #3
0
 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)
예제 #4
0
 def test_two_strings(self):
     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)
     self.assertEqual(rv['name1'][0]['data'], 'foo')
     self.assertEqual(rv['name2'][0]['data'], 'bar')
예제 #5
0
 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!"}
예제 #6
0
 def test_one_string(self):
     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)
     self.assertTrue('name' in rv)
     self.assertEqual(len(rv['name']), 2)
     self.assertEqual(rv['name'][0]['data'], 'foo')
     self.assertEqual(rv['name'][1]['data'], 'bar')
예제 #7
0
 def test_one_string(self):
     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'
예제 #8
0
 def test_complex_input(self):
     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)
     self.assertEqual(rv['name'][0]['mimeType'], 'text/foobar')
     rv_doc = lxml.etree.parse(StringIO(rv['name'][0]['data'])).getroot()
     self.assertEqual(rv_doc.tag, 'TheData')
     self.assertEqual(rv_doc.text, 'hello world')
예제 #9
0
    def test_complex_input_raw_value(self):
        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)
        self.assertEqual(rv['json'][0]['mimeType'], 'application/json')
        json_data = json.loads(rv['json'][0]['data'])
        self.assertEqual(json_data['plot']['Version'], '0.1')
예제 #10
0
 def test_reference_post_input(self):
     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)
     self.assertEqual(rv['name'][0]['href'], 'http://foo/bar/service')
     self.assertEqual(rv['name'][0]['method'], 'POST')
     self.assertEqual(rv['name'][0]['body'], 'request body')
예제 #11
0
    def test_complex_input_base64_value(self):
        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)
        self.assertEqual(rv['json'][0]['mimeType'], 'application/json')
        json_data = json.loads(rv['json'][0]['data'].decode())
        self.assertEqual(json_data['plot']['Version'], '0.1')
예제 #12
0
 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)
예제 #13
0
    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)
예제 #14
0
 def test_bbox_input(self):
     if not PY2:
         self.skipTest('OWSlib not python 3 compatible')
     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'
예제 #15
0
 def test_empty(self):
     request_doc = WPS.Execute(OWS.Identifier('foo'))
     assert get_inputs_from_xml(request_doc) == {}
예제 #16
0
    def _post_request_parser(self, tagname):
        """Factory function returing propper parsing function
        """

        wpsrequest = self

        def parse_post_getcapabilities(doc):
            """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)

        def parse_post_describeprocess(doc):
            """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')
            ]

        def parse_post_execute(doc):
            """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')
                wpsrequest.status = response_document[0].attrib.get(
                    'status', 'false')

        if tagname == WPS.GetCapabilities().tag:
            self.operation = 'getcapabilities'
            return parse_post_getcapabilities
        elif tagname == WPS.DescribeProcess().tag:
            self.operation = 'describeprocess'
            return parse_post_describeprocess
        elif tagname == WPS.Execute().tag:
            self.operation = 'execute'
            return parse_post_execute
        else:
            raise InvalidParameterValue('Unknown request %r' % tagname,
                                        'request')