Projet

Général

Profil

0001-misc-limit-geocoding-to-bounding-box-46410.patch

Lauréline Guérin, 18 décembre 2020 10:50

Télécharger (3,19 ko)

Voir les différences:

Subject: [PATCH] misc: limit geocoding to bounding box (#46410)

 tests/test_api.py       | 16 ++++++++++++++++
 wcs/qommon/publisher.py |  5 +++++
 2 files changed, 21 insertions(+)
tests/test_api.py
3375 3375
        assert urlopen.call_args[0][0] == 'https://nominatim.entrouvert.org/search?format=json&q=test&accept-language=en'
3376 3376

  
3377 3377
        pub.site_options.add_section('options')
3378
        pub.site_options.set('options', 'map-bounds-top-left', '1.23;2.34')
3379
        pub.site_options.set('options', 'map-bounds-bottom-right', '2.34;3.45')
3380
        pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
3381
        resp = get_app(pub).get('/api/geocoding?q=test')
3382
        assert urlopen.call_args[0][0] == ('https://nominatim.entrouvert.org/search?viewbox=2.34,1.23,3.45,2.34&bounded=1&'
3383
                                           'format=json&q=test&accept-language=en')
3384

  
3378 3385
        pub.site_options.set('options', 'nominatim_key', 'KEY')
3386
        pub.site_options.set('options', 'map-bounds-top-left', '')
3387
        pub.site_options.set('options', 'map-bounds-bottom-right', '')
3379 3388
        pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
3380 3389
        resp = get_app(pub).get('/api/geocoding?q=test')
3381 3390
        assert urlopen.call_args[0][0] == 'https://nominatim.entrouvert.org/search?key=KEY&format=json&q=test&accept-language=en'
3382 3391

  
3392
        pub.site_options.set('options', 'map-bounds-top-left', '1.23;2.34')
3393
        pub.site_options.set('options', 'map-bounds-bottom-right', '2.34;3.45')
3394
        pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
3395
        resp = get_app(pub).get('/api/geocoding?q=test')
3396
        assert urlopen.call_args[0][0] == ('https://nominatim.entrouvert.org/search?key=KEY&viewbox=2.34,1.23,3.45,2.34&bounded=1&'
3397
                                           'format=json&q=test&accept-language=en')
3398

  
3383 3399
        pub.site_options.set('options', 'geocoding_service_url', 'http://reverse.example.net/?param=value')
3384 3400
        pub.site_options.write(open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w'))
3385 3401
        resp = get_app(pub).get('/api/geocoding?q=test')
wcs/qommon/publisher.py
789 789
        key = self.get_site_option('nominatim_key')
790 790
        if key:
791 791
            url += '?key=%s' % key
792
        if self.get_site_option('map-bounds-top-left'):
793
            url += '&' if '?' in url else '?'
794
            top, left = self.get_site_option('map-bounds-top-left').split(';')
795
            bottom, right = self.get_site_option('map-bounds-bottom-right').split(';')
796
            url += 'viewbox=%s,%s,%s,%s&bounded=1' % (left, top, right, bottom)
792 797
        return url
793 798

  
794 799
    def get_working_day_calendar(self):
795
-