@@ -68,10 +68,10 @@ def valid_trytes(trytes, trytes_len):
68
68
69
69
def API (get_query , get_data = None , post_data = None ):
70
70
try :
71
- response = []
71
+ response = {}
72
72
if get_data is not None :
73
73
r = requests .get (str (url + get_query + get_data ), timeout = TIMEOUT )
74
- response = [ r .text , str (r .status_code )]
74
+ response = { "content" : r .text , "status_code" : str (r .status_code )}
75
75
76
76
elif post_data is not None :
77
77
command = "curl " + str (
@@ -85,7 +85,10 @@ def API(get_query, get_data=None, post_data=None):
85
85
stderr = subprocess .PIPE )
86
86
out , err = p .communicate ()
87
87
curl_response = str (out .decode ('ascii' ))
88
- response = curl_response .split (", " )
88
+ response = {
89
+ "content" : curl_response .split (", " )[0 ],
90
+ "status_code" : curl_response .split (", " )[1 ]
91
+ }
89
92
else :
90
93
logging .error ("Wrong request method" )
91
94
response = None
@@ -139,16 +142,17 @@ def test_mam_send_msg(self):
139
142
140
143
for i in range (len (response )):
141
144
logging .debug ("send msg i = " + str (i ) + ", res = " +
142
- response [i ][0 ] + ", status code = " + response [i ][1 ])
145
+ response [i ]["content" ] + ", status code = " +
146
+ response [i ]["status_code" ])
143
147
144
148
for i in range (len (response )):
145
149
if i in pass_case :
146
- res_json = json .loads (response [i ][0 ])
150
+ res_json = json .loads (response [i ]["content" ])
147
151
self .assertTrue (valid_trytes (res_json ["channel" ], LEN_ADDR ))
148
152
self .assertTrue (valid_trytes (res_json ["bundle_hash" ],
149
153
LEN_ADDR ))
150
154
else :
151
- self .assertEqual (STATUS_CODE_500 , response [i ][1 ])
155
+ self .assertEqual (STATUS_CODE_500 , response [i ]["status_code" ])
152
156
153
157
# Time Statistics
154
158
payload = "Who are we? Just a speck of dust within the galaxy?"
@@ -187,9 +191,9 @@ def test_mam_recv_msg(self):
187
191
pass_case = [0 ]
188
192
for i in range (len (test_cases )):
189
193
if i in pass_case :
190
- self .assertTrue (expect_cases [i ] in response [i ][0 ])
194
+ self .assertTrue (expect_cases [i ] in response [i ]["content" ])
191
195
else :
192
- self .assertEqual (STATUS_CODE_405 , response [i ][1 ])
196
+ self .assertEqual (STATUS_CODE_405 , response [i ]["status_code" ])
193
197
194
198
# Time Statistics
195
199
# send a MAM message and use it as the the message to be searched
@@ -198,7 +202,7 @@ def test_mam_recv_msg(self):
198
202
post_data_json = json .dumps (post_data )
199
203
response = API ("/mam/" , post_data = post_data_json )
200
204
201
- res_json = json .loads (response [0 ])
205
+ res_json = json .loads (response ["content" ])
202
206
bundle_hash = res_json ["bundle_hash" ]
203
207
204
208
time_cost = []
@@ -255,12 +259,13 @@ def test_send_transfer(self):
255
259
256
260
for i in range (len (response )):
257
261
logging .debug ("send transfer i = " + str (i ) + ", res = " +
258
- response [i ][0 ] + ", status code = " + response [i ][1 ])
262
+ response [i ]["content" ] + ", status code = " +
263
+ response [i ]["status_code" ])
259
264
260
265
pass_case = [0 , 1 , 2 , 3 ]
261
266
for i in range (len (response )):
262
267
if i in pass_case :
263
- res_json = json .loads (response [i ][0 ])
268
+ res_json = json .loads (response [i ]["content" ])
264
269
265
270
# we only send zero tx at this moment
266
271
self .assertEqual (0 , res_json ["value" ])
@@ -278,9 +283,9 @@ def test_send_transfer(self):
278
283
valid_trytes (res_json ["signature_and_message_fragment" ],
279
284
LEN_MSG_SIGN ))
280
285
elif i == 4 :
281
- self .assertEqual (EMPTY_REPLY , response [i ][1 ])
286
+ self .assertEqual (EMPTY_REPLY , response [i ]["status_code" ])
282
287
else :
283
- self .assertEqual (STATUS_CODE_404 , response [i ][1 ])
288
+ self .assertEqual (STATUS_CODE_404 , response [i ]["status_code" ])
284
289
285
290
# Time Statistics
286
291
time_cost = []
@@ -332,8 +337,9 @@ def test_find_transactions_by_tag(self):
332
337
333
338
for i in range (len (transaction_response )):
334
339
logging .debug ("find transactions by tag i = " + str (i ) +
335
- ", tx_res = " + transaction_response [i ][0 ] +
336
- ", status code = " + transaction_response [i ][1 ])
340
+ ", tx_res = " + transaction_response [i ]["content" ] +
341
+ ", status code = " +
342
+ transaction_response [i ]["status_code" ])
337
343
338
344
response = []
339
345
for t_case in test_cases :
@@ -345,17 +351,19 @@ def test_find_transactions_by_tag(self):
345
351
346
352
for i in range (len (response )):
347
353
logging .debug ("find transactions by tag i = " + str (i ) +
348
- ", res = " + response [i ][0 ] + ", status code = " +
349
- response [i ][1 ])
354
+ ", res = " + response [i ]["content" ] +
355
+ ", status code = " + response [i ]["status_code" ])
350
356
pass_case = [0 , 1 ]
351
357
for i in range (len (response )):
352
358
if i in pass_case :
353
- tx_res_json = json .loads (transaction_response [i ][0 ])
354
- res_json = json .loads (response [i ][0 ])
359
+ expected_tx_json = json .loads (
360
+ transaction_response [i ]["content" ])
361
+ res_json = json .loads (response [i ]["content" ])
355
362
356
- self .assertEqual (tx_res_json ["hash" ], res_json ["hashes" ][0 ])
363
+ self .assertEqual (expected_tx_json ["hash" ],
364
+ res_json ["hashes" ][0 ])
357
365
else :
358
- self .assertEqual (STATUS_CODE_400 , response [i ][1 ])
366
+ self .assertEqual (STATUS_CODE_400 , response [i ]["status_code" ])
359
367
360
368
# Time Statistics
361
369
time_cost = []
@@ -390,9 +398,10 @@ def test_get_transactions_object(self):
390
398
391
399
logging .debug ("sent_transaction_obj = " +
392
400
", sent_transaction_obj[0] = " +
393
- sent_transaction_obj [0 ] +
394
- ", sent_transaction_obj[1] = " + sent_transaction_obj [1 ])
395
- sent_transaction_obj_json = json .loads (sent_transaction_obj [0 ])
401
+ sent_transaction_obj ["content" ] +
402
+ ", sent_transaction_obj[1] = " +
403
+ sent_transaction_obj ["status_code" ])
404
+ sent_transaction_obj_json = json .loads (sent_transaction_obj ["content" ])
396
405
sent_transaction_hash = sent_transaction_obj_json ["hash" ]
397
406
test_cases = [
398
407
sent_transaction_hash , sent_transaction_hash [0 :19 ],
@@ -406,16 +415,17 @@ def test_get_transactions_object(self):
406
415
407
416
for i in range (len (response )):
408
417
logging .debug ("get transactions object i = " + str (i ) +
409
- ", res = " + repr (response [i ][0 ]) +
410
- ", status code = " + repr (response [i ][1 ]))
418
+ ", res = " + repr (response [i ]["content" ]) +
419
+ ", status code = " +
420
+ repr (response [i ]["status_code" ]))
411
421
412
422
pass_case = [0 ]
413
423
for i in range (len (response )):
414
424
if i in pass_case :
415
- res_json = json .loads (response [i ][0 ])
425
+ res_json = json .loads (response [i ]["content" ])
416
426
self .assertEqual (sent_transaction_hash , res_json ["hash" ])
417
427
else :
418
- self .assertEqual (STATUS_CODE_405 , response [i ][1 ])
428
+ self .assertEqual (STATUS_CODE_405 , response [i ]["status_code" ])
419
429
420
430
# Time Statistics
421
431
time_cost = []
@@ -467,11 +477,11 @@ def test_find_transactions_obj_by_tag(self):
467
477
])
468
478
else :
469
479
transaction_response .append (
470
- API ("/transaction/" , post_data = post_data_json ))
480
+ [ API ("/transaction/" , post_data = post_data_json )] )
471
481
472
482
for i in range (len (transaction_response )):
473
483
logging .debug ("find transactions obj by tag i = " + str (i ) +
474
- ", tx_res = " + repr (transaction_response [i ][ 0 ] ))
484
+ ", tx_res = " + repr (transaction_response [i ]))
475
485
476
486
response = []
477
487
for t_case in test_cases :
@@ -481,92 +491,67 @@ def test_find_transactions_obj_by_tag(self):
481
491
for i in range (len (response )):
482
492
logging .debug ("find transactions obj by tag i = " + str (i ) +
483
493
", res = " + repr (response [i ]))
484
-
494
+ pass_case = [ 0 , 1 , 2 ]
485
495
for i in range (len (response )):
486
- if i == 0 or i == 1 :
487
- tx_res_json = json .loads (transaction_response [i ][0 ])
488
- res_tx_json = json .loads (response [i ][0 ])
489
- res_json = res_tx_json ["transactions" ][0 ]
490
-
491
- self .assertEqual (tx_res_json ["hash" ], res_json ["hash" ])
492
- self .assertEqual (tx_res_json ["signature_and_message_fragment" ],
493
- res_json ["signature_and_message_fragment" ])
494
- self .assertEqual (tx_res_json ["address" ], res_json ["address" ])
495
- self .assertEqual (tx_res_json ["value" ], res_json ["value" ])
496
- self .assertEqual (tx_res_json ["obsolete_tag" ],
497
- res_json ["obsolete_tag" ])
498
- self .assertEqual (tx_res_json ["timestamp" ],
499
- res_json ["timestamp" ])
500
- self .assertEqual (tx_res_json ["last_index" ],
501
- res_json ["last_index" ])
502
- self .assertEqual (tx_res_json ["bundle_hash" ],
503
- res_json ["bundle_hash" ])
504
- self .assertEqual (tx_res_json ["trunk_transaction_hash" ],
505
- res_json ["trunk_transaction_hash" ])
506
- self .assertEqual (tx_res_json ["branch_transaction_hash" ],
507
- res_json ["branch_transaction_hash" ])
508
- self .assertEqual (tx_res_json ["tag" ], res_json ["tag" ])
509
- self .assertEqual (tx_res_json ["attachment_timestamp" ],
510
- res_json ["attachment_timestamp" ])
511
- self .assertEqual (
512
- tx_res_json ["attachment_timestamp_lower_bound" ],
513
- res_json ["attachment_timestamp_lower_bound" ])
514
- self .assertEqual (
515
- tx_res_json ["attachment_timestamp_upper_bound" ],
516
- res_json ["attachment_timestamp_upper_bound" ])
517
- self .assertEqual (tx_res_json ["nonce" ], res_json ["nonce" ])
518
- elif i == 2 :
519
- res_tx_json = json .loads (response [i ][0 ])
496
+ if i in pass_case :
497
+ res_tx_json = json .loads (response [i ]["content" ])
520
498
res_json = []
521
- tx_res_json = []
499
+ expected_tx_json = []
522
500
for j in range (len (transaction_response [i ])):
523
501
res_json .append (res_tx_json ["transactions" ][j ])
524
- tx_res_json .append (
525
- json .loads (transaction_response [i ][j ][0 ]))
526
-
527
- for j in range (len (tx_res_json )):
502
+ expected_tx_json .append (
503
+ json .loads (transaction_response [i ][j ]["content" ]))
504
+
505
+ for j in range (len (expected_tx_json )):
528
506
case_examined_equal = False
529
507
for k in range (len (res_json )):
530
- if tx_res_json [j ]["hash" ] == res_json [k ]["hash" ]:
508
+ if expected_tx_json [j ]["hash" ] == res_json [k ]["hash" ]:
531
509
self .assertEqual (
532
- tx_res_json [j ]["signature_and_message_fragment" ],
510
+ expected_tx_json [j ]
511
+ ["signature_and_message_fragment" ],
533
512
res_json [k ]["signature_and_message_fragment" ])
534
- self .assertEqual (tx_res_json [j ]["address" ],
535
- res_json [k ]["address" ])
536
- self .assertEqual (tx_res_json [j ]["value" ],
537
- res_json [k ]["value" ])
538
- self .assertEqual (tx_res_json [j ]["obsolete_tag" ],
539
- res_json [k ]["obsolete_tag" ])
540
- self .assertEqual (tx_res_json [j ]["timestamp" ],
541
- res_json [k ]["timestamp" ])
542
- self .assertEqual (tx_res_json [j ]["last_index" ],
543
- res_json [k ]["last_index" ])
544
- self .assertEqual (tx_res_json [j ]["bundle_hash" ],
545
- res_json [k ]["bundle_hash" ])
513
+ self .assertEqual (expected_tx_json [j ]["address" ],
514
+ res_json [k ]["address" ])
515
+ self .assertEqual (expected_tx_json [j ]["value" ],
516
+ res_json [k ]["value" ])
517
+ self .assertEqual (
518
+ expected_tx_json [j ]["obsolete_tag" ],
519
+ res_json [k ]["obsolete_tag" ])
520
+ self .assertEqual (expected_tx_json [j ]["timestamp" ],
521
+ res_json [k ]["timestamp" ])
522
+ self .assertEqual (expected_tx_json [j ]["last_index" ],
523
+ res_json [k ]["last_index" ])
524
+ self .assertEqual (
525
+ expected_tx_json [j ]["bundle_hash" ],
526
+ res_json [k ]["bundle_hash" ])
546
527
self .assertEqual (
547
- tx_res_json [j ]["trunk_transaction_hash" ],
528
+ expected_tx_json [j ]["trunk_transaction_hash" ],
548
529
res_json [k ]["trunk_transaction_hash" ])
549
530
self .assertEqual (
550
- tx_res_json [j ]["branch_transaction_hash" ],
531
+ expected_tx_json [j ]["branch_transaction_hash" ],
551
532
res_json [k ]["branch_transaction_hash" ])
552
- self .assertEqual (tx_res_json [j ]["tag" ],
553
- res_json [k ]["tag" ])
533
+ self .assertEqual (expected_tx_json [j ]["tag" ],
534
+ res_json [k ]["tag" ])
554
535
self .assertEqual (
555
- tx_res_json [j ]["attachment_timestamp" ],
536
+ expected_tx_json [j ]["attachment_timestamp" ],
556
537
res_json [k ]["attachment_timestamp" ])
557
538
self .assertEqual (
558
- tx_res_json [j ]["attachment_timestamp_lower_bound" ],
559
- res_json [k ]["attachment_timestamp_lower_bound" ])
539
+ expected_tx_json [j ]
540
+ ["attachment_timestamp_lower_bound" ],
541
+ res_json [k ]
542
+ ["attachment_timestamp_lower_bound" ])
560
543
self .assertEqual (
561
- tx_res_json [j ]["attachment_timestamp_upper_bound" ],
562
- res_json [k ]["attachment_timestamp_upper_bound" ])
563
- self .assertEqual (tx_res_json [j ]["nonce" ],
564
- res_json [k ]["nonce" ])
544
+ expected_tx_json [j ]
545
+ ["attachment_timestamp_upper_bound" ],
546
+ res_json [k ]
547
+ ["attachment_timestamp_upper_bound" ])
548
+ self .assertEqual (expected_tx_json [j ]["nonce" ],
549
+ res_json [k ]["nonce" ])
565
550
case_examined_equal = True
566
551
break
567
552
self .assertTrue (case_examined_equal )
568
553
else :
569
- self .assertEqual (STATUS_CODE_400 , response [i ][1 ])
554
+ self .assertEqual (STATUS_CODE_400 , response [i ]["status_code" ])
570
555
571
556
# Time Statistics
572
557
time_cost = []
0 commit comments