-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_peers.py
More file actions
66 lines (56 loc) · 1.6 KB
/
Copy pathtest_peers.py
File metadata and controls
66 lines (56 loc) · 1.6 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
import responses
from client import Client
def test_all_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/peers',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.peers.all()
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/peers'
)
def test_all_calls_correct_url_with_params():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/peers',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.peers.all({
'os': 'a',
'status': 'live',
'port': 1337,
'version': '2.0.0',
'orderBy': 'ip',
'page': 5,
'limit': 69,
})
assert len(responses.calls) == 1
url = responses.calls[0].request.url
assert url.startswith('http://127.0.0.1:4002/api/peers?')
assert 'os=a' in url
assert 'status=live' in url
assert 'port=1337' in url
assert 'version=2.0.0' in url
assert 'orderBy=ip' in url
assert 'page=5' in url
assert 'limit=69' in url
def test_get_calls_correct_url_with_ip():
ip = '123.4.5.67'
responses.add(
responses.GET,
f'http://127.0.0.1:4002/api/peers/{ip}',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.peers.get(ip)
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/peers/123.4.5.67'
)