forked from googlemaps/google-maps-services-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_elevation.py
More file actions
114 lines (92 loc) · 4.41 KB
/
test_elevation.py
File metadata and controls
114 lines (92 loc) · 4.41 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
#
# Copyright 2014 Google Inc. All rights reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
"""Tests for the elevation module."""
import datetime
import responses
import googlemaps
import test as _test
class ElevationTest(_test.TestCase):
def setUp(self):
self.key = 'AIzaasdf'
self.client = googlemaps.Client(self.key)
@responses.activate
def test_elevation_single(self):
responses.add(responses.GET,
'https://maps.googleapis.com/maps/api/elevation/json',
body='{"status":"OK","results":[]}',
status=200,
content_type='application/json')
results = self.client.elevation((40.714728, -73.998672))
self.assertEqual(1, len(responses.calls))
self.assertURLEqual('https://maps.googleapis.com/maps/api/elevation/json?'
'locations=enc:abowFtzsbM&key=%s' % self.key,
responses.calls[0].request.url)
@responses.activate
def test_elevation_single_list(self):
responses.add(responses.GET,
'https://maps.googleapis.com/maps/api/elevation/json',
body='{"status":"OK","results":[]}',
status=200,
content_type='application/json')
results = self.client.elevation([(40.714728, -73.998672)])
self.assertEqual(1, len(responses.calls))
self.assertURLEqual('https://maps.googleapis.com/maps/api/elevation/json?'
'locations=enc:abowFtzsbM&key=%s' % self.key,
responses.calls[0].request.url)
@responses.activate
def test_elevation_multiple(self):
responses.add(responses.GET,
'https://maps.googleapis.com/maps/api/elevation/json',
body='{"status":"OK","results":[]}',
status=200,
content_type='application/json')
locations = [(40.714728, -73.998672), (-34.397, 150.644)]
results = self.client.elevation(locations)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual('https://maps.googleapis.com/maps/api/elevation/json?'
'locations=enc:abowFtzsbMhgmiMuobzi@&key=%s' % self.key,
responses.calls[0].request.url)
def test_elevation_along_path_single(self):
with self.assertRaises(googlemaps.exceptions.ApiError):
results = self.client.elevation_along_path(
[(40.714728, -73.998672)], 5)
@responses.activate
def test_elevation_along_path(self):
responses.add(responses.GET,
'https://maps.googleapis.com/maps/api/elevation/json',
body='{"status":"OK","results":[]}',
status=200,
content_type='application/json')
path = [(40.714728, -73.998672), (-34.397, 150.644)]
results = self.client.elevation_along_path(path, 5)
self.assertEqual(1, len(responses.calls))
self.assertURLEqual('https://maps.googleapis.com/maps/api/elevation/json?'
'path=enc:abowFtzsbMhgmiMuobzi@&'
'key=%s&samples=5' % self.key,
responses.calls[0].request.url)
@responses.activate
def test_short_latlng(self):
responses.add(responses.GET,
'https://maps.googleapis.com/maps/api/elevation/json',
body='{"status":"OK","results":[]}',
status=200,
content_type='application/json')
results = self.client.elevation((40, -73))
self.assertEqual(1, len(responses.calls))
self.assertURLEqual('https://maps.googleapis.com/maps/api/elevation/json?'
'locations=40,-73&key=%s' % self.key,
responses.calls[0].request.url)