api: storage test interface
conftest.py : set pre-operation
Current pre-operations: 1. Obtain token and pass in headers, 2. Obtain command line parameters and give them to environment variables to specify the operating environment
commmon: store the public method of the package
connect_mysql.py: connect to the database
http_requests.py: encapsulate your own request method
logger.py: encapsulate the output log file
read_yaml.py: read the yaml file test case data
read_save_data.py: read the saved data file
case: store all test cases
data: store the data required for testing
save_data: store the interface return data, interface download files
test_data: store test case dependent data
upload_data: store upload interface files
logs: log files for storing output
report: store test output report
getpathinfo.py : Package project test path
pytest.int : configuration file
requirement.txt: local python package (pip install -r requirements.txt installs all python packages in the project)
run_main.py: Project running file
# 结构设计
1. Each interface use case is combined in a test class to generate a py file
2. Encapsulate the interface called by each use case in a test class to generate a py file
3. Store the test data in the yml file and parameterize it through parametrize to realize data drive
4. Generate a test report through allure
## 代码展示
api/api_service.py #需要测试的一类接口
'''
Code description: Service related interface
Create time: 2020/12/3
Developer: Ye Xiu
'''
import os
from common.http_requests import HttpRequests
class Api_Auth_Service(object):
def __init__(self):
self.headers = HttpRequests().headers
def api_home_service_list(self):
# 首页服务列表
# url = "http://192.168.2.199:9092/v1/auth/auth_service/findAuthService"
url = os.environ["host"] + "/v1/auth/auth_service/findAuthService" # 读取conftest.py文件地址进行拼接
response = HttpRequests().get(url, headers=self.headers, verify=False)
# print(response.json())
return response
def get_service_id(self):
#获取银行卡三要素认证服务id
url = "http://192.168.2.199:9092/v1/auth/auth_service/findAuthService"
#url = os.environ["host"] + "/v1/auth/auth_service/findAuthService" # 读取conftest.py文件地址进行拼接
response = HttpRequests().get(url,headers=self.headers)
#print(response.json()['data'][0]['service_list'][0]['id'])
service_id = response.json()['data'][0]['service_list'][1]['id']
return service_id
def api_service_info(self,serviceId='0b6cf45bec757afa7ee7209d30012ce1',developerId=''):
#服务详情
body = {
"serviceId" :serviceId,
"developerId":developerId
}
url = "http://192.168.2.199:9092/v1/auth/auth_service/findServiceDetail"
#url = os.environ["host"] + "/v1/auth/auth_service/findServiceDetail"#读取conftest.py文件地址进行拼接
response = HttpRequests().get(url,headers=self.headers,params = body,verify=False)
#print(response.json())
return response
def api_add_or_update_service(self,api_param_req,api_param_res,description,error_code,icon,id,interface_remarks,
name,product_info,request_method,sample_code,sort,type,url):
#服务添加或者更新
body={
"api_param_req": api_param_req,
"api_param_res": api_param_res,
"description": description,
"error_code": error_code,
"icon": icon,
"id": id,
"interface_remarks": interface_remarks,
"name": name,
"product_info": product_info,
"request_method": request_method,
"sample_code": sample_code,
"sort": sort,
"type": type,
"url": url,
}
#url = "http://192.168.2.199:9092/v1/auth/auth_service/insertOrUpdateService"
url = os.environ["host"] + "/v1/auth/auth_service/insertOrUpdateService" # 读取conftest.py文件地址进行拼接
response = HttpRequests().post(url,json=body,headers=self.headers,verify=False)
return response
def api_add_service_price(self,id,max_number,money,service_id,small_number):
#服务价格添加
body = {
"id": id,
"max_number": max_number,
"money": money,
"service_id": service_id,
"small_number": small_number
}
# url = "http://192.168.2.199:9092/v1/auth/auth_service/insertServicePrice"
url = os.environ["host"] + "/v1/auth/auth_service/insertServicePrice" # 读取conftest.py文件地址进行拼接
response = HttpRequests().post(url, json=body, headers=self.headers, verify=False)
return response
def api_apply_service(self,developer_id,service_id):
#申请服务
body ={
"developer_id": developer_id,
"service_id": service_id
}
# url = "http://192.168.2.199:9092/v1/auth/auth_service/applyService"
url = os.environ["host"] + "/v1/auth/auth_service/applyService" # 读取conftest.py文件地址进行拼接
response = HttpRequests().post(url, json=body, headers=self.headers, verify=False)
return response
if name == ‘main’:
#Auth_Service().api_home_service_list()
Api_Auth_Service().get_service_id()
#Auth_Service().api_service_info()
api_service.py
**最后:下方这份完整的软件测试视频学习教程已经整理上传完成,朋友们如果需要可以自行免费领取 【保证100%免费】**
![](https://img-blog.csdnimg.cn/5de4729f538d4c8e8774f46cbc48891f.png#pic_center)
![在这里插入图片描述](https://img-blog.csdnimg.cn/1b48e1bf50c947a0b047dab446f9a23a.png#pic_center)