-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_blocks.py
More file actions
122 lines (100 loc) · 2.99 KB
/
Copy pathtest_blocks.py
File metadata and controls
122 lines (100 loc) · 2.99 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
import responses
from client import Client
def test_all_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.all()
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/blocks'
)
def test_all_calls_correct_url_with_params():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.all({
'page': 5,
'limit': 69,
'orderBy': 'timestamp.epoch',
'number': 6838329,
})
assert len(responses.calls) == 1
url = responses.calls[0].request.url
assert url.startswith('http://127.0.0.1:4002/api/blocks?')
assert 'page=5' in url
assert 'limit=69' in url
assert 'orderBy=timestamp.epoch' in url
assert 'number=6838329' in url
def test_get_calls_correct_url():
block_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks/{}'.format(block_id),
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.get(block_id)
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/blocks/12345'
)
def test_first_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks/first',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.first()
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/blocks/first'
)
def test_last_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks/last',
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.last()
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/api/blocks/last'
)
def test_transactions_calls_correct_url_with_params():
block_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/api/blocks/{}/transactions'.format(
block_id
),
json={'success': True},
status=200
)
client = Client('http://127.0.0.1:4002/api')
client.blocks.transactions(block_id, {
'page': 5,
'limit': 69,
'orderBy': 'timestamp.epoch',
})
assert len(responses.calls) == 1
url = responses.calls[0].request.url
assert url.startswith(
'http://127.0.0.1:4002/api/blocks/12345/transactions?'
)
assert 'page=5' in url
assert 'limit=69' in url
assert 'orderBy=timestamp.epoch' in url