forked from AplaProject/apla-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests_API.py
More file actions
711 lines (648 loc) · 30.7 KB
/
tests_API.py
File metadata and controls
711 lines (648 loc) · 30.7 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
import unittest
import utils
import config
import requests
import json
import funcs
import os
import time
class ApiTestCase(unittest.TestCase):
def setUp(self):
global url, token, prKey, pause
self.config = config.getNodeConfig()
url = self.config["2"]["url"]
pause = self.config["1"]["time_wait_tx_in_block"]
prKey = self.config["1"]['private_key']
self.data = utils.login(url, prKey, 0)
token = self.data["jwtToken"]
def assertTxInBlock(self, result, jwtToken):
self.assertIn("hash", result)
hash = result['hash']
status = utils.txstatus(url, pause, hash, jwtToken)
if len(status['blockid']) > 0:
self.assertNotIn(json.dumps(status), 'errmsg')
return status["blockid"]
else:
return status["errmsg"]["error"]
def check_get_api(self, endPoint, data, keys):
end = url + endPoint
result = funcs.call_get_api(end, data, token)
for key in keys:
self.assertIn(key, result)
return result
def check_post_api(self, endPoint, data, keys):
end = url + endPoint
result = funcs.call_post_api(end, data, token)
for key in keys:
self.assertIn(key, result)
return result
def get_error_api(self, endPoint, data):
end = url + endPoint
result = funcs.call_get_api(end, data, token)
error = result["error"]
message = result["msg"]
return error, message
def call(self, name, data):
resp = utils.call_contract(url, prKey, name, data, token)
resp = self.assertTxInBlock(resp, token)
return resp
def test_balance(self):
asserts = ["amount", "money"]
self.check_get_api('/balance/' + self.data['address'], "", asserts)
def test_balance_incorrect_wallet(self):
wallet = "0000-0990-3244-5453-2310"
msg = "Wallet " + wallet + " is not valid"
error, message = self.get_error_api('/balance/' + wallet, "")
self.assertEqual(error, "E_INVALIDWALLET", "Incorrect error")
def test_getEcosystem(self):
asserts = ["number"]
self.check_get_api("/ecosystems/", "", asserts)
def test_get_param_ecosystem(self):
asserts = ["list"]
ecosysNum = "1"
self.check_get_api("/ecosystemparams/?ecosystem="+ecosysNum, "", asserts)
def test_get_param_current_ecosystem(self):
asserts = ["list"]
self.check_get_api("/ecosystemparams/", "", asserts)
def test_get_params_ecosystem_with_names(self):
asserts = ["list"]
names = "founder_account,new_table,changing_tables"
res = self.check_get_api("/ecosystemparams/?names="+names, "", asserts)
mustBe = dict(count=3,
par1="founder_account",
par2="new_table",
par3="changing_tables")
actual = dict(count=len(res["list"]),
par1=res["list"][0]["name"],
par2=res["list"][1]["name"],
par3=res["list"][2]["name"])
self.assertDictEqual(actual, mustBe, "test_get_params_ecosystem_with_names is failed!")
def test_get_parametr_of_current_ecosystem(self):
asserts = ["id", "name", "value", "conditions"]
data = {}
self.check_get_api("/ecosystemparam/founder_account/", data, asserts)
def test_get_incorrect_ecosys_parametr(self):
asserts = ""
error, message = self.get_error_api("/ecosystemparam/incorrectParam/", asserts)
self.assertEqual(error, "E_PARAMNOTFOUND", "Incorrect error: " + error + message)
def test_get_tables_of_current_ecosystem(self):
asserts = ["list", "count"]
data = {}
self.check_get_api("/tables", data, asserts)
def test_get_table_information(self):
dictNames = {}
dictNamesAPI = {}
data = {}
tables = utils.getEcosysTables(self.config["1"]["dbHost"],
self.config["1"]["dbName"],
self.config["1"]["login"],
self.config["1"]["pass"])
for table in tables:
if "table" not in table:
tableInfo = funcs.call_get_api(url + "/table/" + table[2:], data, token)
if "name" in str(tableInfo):
dictNames[table[2:]] = table[2:]
dictNamesAPI[table[2:]] = tableInfo["name"]
else:
self.fail("Answer from API /table/" + table + " is: " + str(tableInfo))
self.assertDictEqual(dictNamesAPI, dictNames,
"Any of API tableInfo gives incorrect data")
def test_get_incorrect_table_information(self):
table = "tab"
data = {}
error, message = self.get_error_api("/table/" + table, data)
err = "E_TABLENOTFOUND"
msg = "Table " + table + " has not been found"
self.assertEqual(err, error, "Incorrect error")
self.assertEqual(message, msg, "Incorrect error massege")
def test_get_table_data(self):
dictCount = {}
dictCountTable = {}
data = {}
tables = utils.getEcosysTables(self.config["1"]["dbHost"],
self.config["1"]["dbName"],
self.config["1"]["login"],
self.config["1"]["pass"])
for table in tables:
tableData = funcs.call_get_api(url + "/list/" + table[2:], data, token)
count = utils.getCountTable(self.config["1"]["dbHost"],
self.config["1"]["dbName"],
self.config["1"]["login"],
self.config["1"]["pass"], table)
if count > 0:
if len(tableData["list"]) == count or (len(tableData["list"]) == 25 and
count > 25):
dictCount[table] = count
dictCountTable[table] = int(tableData["count"])
else:
self.fail("Count list of " + table +\
" not equels of count table. Count of table: " +\
str(count) + " Count of list length: " +\
str(len(tableData["list"])))
else:
dictCount[table] = 0
dictCountTable[table] = int(tableData["count"])
self.assertDictEqual(dictCount, dictCountTable,
"Any of count not equels real count")
def test_get_incorrect_table_data(self):
table = "tab"
data = {}
error, message = self.get_error_api("/list/" + table, data)
err = "E_TABLENOTFOUND"
msg = "Table " + table + " has not been found"
self.assertEqual(err, error, "Incorrect error")
self.assertEqual(message, msg, "Incorrect error massege")
def test_get_table_data_row(self):
asserts = ["value"]
data = {}
self.check_get_api("/row/contracts/2", data, asserts)
def test_get_incorrect_table_data_row(self):
table = "tab"
data = {}
error, message = self.get_error_api("/row/" + table + "/2", data)
err = "E_QUERY"
msg = "DB query is wrong"
self.assertEqual(err, error, "Incorrect errror")
self.assertEqual(msg, message, "Incorrect error message")
def test_get_contract_information(self):
asserts = ["name"]
data = {}
self.check_get_api("/contract/MainCondition", data, asserts)
def test_get_incorrect_contract_information(self):
contract = "contract"
data = {}
error, message = self.get_error_api("/contract/" + contract, data)
err = "E_CONTRACT"
msg = "There is not " + contract + " contract"
def test_content_lang(self):
nameLang = "Lang_" + utils.generate_random_name()
data = {"ApplicationId": 1, "Name": nameLang,
"Trans": "{\"en\": \"World_en\", \"ru\" : \"Мир_ru\"," +\
"\"fr-FR\": \"Monde_fr-FR\", \"de\": \"Welt_de\"}"}
res = self.call("NewLang", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
namePage = "Page_" + utils.generate_random_name()
valuePage = "Hello, LangRes(" + nameLang + ")"
dataPage = {"ApplicationId": 1, "Name": namePage, "Value": valuePage, "Conditions": "true",
"Menu": "default_menu"}
res = self.call("NewPage", dataPage)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
content = [{'tag': 'text', 'text': 'Hello, World_en'}]
contentRu = [{'tag': 'text', 'text': 'Hello, Мир_ru'}]
contentFr = [{'tag': 'text', 'text': 'Hello, Monde_fr-FR'}]
contentDe = [{'tag': 'text', 'text': 'Hello, Welt_de'}]
dictExp ={"default" : content, "ru": contentRu,
"fr": contentFr, "de": contentDe, "pe": content}
pContent = funcs.get_content(url, "page", namePage, "en", 1, token) # should be: en
ruPContent = funcs.get_content(url, "page", namePage, "ru", 1, token) # should be: ru
frPcontent = funcs.get_content(url, "page", namePage, "fr-FR", 1, token) # should be: fr-FR
dePcontent = funcs.get_content(url, "page", namePage, "de-DE", 1, token) # should be: de
pePcontent = funcs.get_content(url, "page", namePage, "pe", 1, token) # should be: en
dictCur = {"default" : pContent['tree'], "ru": ruPContent['tree'],
"fr": frPcontent['tree'], "de": dePcontent['tree'], "pe": pePcontent['tree']}
self.assertDictEqual(dictCur, dictExp, "One of langRes is faild")
def test_content_lang_after_edit(self):
nameLang = "Lang_" + utils.generate_random_name()
data = {"ApplicationId": 1, "Name": nameLang,
"Trans": "{\"en\": \"World_en\", \"ru\" : \"Мир_ru\"," +\
"\"fr-FR\": \"Monde_fr-FR\", \"de\": \"Welt_de\"}"}
res = self.call("NewLang", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
namePage = "Page_" + utils.generate_random_name()
valuePage = "Hello, LangRes(" + nameLang + ")"
dataPage = {"Name": namePage, "Value": valuePage, "Conditions": "true",
"Menu": "default_menu", "ApplicationId": 1,}
res = self.call("NewPage", dataPage)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
count = self.check_get_api("/list/languages", "", [])["count"]
dataEdit = {"Id": count, "AppID": 1, "Name": nameLang,
"Trans": "{\"en\": \"World_en_ed\", \"ru\" : \"Мир_ru_ed\"," +\
"\"fr-FR\": \"Monde_fr-FR_ed\", \"de\": \"Welt_de_ed\"}"}
res = self.call("EditLang", dataEdit)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
content = [{'tag': 'text', 'text': 'Hello, World_en_ed'}]
contentRu = [{'tag': 'text', 'text': 'Hello, Мир_ru_ed'}]
contentFr = [{'tag': 'text', 'text': 'Hello, Monde_fr-FR_ed'}]
contentDe = [{'tag': 'text', 'text': 'Hello, Welt_de_ed'}]
dictExp ={"default" : content, "ru": contentRu,
"fr": contentFr, "de": contentDe, "pe": content}
pContent = funcs.get_content(url, "page", namePage, "en", 1, token) # should be: en
ruPContent = funcs.get_content(url, "page", namePage, "ru", 1, token) # should be: ru
frPcontent = funcs.get_content(url, "page", namePage, "fr-FR", 1, token) # should be: fr-FR
dePcontent = funcs.get_content(url, "page", namePage, "de-DE", 1, token) # should be: de
pePcontent = funcs.get_content(url, "page", namePage, "pe", 1, token) # should be: en
dictCur = {"default" : pContent['tree'], "ru": ruPContent['tree'],
"fr": frPcontent['tree'], "de": dePcontent['tree'], "pe": pePcontent['tree']}
self.assertDictEqual(dictCur, dictExp, "One of langRes is faild")
def test_get_content_from_template(self):
data = {}
data["template"] = "SetVar(mytest, 100) Div(Body: #mytest#)"
asserts = ["tree"]
res = self.check_post_api("/content", data, asserts)
answerTree = {'tree': [{'tag': 'div', 'children': [{'tag': 'text', 'text': '100'}]}]}
self.assertEqual(answerTree, res)
def test_get_content_from_template_empty(self):
data = {}
data["template"] = ""
asserts = []
res = self.check_post_api("/content", data, asserts)
self.assertEqual(None, res)
def test_get_content_from_template_source(self):
data = {}
data["template"] = "SetVar(mytest, 100) Div(Body: #mytest#)"
data["source"] = "true"
asserts = ["tree"]
res = self.check_post_api("/content", data, asserts)
answerTree = {'tree': [{'tag': 'setvar', 'attr': {'name': 'mytest', 'value': '100'}}, {'tag': 'div', 'children': [{'tag': 'text', 'text': '#mytest#'}]}]}
self.assertEqual(answerTree, res)
def test_get_content_from_template_source_empty(self):
data = {}
data["template"] = ""
data["source"] = "true"
asserts = []
res = self.check_post_api("/content", data, asserts)
self.assertEqual(None, res)
def test_get_content_source(self):
# Create new page for test
name = "Page_" + utils.generate_random_name()
data = {}
data["Name"] = name
data["Value"] = "SetVar(a,\"Hello\") \n Div(Body: #a#)"
data["Conditions"] = "true"
data["Menu"] = "default_menu"
data["ApplicationId"] = 1
res = self.call("NewPage", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# Test
asserts = ["tree"]
res = self.check_post_api("/content/source/"+name, "", asserts)
childrenText = res["tree"][1]["children"][0]["text"]
self.assertEqual("#a#", childrenText)
def test_get_content_with_param_from_address_string(self):
# Create new page for test
name = "Page_" + utils.generate_random_name()
data = {}
data["Name"] = name
data["Value"] = "#test#"
data["Conditions"] = "true"
data["Menu"] = "default_menu"
data["ApplicationId"] = 1
res = self.call("NewPage", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# Test
param = "?test="
value = "hello123"
asserts = ["tree"]
res = self.check_post_api("/content/page/" + name + param + value, "", asserts)
self.assertEqual(value, res["tree"][0]["text"])
def test_get_content_from_another_ecosystem(self):
# create new ecosystem
ecosysName = "Ecosys_" + utils.generate_random_name()
data = {"Name": ecosysName}
res = self.call("NewEcosystem", data)
self.assertGreater(int(res), 0,
"BlockId is not generated: " + str(res))
ecosysNum = funcs.call_get_api(url + "/ecosystems/", "", token)["number"]
# login founder in new ecosystem
data2 = utils.login(url, prKey, 0, ecosysNum)
token2 = data2["jwtToken"]
# create page in new ecosystem
pageName = "Page_" + utils.generate_random_name()
pageText = "Page in "+str(ecosysNum)+" ecosystem"
pageValue = "Span("+pageText+")"
data = {"Name": pageName, "Value": pageValue, "ApplicationId": 1,
"Conditions": "true", "Menu": "default_menu"}
resp = utils.call_contract(url, prKey, "@1NewPage", data, token2)
status = utils.txstatus(url, pause, resp["hash"], token2)
self.assertGreater(int(status["blockid"]), 0,"BlockId is not generated: " + str(status))
# create menu in new ecosystem
menuName = "Menu_" + utils.generate_random_name()
menuTitle = "Test menu"
data = {"Name": menuName, "Value": "MenuItem(Title:\""+menuTitle+"\")", "ApplicationId": 1,
"Conditions": "true"}
resp = utils.call_contract(url, prKey, "@1NewMenu", data, token2)
status = utils.txstatus(url, pause, resp["hash"], token2)
self.assertGreater(int(status["blockid"]), 0, "BlockId is not generated: " + str(status))
# test
data = ""
asserts = ["tree"]
resPage = self.check_post_api("/content/page/@" + str(ecosysNum) + pageName, data, asserts)
resMenu = self.check_post_api("/content/menu/@" + str(ecosysNum) + menuName, data, asserts)
mustBe = dict(pageText=pageText,
menu=menuTitle)
expectedValue = dict(pageText=resPage["tree"][0]["children"][0]["text"],
menu=resMenu["tree"][0]["attr"]["title"])
self.assertEqual(mustBe, expectedValue, "Dictionaries are different!")
def test_get_back_api_version(self):
asserts = ["."]
data = ""
self.check_get_api("/version", data, asserts)
def test_get_systemparams_all_params(self):
asserts = ["list"]
res = self.check_get_api("/systemparams", "", asserts)
self.assertGreater(len(res["list"]), 0, "Count of systemparams not Greater 0: " + str(len(res["list"])))
def test_get_systemparams_some_param(self):
asserts = ["list"]
param = "gap_between_blocks"
res = self.check_get_api("/systemparams/?names=" + param, "", asserts)
self.assertEqual(1, len(res["list"]))
self.assertEqual(param, res["list"][0]["name"])
def test_get_systemparams_incorrect_param(self):
asserts = ["list"]
param = "not_exist_parameter"
res = self.check_get_api("/systemparams/?names="+param, "", asserts)
self.assertEqual(0, len(res["list"]))
def test_get_contracts(self):
limit = 25 # Default value without parameters
asserts = ["list"]
res = self.check_get_api("/contracts", "", asserts)
self.assertEqual(limit, len(res["list"]))
def test_get_contracts_limit(self):
limit = 3
asserts = ["list"]
res = self.check_get_api("/contracts/?limit="+str(limit), "", asserts)
self.assertEqual(limit, len(res["list"]))
def test_get_contracts_offset(self):
asserts = ["list"]
res = self.check_get_api("/contracts", "", asserts)
count = res["count"]
offset = count
res = self.check_get_api("/contracts/?offset=" + str(offset), "", asserts)
self.assertEqual(None, res["list"])
def test_get_contracts_empty(self):
limit = 1000
offset = 1000
asserts = ["list"]
res = self.check_get_api("/contracts/?limit="+str(limit)+"&offset="+str(offset), "", asserts)
self.assertEqual(None, res["list"])
def test_get_interface_page(self):
asserts = ["id"]
page = "default_page"
res = self.check_get_api("/interface/page/"+page, "", asserts)
self.assertEqual("default_page", res["name"])
def test_get_interface_page_incorrect(self):
asserts = ["error"]
page = "not_exist_page_xxxxxxxxxxx"
res = self.check_get_api("/interface/page/"+page, "", asserts)
self.assertEqual("Page not found", res["msg"])
def test_get_interface_menu(self):
asserts = ["id"]
menu = "default_menu"
res = self.check_get_api("/interface/menu/"+menu, "", asserts)
self.assertEqual("default_menu", res["name"])
def test_get_interface_menu_incorrect(self):
asserts = ["error"]
menu = "not_exist_menu_xxxxxxxxxxx"
res = self.check_get_api("/interface/menu/"+menu, "", asserts)
self.assertEqual("Page not found", res["msg"])
def test_get_interface_block(self):
# Add new block
block = "Block_" + utils.generate_random_name()
data = {"Name": block, "Value": "Hello page!", "ApplicationId": 1,
"Conditions": "true"}
res = self.call("NewBlock", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# Test
asserts = ["id"]
res = self.check_get_api("/interface/block/"+block, "", asserts)
self.assertEqual(block, res["name"])
def test_get_interface_block_incorrect(self):
asserts = ["error"]
block = "not_exist_block_xxxxxxxxxxx"
res = self.check_get_api("/interface/block/"+block, "", asserts)
self.assertEqual("Page not found", res["msg"])
def test_get_table_vde(self):
asserts = ["name"]
data = {"vde": "true"}
self.check_get_api("/table/contracts", data, asserts)
def test_create_vde(self):
asserts = ["result"]
data = {}
#self.check_post_api("/vde/create", data, asserts)
def is_node_owner_true(self):
data = {}
resp = utils.call_contract(url, prKey, "NodeOwnerCondition", data, token)
status = utils.txstatus(url, pause, resp["hash"], token)
self.assertGreater(int(status["blockid"]), 0,
"BlockId is not generated: " + str(status))
def is_node_owner_false(self):
keys = config.getKeys()
prKey2 = keys["key1"]
data2 = utils.login(url, prKey2, 0)
token2 = data2["jwtToken"]
data = {}
resp = utils.call_contract(url, prKey2, "NodeOwnerCondition", data, token2)
status = utils.txstatus(url, pause, resp["hash"], token2)
self.assertEqual(status["errmsg"]["error"],
"Sorry, you do not have access to this action.",
"Incorrect message: " + str(status))
def test_login(self):
keys = config.getKeys()
data1 = utils.login(url, keys["key5"], 0)
time.sleep(5)
conf = config.getNodeConfig()
res = utils.is_wallet_created(conf["1"]["dbHost"], conf["1"]["dbName"],
conf["1"]["login"], conf["1"]["pass"],
data1["key_id"])
self.assertTrue(res, "Wallet for new user didn't created")
def test_login2(self):
isOne = False
keys = config.getKeys()
data1 = utils.login(url, keys["key3"], 0)
time.sleep(5)
conf = config.getNodeConfig()
res = utils.is_wallet_created(conf["1"]["dbHost"], conf["1"]["dbName"],
conf["1"]["login"], conf["1"]["pass"],
data1["key_id"])
if res == True:
data2 = utils.login(url, keys["key1"], 0)
time.sleep(5)
isOne = utils.is_wallet_created(conf["1"]["dbHost"], conf["1"]["dbName"],
conf["1"]["login"], conf["1"]["pass"],
data2["key_id"])
self.assertTrue(isOne, "Wallet for new user didn't created")
def test_get_avatar_with_login(self):
# add file in binaries
name = "file_" + utils.generate_random_name()
path = os.path.join(os.getcwd(), "fixtures", "image2.jpg")
with open(path, 'rb') as f:
file = f.read()
files = {'Data': file}
data = {"Name": name, "ApplicationId": 1, "DataMimeType":"image/jpeg"}
resp = utils.call_contract_with_files(url, prKey, "UploadBinary", data,
files, token)
res = self.assertTxInBlock(resp, token)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# find last added file
asserts = ["count"]
res = self.check_get_api("/list/binaries", "", asserts)
lastRec = res["count"]
# find founder ID
asserts = ["list"]
res = self.check_get_api("/list/members", "", asserts)
# iterating response elements
i = 0
founderID = ""
while i < len(res['list']):
if res['list'][i]['member_name'] == "founder":
founderID = res['list'][i]['id']
i += 1
# change column permissions
data = {"TableName": "members",
"Name":"image_id",
"UpdatePerm": "true",
"ReadPerm": "true"}
res = self.call("EditColumn", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# update members table
code = """
{
data{}
conditions{}
action{
DBUpdate("members", %s, {image_id: "%s"})
}
}
""" % (founderID, lastRec)
code, name = utils.generate_name_and_code(code)
data = {"Value": code, "ApplicationId": 1,
"Conditions": "true"}
res = self.call("NewContract", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
data = {}
resp = utils.call_contract(url, prKey, name, data, token)
res = self.assertTxInBlock(resp, token)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# rollback changes column permissions
data = {"TableName": "members",
"Name":"image_id",
"UpdatePerm": "ContractAccess(\"Profile_Edit\")",
"ReadPerm": "true"}
res = self.call("EditColumn", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# test
ecosystemID = "1"
asserts = ""
data = ""
avaURL = url + "/avatar/" + ecosystemID + "/" + founderID
res = funcs.call_get_api_with_full_response(avaURL, data, asserts)
msg = "Content-Length is different!"
self.assertIn("71926", str(res.headers["Content-Length"]),msg)
def test_get_avatar_without_login(self):
# add file in binaries
name = "file_" + utils.generate_random_name()
path = os.path.join(os.getcwd(), "fixtures", "image2.jpg")
with open(path, 'rb') as f:
file = f.read()
files = {'Data': file}
data = {"Name": name, "ApplicationId": 1, "DataMimeType":"image/jpeg"}
resp = utils.call_contract_with_files(url, prKey, "UploadBinary", data,
files, token)
res = self.assertTxInBlock(resp, token)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# find last added file
asserts = ["count"]
res = self.check_get_api("/list/binaries", "", asserts)
lastRec = res["count"]
# find founder ID
asserts = ["list"]
res = self.check_get_api("/list/members", "", asserts)
# iterating response elements
i = 0
founderID = ""
while i < len(res['list']):
if res['list'][i]['member_name'] == "founder":
founderID = res['list'][i]['id']
i += 1
# change column permissions
data = {"TableName": "members",
"Name": "image_id",
"UpdatePerm": "true",
"ReadPerm": "true"}
res = self.call("EditColumn", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# update members table
code = """
{
data{}
conditions{}
action{
DBUpdate("members", %s, {image_id: "%s"})
}
}
""" % (founderID, lastRec)
code, name = utils.generate_name_and_code(code)
data = {"Value": code, "ApplicationId": 1,
"Conditions": "true"}
res = self.call("NewContract", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
data = {}
resp = utils.call_contract(url, prKey, name, data, token)
res = self.assertTxInBlock(resp, token)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# rollback changes column permissions
data = {"TableName": "members",
"Name":"image_id",
"UpdatePerm": "ContractAccess(\"Profile_Edit\")",
"ReadPerm": "true"}
res = self.call("EditColumn", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
# test
ecosystemID = "1"
avaURL = url + "/avatar/" + ecosystemID + "/" + founderID
resp = requests.get(avaURL)
msg = "Content-Length is different!"
self.assertIn("71926", str(resp.headers["Content-Length"]), msg)
def test_get_centrifugo_address_without_login(self):
resp = requests.get(url + '/config/centrifugo')
res = resp.json()
self.assertIn("ws://", res, "Centrifugo is not connection to node!")
def test_get_centrifugo_address_with_login(self):
asserts = ["ws://"]
data = ""
res = self.check_get_api("/config/centrifugo", data, asserts)
def test_content_hash(self):
# 1. test with login
# 2. test without login
# 3. negative test without login
def isHashNotEmpty(hash):
hash = str(hash)
if hash.find("{'hash':") != -1:
return True
else:
return False
name = "Page_" + utils.generate_random_name()
data = {"Name": name, "Value": "Div(,Hello page!)", "ApplicationId": 1,
"Conditions": "true", "Menu": "default_menu"}
res = self.call("NewPage", data)
self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
asserts = ["hash"]
authRes = self.check_post_api("/content/hash/" + name, "", asserts)
notAuthRes = requests.post(url + "/content/hash/" + name)
notAuthRes = notAuthRes.json()
page = "not_exist_page_xxxxxxxxx"
notAuthResNotExist = requests.post(url + "/content/hash/" + page)
notAuthResNotExist = notAuthResNotExist.json()
mustBe = dict(authRes=True,
notAuthRes=True,
msg="Page not found")
actual = dict(authRes=isHashNotEmpty(authRes),
notAuthRes=isHashNotEmpty(notAuthRes),
msg=notAuthResNotExist["msg"])
self.assertDictEqual(mustBe, actual, "Not all assertions passed in test_content_hash")
def test_get_ecosystem_name(self):
id = 1
asserts = ["ecosystem_name"]
self.check_get_api("/ecosystemname?id=" + str(id), "", asserts)
def test_get_ecosystem_name_new(self):
data = {"Name": "ecos_" + utils.generate_random_name()}
res = self.call("NewEcosystem",data)
id = self.check_get_api("/list/ecosystems", "", [])["count"]
asserts = ["ecosystem_name"]
self.check_get_api("/ecosystemname?id=" + str(id), "", asserts)
def test_get_ecosystem_name_incorrect(self):
id = 99999
asserts = ["error"]
self.check_get_api("/ecosystemname?id=" + str(id), "", asserts)
if __name__ == '__main__':
unittest.main()