1from geopy.geocoders import Photon
2from geopy.point import Point
3from test.geocoders.util import BaseTestGeocoder
4
5
6class TestPhoton(BaseTestGeocoder):
7    known_country_de = "Frankreich"
8    known_country_fr = "France"
9
10    @classmethod
11    def make_geocoder(cls, **kwargs):
12        return Photon(**kwargs)
13
14    async def test_user_agent_custom(self):
15        geocoder = Photon(
16            user_agent='my_user_agent/1.0'
17        )
18        assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0'
19
20    async def test_geocode(self):
21        location = await self.geocode_run(
22            {"query": "14 rue pelisson villeurbanne"},
23            {"latitude": 45.7733963, "longitude": 4.88612369},
24        )
25        assert "France" in location.address
26
27    async def test_osm_tag(self):
28        await self.geocode_run(
29            {"query": "Freedom", "osm_tag": "tourism:artwork"},
30            {"latitude": 38.8898061, "longitude": -77.009088, "delta": 2.0},
31        )
32
33        await self.geocode_run(
34            {"query": "Freedom", "osm_tag": ["!office", "place:hamlet"]},
35            {"latitude": 44.3862491, "longitude": -88.290994, "delta": 2.0},
36        )
37
38    async def test_bbox(self):
39        await self.geocode_run(
40            {"query": "moscow"},
41            {"latitude": 55.7504461, "longitude": 37.6174943},
42        )
43        await self.geocode_run(
44            {"query": "moscow",  # Idaho USA
45             "bbox": [[50.1, -130.1], [44.1, -100.9]]},
46            {"latitude": 46.7323875, "longitude": -117.0001651},
47        )
48
49    async def test_unicode_name(self):
50        await self.geocode_run(
51            {"query": "\u6545\u5bab"},
52            {"latitude": 39.916, "longitude": 116.390},
53        )
54
55    async def test_reverse(self):
56        result = await self.reverse_run(
57            {"query": Point(45.7733105, 4.8869339)},
58            {"latitude": 45.7733105, "longitude": 4.8869339}
59        )
60        assert "France" in result.address
61
62    async def test_geocode_language_parameter(self):
63        result_geocode = await self.geocode_run(
64            {"query": self.known_country_fr, "language": "de"},
65            {},
66        )
67        assert (
68            result_geocode.raw['properties']['country'] ==
69            self.known_country_de
70        )
71
72    async def test_reverse_language_parameter(self):
73
74        result_reverse_it = await self.reverse_run(
75            {"query": "45.7733105, 4.8869339",
76             "language": "de"},
77            {},
78        )
79        assert (
80            result_reverse_it.raw['properties']['country'] ==
81            self.known_country_de
82        )
83
84        result_reverse_fr = await self.reverse_run(
85            {"query": "45.7733105, 4.8869339",
86             "language": "fr"},
87            {},
88        )
89        assert (
90            result_reverse_fr.raw['properties']['country'] ==
91            self.known_country_fr
92        )
93