예제 #1
0
def impApp(appName, url, prKey, token):
    path = os.path.join(os.getcwd(), "fixtures", "basic", appName + ".json")
    with open(path, 'r', encoding="utf8") as f:
        file = f.read()
    files = {'input_file': file}
    resp = utils.call_contract_with_files(url, prKey, "ImportUpload", {},
                                          files, token)
    if ("hash" in resp):
        resImportUpload = utils.txstatus(url, 30, resp["hash"], token)
        if int(resImportUpload["blockid"]) > 0:
            founderID = funcs.call_get_api(
                url + "/ecosystemparam/founder_account/", "", token)['value']
            result = funcs.call_get_api(url + "/list/buffer_data", "", token)
            buferDataList = result['list']
            for item in buferDataList:
                if item['key'] == "import" and item['member_id'] == founderID:
                    importAppData = json.loads(item['value'])['data']
                    break
            contractName = "Import"
            data = [{
                "contract": contractName,
                "params": importAppData[i]
            } for i in range(len(importAppData))]
            resp = utils.call_multi_contract(url, prKey, contractName, data,
                                             token)
            time.sleep(30)
            if "hashes" in resp:
                hashes = resp['hashes']
                result = utils.txstatus_multi(url, 30, hashes, token)
                for status in result.values():
                    print(status)
                    if int(status["blockid"]) < 1:
                        print("Import is failed")
                        exit(1)
                print("App '" + appName + "' successfully installed")
예제 #2
0
 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")
예제 #3
0
 def test_rollback1(self):
     # Install apps
     self.impApp("admin", url, prKey, token)
     self.impApp("system_parameters", url, prKey, token)
     print("Start rollback test")
     self.addNotification()
     self.addBinary()
     tableName = self.addUserTable()
     self.insertToUserTable(tableName)
     # Save to file block id for rollback
     rollbackBlockId = funcs.get_max_block_id(url, token)
     file = os.path.join(os.getcwd(), "blockId.txt")
     with open(file, 'w') as f:
         f.write(str(rollbackBlockId))
     # Save to file user table name
     tableNameWithPrefix = "1_" + tableName
     file = os.path.join(os.getcwd(), "userTableName.txt")
     with open(file, 'w') as f:
         f.write(tableNameWithPrefix)
     # Save to file user table state
     dbUserTableInfo = utils.getUserTableState(host, db, login, pas,
                                               tableNameWithPrefix)
     file = os.path.join(os.getcwd(), "dbUserTableState.json")
     with open(file, 'w') as fconf:
         json.dump(dbUserTableInfo, fconf)
     # Save to file all tables state
     dbInformation = utils.getCountDBObjects(host, db, login, pas)
     file = os.path.join(os.getcwd(), "dbState.json")
     with open(file, 'w') as fconf:
         json.dump(dbInformation, fconf)
     self.updateUserTable(tableName)
     self.money_transfer()
     contract, code = self.create_contract("")
     self.edit_contract(contract, code)
     self.activate_contract(contract)
     self.deactivate_contract(contract)
     param = self.new_parameter()
     self.edit_parameter(param)
     menu = self.new_menu()
     self.edit_menu()
     self.append_memu()
     self.new_page()
     self.edit_page()
     self.append_page()
     self.new_block()
     self.edit_block()
     table = self.new_table()
     self.edit_table(table)
     column = self.new_column(table)
     self.edit_column(table, column)
     lang = self.new_lang()
     langs = funcs.call_get_api(url + "/list/languages", {}, token)
     self.edit_lang(langs["count"], lang)
     sign = self.new_sign()
     self.edit_sign(sign)
     self.impApp("basic", url, prKey, token)
     time.sleep(20)
예제 #4
0
 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!")
예제 #5
0
 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")
예제 #6
0
 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
예제 #7
0
 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