Projet

Général

Profil

0001-okina-add-lat-and-lon-on-results-when-possible-43292.patch

Thomas Noël, 26 mai 2020 12:34

Télécharger (4,48 ko)

Voir les différences:

Subject: [PATCH] okina: add 'lat' and 'lon' on results when possible (#43292)

 passerelle/apps/okina/models.py |  9 +++++++--
 tests/test_okina.py             | 10 ++++++++--
 2 files changed, 15 insertions(+), 4 deletions(-)
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['lat'] = city.get('latitude')
89
            city['lon'] = city.get('longitude')
89 90
            cities.append(city)
90 91
        cities.sort(key=lambda x: x['text'])
91 92
        return {'data': cities}
......
105 106
            del institution['schoolEstablishment']
106 107
            institution['id'] = '%s' % institution['id']
107 108
            institution['text'] = '%(uaiLabel)s' % institution
109
            institution['lat'] = institution.get('customLocationY') or institution.get('locationY')
110
            institution['lon'] = institution.get('customLocationX') or institution.get('locationX')
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['lat'] = stop.get('latitude')
152
            stop['lon'] = stop.get('longitude')
148 153
        return {'data': stops}
149 154

  
150 155
    @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]['lat'] is None
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]['lat'] is None
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]['lat'] == '46.791332586468016'
1707
            assert resp.json['data'][0]['lon'] == '1.6926355997775921'
1704 1708

  
1705 1709
            resp = app.get(endpoint, params={'insee': '36005'}, status=200)
1706 1710
            assert requests_get.call_args[0][0] == 'https://okina.example.net/b2b/institutions?inseeCode=36005'
......
1744 1748
        assert len(resp.json['data']) == 2
1745 1749
        assert resp.json['data'][0]['id'] == '3312'
1746 1750
        assert resp.json['data'][0]['text'] == 'Le Grand Verger'
1751
        assert resp.json['data'][0]['lat'] == 46.8444186
1752
        assert resp.json['data'][0]['lon'] == 1.708197
1747 1753
        # french decimals
1748 1754
        resp = app.get(endpoint + '?lat=46,8&lon=1,71&address=nowhere&mode=FAR_ALL&institution=280',
1749 1755
                       status=200)
1750
-