1from geopy.geocoders import MapQuest
2from geopy.point import Point
3from test.geocoders.util import BaseTestGeocoder, env
4
5
6class TestMapQuest(BaseTestGeocoder):
7    @classmethod
8    def make_geocoder(cls, **kwargs):
9        return MapQuest(api_key=env['MAPQUEST_KEY'], timeout=3, **kwargs)
10
11    async def test_geocode(self):
12        await self.geocode_run(
13            {"query": "435 north michigan ave, chicago il 60611 usa"},
14            {"latitude": 41.89036, "longitude": -87.624043},
15        )
16
17    async def test_unicode_name(self):
18        await self.geocode_run(
19            {"query": "\u6545\u5bab"},
20            {"latitude": 25.0968, "longitude": 121.54714, "delta": 5.0},
21        )
22
23    async def test_reverse(self):
24        new_york_point = Point(40.75376406311989, -73.98489005863667)
25        location = await self.reverse_run(
26            {"query": new_york_point},
27            {"latitude": 40.7537640, "longitude": -73.98489, "delta": 1},
28        )
29        assert "New York" in location.address
30
31    async def test_zero_results(self):
32        await self.geocode_run(
33            {"query": ''},
34            {},
35            expect_failure=True,
36        )
37
38    async def test_geocode_bbox(self):
39        await self.geocode_run(
40            {
41                "query": "435 north michigan ave, chicago il 60611 usa",
42                "bounds": [Point(35.227672, -103.271484),
43                           Point(48.603858, -74.399414)]
44            },
45            {"latitude": 41.890, "longitude": -87.624},
46        )
47
48    async def test_geocode_raw(self):
49        result = await self.geocode_run(
50            {"query": "New York"},
51            {"latitude": 40.713054, "longitude": -74.007228, "delta": 1},
52        )
53        assert result.raw['adminArea1'] == "US"
54
55    async def test_geocode_limit(self):
56        list_result = await self.geocode_run(
57            {"query": "maple street", "exactly_one": False, "limit": 2},
58            {},
59        )
60        assert len(list_result) == 2
61
62        list_result = await self.geocode_run(
63            {"query": "maple street", "exactly_one": False, "limit": 4},
64            {},
65        )
66        assert len(list_result) == 4
67