美文网首页
httprunner 3.X (15)upload

httprunner 3.X (15)upload

作者: Sandra_liu | 来源:发表于2022-01-19 22:25 被阅读0次

    debugtalk:添加get_login_token()方法

    def get_login_token():
        url = "https://api.testing.net/account/v1/login"
        json = {"account": "134287505XX", "password": "a123456"}
        headers = {"X-HB-Client-Type": "ios", "X-HB-Auth-Type": "token",
                   'Content-Type': 'application/json; charset=UTF-8'}
        r = requests.post(url, json=json, headers=headers, verify=False)
        print(r.json())
    
        user_id = r.json()["user_id"]
        token = r.json()["token"]
        token64 = str(user_id) + ":" + str(token)
        print(token64.encode("utf-8"))
        print(base64.b64encode(token64.encode("utf-8")))
        temp = base64.b64encode(token64.encode("utf-8"))
        tokens = "HBAPI" + " " + temp.decode("utf-8")
        print(tokens)
        return tokens
    

    用例:在header中调用debugtalk中添加的get_login_token()方法

    from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
    
    
    class TestCaseT2(HttpRunner):
        config = Config("上传图片") \
            .variables() \
            .verify(False)
    
    
        teststeps = [
            Step(
                RunRequest("")
                .post("https://api.testing.net/user/v1/babies/avatars")
                .with_headers(
                    **{
                        "authorization": "${get_login_token()}",
                        "x-hb-client-type": "android",
                        "Content-Type":"multipart/form-data",
                    }
                )
                .upload(**{"avatar": "data/avatar.png"})
                .with_cookies()
                .validate()
                .assert_equal("status_code", 200)
    
            ),
        ]
    
    
    if __name__ == "__main__":
        TestCaseT2().test_start()
    

    相关文章

      网友评论

          本文标题:httprunner 3.X (15)upload

          本文链接:https://www.haomeiwen.com/subject/ugxlhrtx.html