python多接口测试

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

python多接口测试

# -*- coding:utf-8 -*-

import requests import json import unittest

class TestTruck(unittest.TestCase): @classmethod

def setUpClass(self):

print"---setUpClass---"

def test_login(self):

'''获取token,需要图形验证码'''

url = "http://192.168.3.21:30226/auth/token/profile/get/"

headers = {'Content-Type':'application/json;charset=UTF-8'}

request_param = {

'username' : '10086',

'password' : '10086',

'captcha':'XHUV',

'hashkey':'7265011fcd710066653b8615fb0fbb8ef44652a8'

}

response = requests.post(url, data=json.dumps(request_param), headers=headers) # print response.json()['token']

def auth_token_get(self):

'''直接获取token,跳过图形验证码'''

url = "http://192.168.3.21:30226/auth/token/get/"

request_param = {

'username' : '10086',

'password' : '10086'

}

response = requests.post(url,data = request_param)

token = response.json()['token']

return token

def test_truck_engine_factory(self):

'''发动机厂家接口,需token认证'''

token = auth_token_get(self)

Authorization = 'JWT ' + token

# print Authorization

# print token

url = "http://xx:30226/truck/engine_factory/"

request_param = {

'page' : '1',

'page_size' : '999'

}

headers = {

'Content-Type':'application/json;charset=UTF-8',

'Authorization':Authorization

}

response = requests.get(url,data=json.dumps(request_param),headers=headers) print response.text

@classmethod

def setDownClass(self):

print"---setDownClass---"

if __name__ == "__main__":

unittest.main()

相关文档
最新文档