This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
/
test_distances.py
61 lines (51 loc) · 1.53 KB
/
test_distances.py
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
import responses
import mapbox
points = [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-87.337875,
36.539156]}}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-86.577791,
36.722137
]}}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-88.247685,
36.922175]}}]
@responses.activate
def test_distance():
responses.add(
responses.POST,
'https://api.mapbox.com/distances/v1/mapbox/driving?access_token=pk.test',
match_querystring=True,
body='{"durations":[[0,4977,5951],[4963,0,9349],[5881,9317,0]]}',
status=200,
content_type='application/json')
res = mapbox.Distance(access_token='pk.test').distances(points)
assert res.status_code == 200
assert list(res.json().keys()) == ["durations", ]
@responses.activate
def test_distances_matrix():
responses.add(
responses.POST,
'https://api.mapbox.com/distances/v1/mapbox/driving?access_token=pk.test',
match_querystring=True,
body='{"durations":[[0,4977,5951],[4963,0,9349],[5881,9317,0]]}',
status=200,
content_type='application/json')
res = mapbox.Distance(access_token='pk.test').distances(points)
matrix = res.json()['durations']
# 3x3 list
assert len(matrix) == 3
assert len(matrix[0]) == 3