-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathtest_api.py
66 lines (61 loc) · 2.18 KB
/
test_api.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
62
63
64
65
66
from OSMPythonTools.api import Api
def metadata(x):
assert x.version() != None and x.version() != '' and float(x.version()) > 0
assert x.generator() != None and x.generator() != ''
assert x.copyright() != None and x.copyright() != ''
assert x.attribution() != None and x.attribution() != ''
assert x.license() != None and x.license() != ''
def test_node():
api = Api()
x = api.query('node/42467507')
assert x.isValid()
assert x.id() == 42467507
assert x.type() == 'node'
assert len(x.tags()) > 0
assert 'highway' in x.tags()
assert x.tag('highway') is not None
assert x.tag('abcde') is None
assert abs(x.lat() - 40.7014417) < .00001
assert abs(x.lon() - (-73.9430797)) < .00001
assert int(x.version()) > 0
metadata(x)
def test_way():
api = Api()
x = api.query('way/108402486')
assert x.isValid()
assert x.id() == 108402486
assert x.type() == 'way'
assert len(x.nodes()) > 0
assert 1243967857 in [n.id() for n in x.nodes()]
assert abs(x.nodes()[0].lat() - 40.866) < .01
assert abs(x.nodes()[0].lon() - (-73.795)) < .01
assert abs(x.nodes(shallow=False)[1].lat() - 40.866) < .01
assert abs(x.nodes(shallow=False)[1].lon() - (-73.795)) < .01
assert int(x.version()) > 0
metadata(x)
def test_relation():
api = Api()
x = api.query('relation/1539714')
assert x.isValid()
assert x.id() == 1539714
assert x.type() == 'relation'
assert len(x.members()) > 0
assert 108402486 in [n.id() for n in x.members()]
assert abs(x.members(shallow=False)[0].nodes()[0].lat() - 40.866) < .01
assert abs(x.members()[0].nodes()[0].lon() - (-73.795)) < .01
assert abs(x.members(shallow=False)[1].nodes()[0].lat() - 40.866) < .01
assert abs(x.members(shallow=False)[1].nodes()[0].lon() - (-73.795)) < .01
assert int(x.version()) > 0
metadata(x)
def test_history():
api = Api()
busStop = api.query('node/42467507')
assert busStop.history() is None
busStop = api.query('node/42467507', history=True)
assert len(busStop.history()) >= 5
assert len(busStop.history()) == busStop.version()
for i, b in enumerate(busStop.history()):
assert b.id() == 42467507
assert b.type() == 'node'
assert b.version() == i + 1
assert len(b.tags()) >= 0