6 |
6 |
import utils
|
7 |
7 |
|
8 |
8 |
FAKE_FEATURE_INFO = '''<?xml version="1.0" encoding="UTF-8"?>
|
9 |
|
<msGMLOutput xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
9 |
<msGMLOutput
|
|
10 |
xmlns:gml="http://www.opengis.net/gml"
|
|
11 |
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
12 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
10 |
13 |
<cad_cadastre.cadparcelle_layer>
|
11 |
14 |
<gml:name>Parcelle cadastrale (Plan cadastral informatise du Grand Lyon)</gml:name>
|
12 |
15 |
<cad_cadastre.cadparcelle_feature>
|
... | ... | |
28 |
31 |
</msGMLOutput>'''
|
29 |
32 |
|
30 |
33 |
FAKE_SERVICE_CAPABILITIES = '''<?xml version="1.0" encoding="UTF-8"?>
|
31 |
|
<wfs:WFS_Capabilities version="2.0.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:ows="http://www.opengis.net/ows/1.1">
|
|
34 |
<wfs:WFS_Capabilities version="2.0.0"
|
|
35 |
xmlns:wfs="http://www.opengis.net/wfs/2.0"
|
|
36 |
xmlns:ows="http://www.opengis.net/ows/1.1">
|
32 |
37 |
<ows:ServiceIdentification>
|
33 |
38 |
<ows:Title/><ows:Abstract/>
|
34 |
39 |
<ows:ServiceType>WFS</ows:ServiceType><ows:ServiceTypeVersion>2.0.0</ows:ServiceTypeVersion><ows:Fees/>
|
... | ... | |
99 |
104 |
"type": "FeatureCollection"
|
100 |
105 |
}'''
|
101 |
106 |
|
102 |
|
FAKE_ERROR = u'<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 https://sigmetropole.lametro.fr/geoserver/schemas/ows/1.1.0/owsAll.xsd">\n <ows:Exception exceptionCode="NoApplicableCode">\n <ows:ExceptionText>Could not parse CQL filter list.\nEncountered &quot;BIS&quot; at line 1, column 129.\nWas expecting one of:\n &lt;EOF&gt; \n &quot;and&quot; ...\n &quot;or&quot; ...\n &quot;;&quot; ...\n &quot;/&quot; ...\n &quot;*&quot; ...\n &quot;+&quot; ...\n &quot;-&quot; ...\n Parsing : strEqualsIgnoreCase(nom_commune, &apos;Grenoble&apos;) = true AND strEqualsIgnoreCase(nom_voie, &apos;rue albert recoura&apos;) = true AND numero=8 BIS.</ows:ExceptionText>\n </ows:Exception>\n</ows:ExceptionReport>\n'
|
|
107 |
FAKE_ERROR = u'''<ows:ExceptionReport
|
|
108 |
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
|
109 |
xmlns:ows="http://www.opengis.net/ows/1.1"
|
|
110 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
111 |
version="2.0.0"
|
|
112 |
xsi:schemaLocation="http://www.opengis.net/ows/1.1 https://sigmetropole.lametro.fr/geoserver/schemas/ows/1.1.0/owsAll.xsd">
|
|
113 |
<ows:Exception exceptionCode="NoApplicableCode">
|
|
114 |
<ows:ExceptionText>Could not parse CQL filter list.
|
|
115 |
Encountered &quot;BIS&quot; at line 1, column 129.
|
|
116 |
Was expecting one of:
|
|
117 |
&lt;EOF&gt;
|
|
118 |
&quot;and&quot; ...
|
|
119 |
&quot;or&quot; ...
|
|
120 |
&quot;;&quot; ...
|
|
121 |
&quot;/&quot; ...
|
|
122 |
&quot;*&quot; ...
|
|
123 |
&quot;+&quot; ...
|
|
124 |
&quot;-&quot; ...
|
|
125 |
Parsing : strEqualsIgnoreCase(nom_commune, &apos;Grenoble&apos;) = true AND strEqualsIgnoreCase(nom_voie, &apos;rue albert recoura&apos;) = true AND numero=8 BIS.</ows:ExceptionText>
|
|
126 |
</ows:Exception>
|
|
127 |
</ows:ExceptionReport>
|
|
128 |
'''
|
103 |
129 |
|
104 |
130 |
FAKE_GEOLOCATED_FEATURE = '''{
|
105 |
131 |
"crs": {
|
... | ... | |
195 |
221 |
wms_service_url='http://example.net/wms',
|
196 |
222 |
wfs_service_url='http://example.net/wfs'))
|
197 |
223 |
|
|
224 |
|
198 |
225 |
def geoserver_responses(url, **kwargs):
|
199 |
226 |
if kwargs['params'].get('request') == 'GetCapabilities':
|
200 |
227 |
return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES)
|
201 |
228 |
return utils.FakedResponse(status_code=200, content=FAKE_FEATURES_JSON)
|
202 |
229 |
|
|
230 |
|
203 |
231 |
def geoserver_responses_errors(url, **kwargs):
|
204 |
232 |
if kwargs['params'].get('request') == 'GetCapabilities':
|
205 |
233 |
return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES)
|
206 |
234 |
return utils.FakedResponse(status_code=200, content=FAKE_ERROR)
|
207 |
235 |
|
|
236 |
|
208 |
237 |
def geoserver_responses_errors_unparsable(url, **kwargs):
|
209 |
238 |
if kwargs['params'].get('request') == 'GetCapabilities':
|
210 |
239 |
return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES)
|
211 |
240 |
return utils.FakedResponse(status_code=200, content=FAKE_ERROR[:10])
|
212 |
241 |
|
|
242 |
|
213 |
243 |
@mock.patch('passerelle.utils.Request.get')
|
214 |
244 |
def test_feature_info(mocked_get, app, connector):
|
215 |
245 |
endpoint = utils.generic_endpoint_url('opengis', 'feature_info', slug=connector.slug)
|
... | ... | |
218 |
248 |
resp = app.get(endpoint, params={'lat': '45.796890', 'lon': '4.784140'})
|
219 |
249 |
assert mocked_get.call_args[1]['params']['BBOX'] == '5747860.22776,532568.028684,5748179.56467,532790.667665'
|
220 |
250 |
assert mocked_get.call_args[1]['params']['CRS'] == 'EPSG:3857'
|
221 |
|
assert resp.json['data']['cad_cadastrecadparcelle_layer']['cad_cadastrecadparcelle_feature']['natureproprietaire'] == 'Particulier'
|
|
251 |
assert (resp.json['data']
|
|
252 |
['cad_cadastrecadparcelle_layer']
|
|
253 |
['cad_cadastrecadparcelle_feature']
|
|
254 |
['natureproprietaire']
|
|
255 |
== 'Particulier')
|
222 |
256 |
connector.projection = 'EPSG:4326'
|
223 |
257 |
connector.save()
|
224 |
258 |
resp = app.get(endpoint, params={'lat': '45.796890', 'lon': '4.784140'})
|
225 |
259 |
assert mocked_get.call_args[1]['params']['BBOX'] == '45.796890,4.784140,45.79889,4.78614'
|
226 |
260 |
assert mocked_get.call_args[1]['params']['CRS'] == 'EPSG:4326'
|
227 |
261 |
|
|
262 |
|
228 |
263 |
@mock.patch('passerelle.utils.Request.get')
|
229 |
264 |
def test_tile(mocked_get, app, connector):
|
230 |
265 |
endpoint = utils.generic_endpoint_url('opengis', 'tile', slug=connector.slug)
|
... | ... | |
249 |
284 |
assert endpoint == '/opengis/test/features'
|
250 |
285 |
mocked_get.side_effect = geoserver_responses
|
251 |
286 |
resp = app.get(endpoint, params={'type_names': 'ref_metro_limites_communales', 'property_name': 'nom'})
|
252 |
|
print resp.content
|
253 |
|
assert resp.json['data'] == None
|
|
287 |
assert resp.json['data'] is None
|
254 |
288 |
assert resp.json['err'] == 1
|
255 |
289 |
assert resp.json['err_desc'] == 'no wfs URL declared'
|
256 |
290 |
|
|
291 |
|
257 |
292 |
@mock.patch('passerelle.utils.Request.get')
|
258 |
293 |
def test_get_feature(mocked_get, app, connector):
|
259 |
294 |
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
... | ... | |
270 |
305 |
for item in resp.json['data']:
|
271 |
306 |
assert 'text' in item
|
272 |
307 |
|
|
308 |
|
273 |
309 |
@mock.patch('passerelle.utils.Request.get')
|
274 |
310 |
def test_get_filtered_feature(mocked_get, app, connector):
|
275 |
311 |
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
276 |
312 |
mocked_get.side_effect = geoserver_responses
|
277 |
|
resp = app.get(endpoint, params={'type_names': 'ref_metro_limites_communales',
|
278 |
|
'property_name': 'nom', 'cql_filter': 'nom=\'Fontaine\''})
|
|
313 |
app.get(endpoint,
|
|
314 |
params={
|
|
315 |
'type_names': 'ref_metro_limites_communales',
|
|
316 |
'property_name': 'nom',
|
|
317 |
'cql_filter': 'nom=\'Fontaine\''
|
|
318 |
})
|
279 |
319 |
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'nom=\'Fontaine\''
|
280 |
320 |
|
|
321 |
|
281 |
322 |
@mock.patch('passerelle.utils.Request.get')
|
282 |
323 |
def test_get_filtered_by_property_feature(mocked_get, app, connector):
|
283 |
324 |
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
... | ... | |
285 |
326 |
params = {'type_names': 'ref_metro_limites_communales',
|
286 |
327 |
'property_name': 'nom', 'cql_filter': 'nom=\'Fontaine\'',
|
287 |
328 |
'filter_property_name': 'nom'}
|
288 |
|
resp = app.get(endpoint, params=params)
|
|
329 |
app.get(endpoint, params=params)
|
289 |
330 |
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'nom=\'Fontaine\''
|
290 |
331 |
params['q'] = 'bens'
|
291 |
|
resp = app.get(endpoint, params=params)
|
|
332 |
app.get(endpoint, params=params)
|
292 |
333 |
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'nom=\'Fontaine\' AND nom LIKE \'%bens%\''
|
293 |
334 |
params['case-insensitive'] = True
|
294 |
|
resp = app.get(endpoint, params=params)
|
|
335 |
app.get(endpoint, params=params)
|
295 |
336 |
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'nom=\'Fontaine\' AND nom ILIKE \'%bens%\''
|
296 |
337 |
params.pop('cql_filter')
|
297 |
|
resp = app.get(endpoint, params=params)
|
|
338 |
app.get(endpoint, params=params)
|
298 |
339 |
assert 'CQL_FILTER' not in mocked_get.call_args[1]['params']
|
299 |
340 |
|
|
341 |
|
300 |
342 |
@mock.patch('passerelle.utils.Request.get')
|
301 |
343 |
def test_get_feature_error(mocked_get, app, connector):
|
302 |
344 |
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
... | ... | |
317 |
359 |
assert result['err_desc'] == 'OpenGIS Error: NoApplicableCode'
|
318 |
360 |
assert 'Could not parse' in result['data']['text']
|
319 |
361 |
|
|
362 |
|
320 |
363 |
@mock.patch('passerelle.utils.Request.get')
|
321 |
|
def test_get_feature_error(mocked_get, app, connector):
|
|
364 |
def test_get_feature_error2(mocked_get, app, connector):
|
322 |
365 |
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
323 |
366 |
assert endpoint == '/opengis/test/features'
|
324 |
367 |
mocked_get.side_effect = geoserver_responses_errors_unparsable
|
... | ... | |
337 |
380 |
assert result['err_desc'] == 'OpenGIS Error: unparsable error'
|
338 |
381 |
assert '<ows:' in result['data']['content']
|
339 |
382 |
|
|
383 |
|
340 |
384 |
@mock.patch('passerelle.utils.Request.get')
|
341 |
385 |
def test_reverse_geocoding(mocked_get, app, connector):
|
342 |
386 |
connector.search_radius = 45
|
... | ... | |
345 |
389 |
endpoint = utils.generic_endpoint_url('opengis', 'reverse', slug=connector.slug)
|
346 |
390 |
assert endpoint == '/opengis/test/reverse'
|
347 |
391 |
mocked_get.return_value = utils.FakedResponse(content=FAKE_GEOLOCATED_FEATURE, status_code=200)
|
348 |
|
resp = app.get(endpoint, params={'lat':'45.1893469606986', 'lon': '5.72462060798'})
|
349 |
|
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'DWITHIN(the_geom,Point(1914061.48604 4224640.45779),45,meters)'
|
|
392 |
resp = app.get(endpoint,
|
|
393 |
params={
|
|
394 |
'lat': '45.1893469606986',
|
|
395 |
'lon': '5.72462060798'
|
|
396 |
})
|
|
397 |
assert (mocked_get.call_args[1]['params']['CQL_FILTER']
|
|
398 |
== 'DWITHIN(the_geom,Point(1914061.48604 4224640.45779),45,meters)')
|
350 |
399 |
assert resp.json['lon'] == '5.72407744145'
|
351 |
400 |
assert resp.json['lat'] == '45.1893972656'
|
352 |
401 |
assert resp.json['address']['house_number'] == '4'
|
... | ... | |
358 |
407 |
connector.search_radius = 10
|
359 |
408 |
connector.save()
|
360 |
409 |
mocked_get.return_value = utils.FakedResponse(content='{"features": []}', status_code=200)
|
361 |
|
resp = app.get(endpoint, params={'lat':'45.183784', 'lon': '5.714885'})
|
|
410 |
resp = app.get(
|
|
411 |
endpoint,
|
|
412 |
params={
|
|
413 |
'lat': '45.183784',
|
|
414 |
'lon': '5.714885'
|
|
415 |
})
|
362 |
416 |
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'DWITHIN(the_geom,Point(5.714885 45.183784),10,meters)'
|
363 |
417 |
assert resp.json['err'] == 1
|
364 |
418 |
assert resp.json['err_desc'] == 'Unable to geocode'
|
365 |
419 |
|
366 |
420 |
mocked_get.return_value = utils.FakedResponse(status_code=404, content='{}', ok=False)
|
367 |
|
resp = app.get(endpoint, params={'lat':'45.183784', 'lon': '5.714885'})
|
|
421 |
resp = app.get(endpoint,
|
|
422 |
params={
|
|
423 |
'lat': '45.183784',
|
|
424 |
'lon': '5.714885'
|
|
425 |
})
|
368 |
426 |
assert resp.json['err'] == 1
|
369 |
427 |
assert resp.json['err_desc'] == 'Webservice returned status code 404'
|
370 |
|
-
|