0001-okina-add-latlon-on-results-when-possible-43292.patch
passerelle/apps/okina/models.py | ||
---|---|---|
80 | 80 |
cities = [] |
81 | 81 |
for city in okina_cities: |
82 | 82 |
if 'name' in city: |
83 |
city['id'] = '%s' % city['id'] |
|
84 | 83 |
city['text'] = '%(name)s (%(zipCode)s)' % city |
85 | 84 |
else: # old API |
86 | 85 |
city = city['cityObject'] |
87 |
city['id'] = '%s' % city['id'] |
|
88 | 86 |
city['text'] = '%(nameCity)s (%(zipCode)s)' % city |
87 |
city['id'] = '%s' % city['id'] |
|
88 |
city['latlon'] = '%s;%s' % (city.get('latitude') or '0.00', city.get('longitude') or '0.00') |
|
89 | 89 |
cities.append(city) |
90 | 90 |
cities.sort(key=lambda x: x['text']) |
91 | 91 |
return {'data': cities} |
... | ... | |
105 | 105 |
del institution['schoolEstablishment'] |
106 | 106 |
institution['id'] = '%s' % institution['id'] |
107 | 107 |
institution['text'] = '%(uaiLabel)s' % institution |
108 |
latitude = institution.get('customLocationY') or institution.get('locationY') or '0.00' |
|
109 |
longitude = institution.get('customLocationX') or institution.get('locationX') or '0.00' |
|
110 |
institution['latlon'] = '%s;%s' % (latitude, longitude) |
|
108 | 111 |
institutions.append(institution) |
109 | 112 |
institutions.sort(key=lambda x: x['text']) |
110 | 113 |
return institutions |
... | ... | |
145 | 148 |
for stop in stops: |
146 | 149 |
stop['id'] = '%s' % stop['id'] |
147 | 150 |
stop['text'] = stop['commercial_name'] |
151 |
stop['latlon'] = '%s;%s' % (stop.get('latitude') or '0.00', stop.get('longitude') or '0.00') |
|
148 | 152 |
return {'data': stops} |
149 | 153 | |
150 | 154 |
@endpoint(name='stop-areas', |
tests/test_okina.py | ||
---|---|---|
99 | 99 |
"address" : "4 ALLÉE DES LAURIERS", |
100 | 100 |
"zipCode" : "36007", |
101 | 101 |
"cityName" : "CHATEAUROUX CEDEX", |
102 |
"locationX" : "1.692635599708531",
|
|
103 |
"locationY" : "46.791332546947025",
|
|
102 |
"locationX" : "1.6926355997775921",
|
|
103 |
"locationY" : "46.791332586468016",
|
|
104 | 104 |
"nature" : "340", |
105 | 105 |
"natureTitle" : "Collège" |
106 | 106 |
}, |
... | ... | |
1663 | 1663 |
assert resp.json['data'][0]['id'] == '83355' |
1664 | 1664 |
assert resp.json['data'][0]['insee'] == '36005' |
1665 | 1665 |
assert resp.json['data'][0]['text'] == 'ARDENTES (36120)' |
1666 |
assert resp.json['data'][0]['latlon'] == '0.00;0.00' |
|
1666 | 1667 | |
1667 | 1668 |
requests_get.return_value = utils.FakedResponse(content=CITIES_NEW, |
1668 | 1669 |
status_code=200) |
... | ... | |
1674 | 1675 |
assert resp.json['data'][0]['id'] == '83355' |
1675 | 1676 |
assert resp.json['data'][0]['insee'] == '36005' |
1676 | 1677 |
assert resp.json['data'][0]['text'] == 'ARDENTES (36120)' |
1678 |
assert resp.json['data'][0]['latlon'] == '0.00;0.00' |
|
1677 | 1679 | |
1678 | 1680 |
def test_okina_classes(app, okina): |
1679 | 1681 |
endpoint = utils.generic_endpoint_url('okina', 'classes', slug=okina.slug) |
... | ... | |
1701 | 1703 |
assert len(resp.json['data']) == 2 |
1702 | 1704 |
assert resp.json['data'][0]['id'] == '277' |
1703 | 1705 |
assert resp.json['data'][0]['text'] == u'Collège Touvent' |
1706 |
assert resp.json['data'][0]['latlon'] == '46.791332586468016;1.6926355997775921' |
|
1704 | 1707 | |
1705 | 1708 |
resp = app.get(endpoint, params={'insee': '36005'}, status=200) |
1706 | 1709 |
assert requests_get.call_args[0][0] == 'https://okina.example.net/b2b/institutions?inseeCode=36005' |
... | ... | |
1744 | 1747 |
assert len(resp.json['data']) == 2 |
1745 | 1748 |
assert resp.json['data'][0]['id'] == '3312' |
1746 | 1749 |
assert resp.json['data'][0]['text'] == 'Le Grand Verger' |
1750 |
assert resp.json['data'][0]['latlon'] == '46.8444186;1.708197' |
|
1747 | 1751 |
# french decimals |
1748 | 1752 |
resp = app.get(endpoint + '?lat=46,8&lon=1,71&address=nowhere&mode=FAR_ALL&institution=280', |
1749 | 1753 |
status=200) |
1750 |
- |