Пример #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 addBinary(self):
     name = "image_" + 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}
     resp = utils.call_contract_with_files(url, prKey, "UploadBinary", data,
                                           files, token)
     res = utils.txstatus(url, waitTx, resp['hash'], token)
     self.assertGreater(int(res['blockid']), 0,
                        "BlockId is not generated: " + str(res))
Пример #3
0
def updateProfile(name, url, prKey, token):
    time.sleep(5)
    path = os.path.join(os.getcwd(), "fixtures", "image2.jpg")
    with open(path, 'rb') as f:
        file = f.read()
    files = {'member_image': file}
    data = {"member_name": name}
    resp = utils.call_contract_with_files(url, prKey, "ProfileEdit", data,
                                          files, token)
    if not isInBlock(resp, url, token):
        print("UpdateProfile " + name + " is failed")
        exit(1)
Пример #4
0
 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)