-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_gecoding.py
More file actions
165 lines (128 loc) · 7.71 KB
/
test_gecoding.py
File metadata and controls
165 lines (128 loc) · 7.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import os
import unittest
import stadiamaps
address = "Põhja pst 27"
class TestGeocoding(unittest.TestCase):
def setUp(self):
self.configuration = stadiamaps.Configuration()
self.configuration.api_key["ApiKeyAuth"] = os.environ["STADIA_API_KEY"]
def tearDown(self):
pass
def testAutocompleteV1(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.autocomplete(text=address, lang="en")
self.assertEqual("Estonia", res.features[0].properties.country)
self.assertEqual("address", res.features[0].properties.layer)
def testAutocompleteV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.autocomplete_v2(text=address, lang="en")
self.assertEqual(None, res.features[0].properties.context)
self.assertEqual("address", res.features[0].properties.layer)
def testSearch(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.search(address)
self.assertEqual("Estonia", res.features[0].properties.country)
self.assertEqual("address", res.features[0].properties.layer)
def testSearchV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.search_v2(address)
self.assertEqual("EST", res.features[0].properties.context.iso_3166_a3)
self.assertEqual("address", res.features[0].properties.layer)
def testStructuredSearch(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.search_structured(address=address, country="Estonia")
self.assertEqual("Estonia", res.features[0].properties.country)
self.assertEqual("address", res.features[0].properties.layer)
def testReverse(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.reverse(59.444351, 24.750645)
self.assertEqual("Estonia", res.features[0].properties.country)
def testReverseV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.reverse_v2(59.444351, 24.750645, lang="en")
self.assertEqual("EST", res.features[0].properties.context.iso_3166_a3)
def testReverseWithLayerFilter(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.reverse(59.444351, 24.750645,
layers=[stadiamaps.GeocodingLayer.ADDRESS, stadiamaps.GeocodingLayer.OCEAN])
self.assertEqual("Estonia", res.features[0].properties.country)
self.assertEqual("address", res.features[0].properties.layer)
def testReverseWithLayerFilterV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.reverse_v2(59.444351, 24.750645,
layers=[stadiamaps.LayerId.ADDRESS, stadiamaps.LayerId.OCEAN],
lang="en")
self.assertEqual("EST", res.features[0].properties.context.iso_3166_a3)
self.assertEqual("address", res.features[0].properties.layer)
def testReverseUncommonLayer(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
# Middle of the Gulf of Oman
res = api_instance.reverse(24.750645, 59.444351)
self.assertEqual("marinearea", res.features[0].properties.layer)
def testReverseUncommonLayerV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
# Middle of the Gulf of Oman
res = api_instance.reverse_v2(24.750645, 59.444351, lang="en")
self.assertEqual("marinearea", res.features[0].properties.layer)
def testPlaceV1(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.place_details(["openstreetmap:address:way/109867749"])
self.assertEqual(1, len(res.features))
self.assertEqual("Estonia", res.features[0].properties.country)
self.assertEqual("address", res.features[0].properties.layer)
def testPlaceV2(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.place_details_v2(["openstreetmap:address:way/109867749"], lang="en")
self.assertEqual(1, len(res.features))
self.assertEqual("Estonia", res.features[0].properties.context.whosonfirst.country.name)
self.assertEqual("EST", res.features[0].properties.context.iso_3166_a3)
self.assertEqual("address", res.features[0].properties.layer)
def testBulk(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.search_bulk([
stadiamaps.BulkRequest(endpoint="/v1/search",
query=stadiamaps.BulkRequestQuery(stadiamaps.SearchQuery(text=address))),
stadiamaps.BulkRequest(endpoint="/v1/search/structured",
query=stadiamaps.BulkRequestQuery(stadiamaps.SearchStructuredQuery(
address=address,
country="EE",
layers=[
stadiamaps.GeocodingLayer.COARSE,
stadiamaps.GeocodingLayer.ADDRESS]))),
])
self.assertEqual(2, len(res))
for rec in res:
self.assertEqual(200, rec.status)
self.assertEqual("Estonia", rec.response.features[0].properties.country)
self.assertEqual("address", rec.response.features[0].properties.layer)
def testBulkPostalcodeRegression(self):
with stadiamaps.ApiClient(self.configuration) as api_client:
api_instance = stadiamaps.GeocodingApi(api_client)
res = api_instance.search_bulk([
stadiamaps.BulkRequest(endpoint="/v1/search/structured",
query=stadiamaps.BulkRequestQuery(stadiamaps.SearchStructuredQuery(
locality="Aach",
postalcode="78267",
region="North Rhine-Westphalia",
country="Germany"))),
])
self.assertEqual(1, len(res))
rec = res[0]
self.assertEqual(200, rec.status)
self.assertEqual("Germany", rec.response.features[0].properties.country)
self.assertEqual("postalcode", rec.response.features[0].properties.layer)
self.assertEqual("78267", rec.response.features[0].properties.postalcode)