Esempio n. 1
0
 def testinterface(self):
     self.data = openExecle(r".\Data\tacase.xlsx", "test_denglu")
     listpram = self.data.get_pram()
     listurl = self.data.get_url()
     listurl2 = self.data.get_url2()
     listmeth = self.data.get_meth()
     listcode = self.data.get_code()
     listmsg = self.data.get_msg()
     listid = self.data.get_id()
     listname = self.data.get_name()
     listresult = []
     listjson = []
     list_pass = 0
     list_fail = 0
     list_url = []
     for i in range(len(listurl)):
         request = reqs(url=listurl[i] + listurl2[i],
                        pram=listpram[i],
                        fangshi=listmeth[i])
         code, json = request.testapi()
         if code == listcode[i] and json['msg'] == listmsg[i]:
             list_pass += 1
             listresult.append("pass")
             listjson.append(json)
         else:
             list_fail += 1
             listresult.append("fail")
             listjson.append(json)
         list_url.append(listurl[i] + listurl2[i])
     return list_fail, list_pass, listid, listname, list_url, listmeth, listpram, listcode, listmsg, listresult, listjson
Esempio n. 2
0
 def setUp(self):
     requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
     self.openexecle = openExecle(r'.\Data\tacase.xlsx', 'test_denglu')
     self.headers = {
         "Content-Type":
         "application/json; charset=utf-8",
         "User-Agent":
         "Dalvik/2.1.0 (Linux; U; Android 8.1.0; vivo X21i A Build/O11019)"
     }
     self.exturl = '&appType=1&tenant=tianan&'
Esempio n. 3
0
def login(url, pram):
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    headers = {
        "Content-Type":
        "application/json; charset=utf-8",
        "User-Agent":
        "Dalvik/2.1.0 (Linux; U; Android 8.1.0; vivo X21i A Build/O11019)"
    }
    r = requests.post(url, data=pram, headers=headers, verify=False)
    session = r.headers["Set-Cookie"]
    json = r.json()
    userid = json["data"]["userId"]
    return session, userid


def write_token(session):
    curpath = os.path.dirname(os.path.dirname(__file__))
    ypath = os.path.join(curpath, "Data", "token.yaml")
    t = {"Cookie": session}
    with open(ypath, "w", encoding="utf-8") as f:
        yaml.dump(t, f, Dumper=yaml.RoundTripDumper)


if __name__ == "__main__":
    readdata = openExecle(r'..\Data\testcase.xlsx', 'test_denglu')
    url = readdata.sheet.row(10)[3].value
    pram = readdata.sheet.row(10)[6].value
    session, userid = login(url, pram)
    print(session)
    write_token(session)