Skip to content

Commit 2370c9f

Browse files
hackaugustoLefterisJP
authored andcommitted
using grequest json
1 parent 1210134 commit 2370c9f

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

raiden/tests/api/test_api.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pyethapp.jsonrpc import address_encoder, address_decoder
99

1010
from raiden.api.v1.encoding import HexAddressConverter
11-
from raiden.tests.utils.apitestcontext import decode_response
1211
from raiden.utils import channel_to_api_dict
1312
from raiden.tests.utils.transfer import channel
1413
from raiden.transfer.state import (
@@ -91,12 +90,12 @@ def test_api_query_channels(
9190
)
9291
response = request.send().response
9392
assert_proper_response(response)
94-
assert decode_response(response) == api_test_context.expect_channels()
93+
assert response.json() == api_test_context.expect_channels()
9594

9695
api_test_context.make_channel_and_add()
9796
response = request.send().response
9897
assert_proper_response(response)
99-
assert decode_response(response) == api_test_context.expect_channels()
98+
assert response.json() == api_test_context.expect_channels()
10099

101100

102101
def test_api_open_and_deposit_channel(
@@ -119,7 +118,7 @@ def test_api_open_and_deposit_channel(
119118
response = request.send().response
120119

121120
assert_proper_response(response)
122-
response = decode_response(response)
121+
response = response.json()
123122
expected_response = channel_data_obj
124123
expected_response['balance'] = 0
125124
expected_response['state'] = CHANNEL_STATE_OPENED
@@ -145,7 +144,7 @@ def test_api_open_and_deposit_channel(
145144
response = request.send().response
146145

147146
assert_proper_response(response)
148-
response = decode_response(response)
147+
response = response.json()
149148
expected_response = channel_data_obj
150149
expected_response['balance'] = balance
151150
expected_response['state'] = CHANNEL_STATE_OPENED
@@ -166,7 +165,7 @@ def test_api_open_and_deposit_channel(
166165
)
167166
response = request.send().response
168167
assert_proper_response(response)
169-
response = decode_response(response)
168+
response = response.json()
170169
expected_response = {
171170
'channel_address': first_channel_address,
172171
'partner_address': first_partner_address,
@@ -188,7 +187,7 @@ def test_api_open_and_deposit_channel(
188187

189188
response = request.send().response
190189
assert_proper_response(response)
191-
response = decode_response(response)
190+
response = response.json()
192191
expected_response = {
193192
'channel_address': second_channel_address,
194193
'partner_address': second_partner_address,
@@ -221,7 +220,7 @@ def test_api_open_close_and_settle_channel(
221220

222221
balance = 0
223222
assert_proper_response(response)
224-
response = decode_response(response)
223+
response = response.json()
225224
expected_response = channel_data_obj
226225
expected_response['balance'] = balance
227226
expected_response['state'] = CHANNEL_STATE_OPENED
@@ -242,7 +241,6 @@ def test_api_open_close_and_settle_channel(
242241
)
243242
response = request.send().response
244243
assert_proper_response(response)
245-
response = decode_response(response)
246244
expected_response = {
247245
'channel_address': channel_address,
248246
'partner_address': partner_address,
@@ -251,7 +249,7 @@ def test_api_open_close_and_settle_channel(
251249
'state': CHANNEL_STATE_CLOSED,
252250
'balance': balance
253251
}
254-
assert response == expected_response
252+
assert response.json() == expected_response
255253

256254
# let's settle the channel
257255
request = grequests.patch(
@@ -264,7 +262,6 @@ def test_api_open_close_and_settle_channel(
264262
)
265263
response = request.send().response
266264
assert_proper_response(response)
267-
response = decode_response(response)
268265
expected_response = {
269266
'channel_address': channel_address,
270267
'partner_address': partner_address,
@@ -273,7 +270,7 @@ def test_api_open_close_and_settle_channel(
273270
'state': CHANNEL_STATE_SETTLED,
274271
'balance': balance
275272
}
276-
assert response == expected_response
273+
assert response.json() == expected_response
277274

278275

279276
def test_api_channel_state_change_errors(
@@ -295,7 +292,7 @@ def test_api_channel_state_change_errors(
295292
)
296293
response = request.send().response
297294
assert_proper_response(response)
298-
response = decode_response(response)
295+
response = response.json()
299296
channel_address = response['channel_address']
300297

301298
# let's try to settle the channel (we are bad!)
@@ -430,7 +427,7 @@ def test_api_tokens(
430427
)
431428
response = request.send().response
432429
assert_proper_response(response)
433-
response = decode_response(response)
430+
response = response.json()
434431
expected_response = [
435432
{'address': '0x61c808d82a3ac53231750dadc13c777b59310bd9'},
436433
{'address': '0xea674fdde714fd979de3edf0f56aa9716b898ec8'},
@@ -458,7 +455,7 @@ def test_query_partners_by_token(
458455
)
459456
response = request.send().response
460457
assert_proper_response(response)
461-
response = decode_response(response)
458+
response = response.json()
462459
first_channel_address = response['channel_address']
463460

464461
channel_data_obj['partner_address'] = second_partner_address
@@ -468,7 +465,7 @@ def test_query_partners_by_token(
468465
)
469466
response = request.send().response
470467
assert_proper_response(response)
471-
response = decode_response(response)
468+
response = response.json()
472469
second_channel_address = response['channel_address']
473470

474471
# and a channel for another token
@@ -491,7 +488,7 @@ def test_query_partners_by_token(
491488
)
492489
response = request.send().response
493490
assert_proper_response(response)
494-
response = decode_response(response)
491+
response = response.json()
495492
expected_response = [
496493
{
497494
'partner_address': first_partner_address,
@@ -775,7 +772,7 @@ def test_api_transfers(
775772
)
776773
response = request.send().response
777774
assert_proper_response(response)
778-
response = decode_response(response)
775+
response = response.json()
779776
assert response == transfer
780777

781778

@@ -790,9 +787,9 @@ def test_connect_and_leave_token_network(
790787
)
791788
response = request.send().response
792789
assert_proper_response(response)
793-
channels = decode_response(response)
794-
assert len(channels) == 0
795-
assert decode_response(response) == api_test_context.expect_channels()
790+
channels = response.json()
791+
assert not channels
792+
assert response.json() == api_test_context.expect_channels()
796793

797794
funds = 100
798795
initial_channel_target = DEFAULT_INITIAL_CHANNEL_TARGET
@@ -814,10 +811,10 @@ def test_connect_and_leave_token_network(
814811
)
815812
response = request.send().response
816813
assert_proper_response(response)
817-
channels = decode_response(response)
814+
channels = response.json()
818815
# There should be three channels according to the default initial_channel_target
819816
assert len(channels) == DEFAULT_INITIAL_CHANNEL_TARGET
820-
assert decode_response(response) == api_test_context.expect_channels()
817+
assert response.json() == api_test_context.expect_channels()
821818

822819
expected_balance = int((funds * joinable_funds_target) / initial_channel_target)
823820
assert channels[0]['balance'] == expected_balance
@@ -841,7 +838,7 @@ def test_connect_and_leave_token_network(
841838
response = request.send().response
842839
assert_proper_response(response)
843840

844-
channels = decode_response(response)
841+
channels = response.json()
845842
assert channels[0]['state'] == CHANNEL_STATE_SETTLED
846843
assert channels[1]['state'] == CHANNEL_STATE_SETTLED
847844
assert channels[2]['state'] == CHANNEL_STATE_SETTLED

raiden/tests/utils/apitestcontext.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ def settled(self):
3535
return self.state == CHANNEL_STATE_SETTLED
3636

3737

38-
def decode_response(response):
39-
return json.loads(response._content)
40-
41-
4238
class ApiTestContext():
4339

4440
def __init__(self, reveal_timeout):

0 commit comments

Comments
 (0)