Example #1
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'
Example #2
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'
Example #3
0
    def _execute_xml_data(self):
        """Return Data node
        """
        doc = WPS.Data()

        complex_doc = WPS.ComplexData()

        if self.data is not None:
            try:
                data_doc = etree.parse(self.file)
                complex_doc.append(data_doc.getroot())
            except:
                if isinstance(self.data, str):
                    complex_doc.text = self.data
                else:
                    complex_doc.text = etree.CDATA(self.base64)

        if self.data_format:
            if self.data_format.mime_type:
                complex_doc.attrib['mimeType'] = self.data_format.mime_type
            if self.data_format.encoding:
                complex_doc.attrib['encoding'] = self.data_format.encoding
            if self.data_format.schema:
                complex_doc.attrib['schema'] = self.data_format.schema
        doc.append(complex_doc)
        return doc
Example #4
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!"}
Example #5
0
    def _execute_xml_data(self):
        """Return Data node
        """
        doc = WPS.Data()
        literal_doc = WPS.LiteralData(str(self.data))

        if self.data_type:
            literal_doc.attrib['dataType'] = self.data_type
        if self.uom:
            literal_doc.attrib['uom'] = self.uom
        doc.append(literal_doc)
        return doc
Example #6
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'
Example #7
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'
Example #8
0
    def _execute_xml_data(self):
        """Return Data node
        """
        doc = WPS.Data()
        complex_doc = WPS.ComplexData(self.data)

        if self.data_format:
            if self.data_format.mime_type:
                complex_doc.attrib['mimeType'] = self.data_format.mime_type
            if self.data_format.encoding:
                complex_doc.attrib['encoding'] = self.data_format.encoding
            if self.data_format.schema:
                complex_doc.attrib['schema'] = self.data_format.schema
        doc.append(complex_doc)
        return doc
Example #9
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'
Example #10
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'
Example #11
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
Example #12
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)