Project

General

Profile

0001-opengis-adapt-typename-parameter-to-server-version-3.patch

Nicolas Roche, 09 January 2020 05:53 PM

Download (4.36 KB)

View differences:

Subject: [PATCH] opengis: adapt typename parameter to server version (#38851)

 passerelle/apps/opengis/models.py | 12 ++++++++++--
 tests/test_opengis.py             | 29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)
passerelle/apps/opengis/models.py
93 93
    def get_wfs_service_version(self, renew=False):
94 94
        return self.get_service_version('wfs', self.wfs_service_url, renew=renew)
95 95

  
96
    def get_typename_label(self):
97
        version_str = self.get_wfs_service_version()
98
        version_tuple = tuple(int(x) for x in version_str.split('.'))
99
        if version_tuple <= (1, 1, 0):
100
            return 'TYPENAME'
101
        else:
102
            return 'TYPENAMES'
103

  
96 104
    def check_status(self):
97 105
        if self.wms_service_url:
98 106
            response = self.requests.get(
......
144 152
            'VERSION': self.get_wfs_service_version(),
145 153
            'SERVICE': 'WFS',
146 154
            'REQUEST': 'GetFeature',
147
            'TYPENAMES': type_names,
155
            self.get_typename_label(): type_names,
148 156
            'PROPERTYNAME': property_name,
149 157
            'OUTPUTFORMAT': 'json',
150 158
        }
......
297 305
            'VERSION': self.get_wfs_service_version(),
298 306
            'SERVICE': 'WFS',
299 307
            'REQUEST': 'GetFeature',
300
            'TYPENAMES': self.query_layer,
308
            self.get_typename_label(): self.query_layer,
301 309
            'OUTPUTFORMAT': 'json',
302 310
            'CQL_FILTER': cql_filter
303 311
        }
tests/test_opengis.py
41 41
    </ows:ServiceIdentification>
42 42
</wfs:WFS_Capabilities>'''
43 43

  
44
FAKE_SERVICE_CAPABILITIES_V1_0_0 = '''<?xml version="1.0" encoding="UTF-8"?>
45
<wfs:WFS_Capabilities version="1.0.0"
46
       xmlns:wfs="http://www.opengis.net/wfs/2.0"
47
       xmlns:ows="http://www.opengis.net/ows/1.1">
48
    <ows:ServiceIdentification>
49
        <ows:Title/><ows:Abstract/>
50
        <ows:ServiceType>WFS</ows:ServiceType><ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion><ows:Fees/>
51
        <ows:AccessConstraints/>
52
    </ows:ServiceIdentification>
53
</wfs:WFS_Capabilities>'''
54

  
44 55
FAKE_FEATURES_JSON = '''
45 56
{
46 57
    "features": [
......
227 238
        return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES)
228 239
    return utils.FakedResponse(status_code=200, content=FAKE_FEATURES_JSON)
229 240

  
241
def geoserver_responses_v1_0_0(url, **kwargs):
242
    if kwargs['params'].get('request') == 'GetCapabilities':
243
        return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES_V1_0_0)
244
    return utils.FakedResponse(status_code=200, content=FAKE_FEATURES_JSON)
230 245

  
231 246
def geoserver_responses_errors(url, **kwargs):
232 247
    if kwargs['params'].get('request') == 'GetCapabilities':
......
395 410
    assert '<ows:' in result['data']['content']
396 411

  
397 412

  
413
@pytest.mark.parametrize("server_responses, version, typename_label", [
414
    (geoserver_responses_v1_0_0, '1.0.0', 'TYPENAME'),
415
    (geoserver_responses, '2.0.0', 'TYPENAMES')])
416
@mock.patch('passerelle.utils.Request.get')
417
def test_typename_parameter_upgrade(mocked_get, server_responses, version, typename_label, app, connector):
418
    endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
419
    assert endpoint == '/opengis/test/features'
420
    mocked_get.side_effect = server_responses
421
    resp = app.get(endpoint, params={'type_names': '...', 'property_name': '...'})
422
    assert mocked_get.call_args[1]['params']['REQUEST'] == 'GetFeature'
423
    assert mocked_get.call_args[1]['params']['VERSION'] == version
424
    assert typename_label in mocked_get.call_args[1]['params'].keys()
425

  
426

  
398 427
@mock.patch('passerelle.utils.Request.get')
399 428
def test_reverse_geocoding(mocked_get, app, connector):
400 429
    connector.search_radius = 45
401
-