0001-base-adresse-pass-lat-lon-when-geocoding-33098.patch
passerelle/apps/base_adresse/models.py | ||
---|---|---|
34 | 34 |
verbose_name = _('Base Adresse Web Service') |
35 | 35 | |
36 | 36 |
@endpoint(pattern='(?P<q>.+)?$') |
37 |
def search(self, request, q, zipcode='', **kwargs): |
|
37 |
def search(self, request, q, zipcode='', lat=None, lon=None, **kwargs):
|
|
38 | 38 |
if kwargs.get('format', 'json') != 'json': |
39 | 39 |
raise NotImplementedError() |
40 | 40 | |
... | ... | |
46 | 46 |
query_args = {'q': q, 'limit': 1} |
47 | 47 |
if zipcode: |
48 | 48 |
query_args['postcode'] = zipcode |
49 |
if lat and lon: |
|
50 |
query_args['lat'] = lat |
|
51 |
query_args['lon'] = lon |
|
49 | 52 |
query = urlencode(query_args) |
50 | 53 |
url = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) |
51 | 54 |
tests/test_base_adresse.py | ||
---|---|---|
110 | 110 |
assert 'display_name' in resp.json[0] |
111 | 111 | |
112 | 112 | |
113 |
@mock.patch('passerelle.utils.Request.get') |
|
114 |
def test_base_adresse_search_qs_lat_lon(mocked_get, app, base_adresse): |
|
115 |
resp = app.get('/base-adresse/%s/search?q=plop&lat=0&lon=1' % base_adresse.slug) |
|
116 |
assert 'lat=0' in mocked_get.call_args[0][0] |
|
117 |
assert 'lon=1' in mocked_get.call_args[0][0] |
|
118 | ||
119 | ||
113 | 120 |
def test_base_adresse_search_qs_empty(app, base_adresse, mock_api_adresse_data_gouv_fr_search): |
114 | 121 |
resp = app.get('/base-adresse/%s/search?q=' % base_adresse.slug) |
115 | 122 |
assert len(resp.json) == 0 |
116 |
- |