学校管理系统接口测试基本流
# 引入模块requests与random
import requests
import random
import json
# 管理系统父路径
SMS_Url = "http://192.168.233.128:8080/recruit.students/school/manage"
## 登录系统
# 学校管理系统登录页路径
SMS_LoginUrl = "http://192.168.233.128:8080/recruit.students/login/in"
# 登录get请求的params参数
LoginParams = {
"account": "admin",
"pwd": "660B8D2D5359FF6F94F8D3345698F88C"
}
# 使用requests模块的Session方法构建一个用于保持登录状态的SMS_LoginKeep实例对象
SMS_LoginKeep = requests.Session()
# 构建,发送登录get请求
SMS_LoginKeep.get(url = SMS_LoginUrl, params = LoginParams)
## 新建学校
# 管理系统新建学校子路径
SMS_AddUrl = "/addSchoolInfo"
# 一个随机学校名和一个随机备注
SchoolNameRandom = random.randint(1, 1000000000)
RemarkRandom = random.randint(1, 100000)
# 新建学校post请求的body参数
SchoolAddBody = {
"schoolName": SchoolNameRandom,
"listSchoolType[0].id": 2,
"canRecruit": 1,
"remark": RemarkRandom
}
# 构建,发送新建学校post请求
RespondOfSchoolAdd = SMS_LoginKeep.post(url = SMS_Url + SMS_AddUrl, data = SchoolAddBody)
# 新建学校后响应新学校信息的json转为字典储存在NewSchoolInfoDict
NewSchoolInfoDict = RespondOfSchoolAdd.json()
## 禁用学校
# 管理系统禁用学校子路径
SMS_EnableOrDisableUrl = "/enableOrDisableSchool"
# 禁用学校post请求的body参数
SchoolDisableBody = [{"id": NewSchoolInfoDict["data"]["laccount"], "disable": 0, "schoolId": NewSchoolInfoDict["data"]["id"]}]
# 构建,发送启用或禁用学校的post请求
SMS_EnableOrDisable = SMS_LoginKeep.post(url = SMS_Url + SMS_EnableOrDisableUrl, json = SchoolDisableBody)
print(SMS_EnableOrDisable.text)
## 设置学生录入时间
# 设置学生录入时间子路径 以下未写
SMS_SetStudentsRecruitTimeUrl = "/setStudentRecruitTime"
# 更改学生录入时间
# 更改学校为自主招生
# SMS_SetSchoolself = SMS_LoginKeep.post(url = )
shop商场 项目主要流程
# 引入requests模块
import requests
# Url:登录请求路径
Url = "http://192.168.233.128/xiaoqiangshop/user.php"
# LoginBody:登录的body参数
LoginBody = {
"username": "admin",
"password": "test123",
"remember": "1",
"act": "act_login",
"back_act": "http%3A%2F%2F192.168.233.128%2Fxiaoqiangshop%2Findex.php&submit="
}
# GoodsUrl商品查询路径
GoodsUrl = "http://192.168.233.128/xiaoqiangshop/goods.php"
# 查询id为134的商品的params参数
GoodNum134 = {
"id": "134"
}
# 加入购物车步骤的路径
AddToCartAndCheck = "http://192.168.233.128/xiaoqiangshop/flow.php"
# 加入购物车的params参数
ParAddInCart = {
"step": "add_to_cart"
}
# 商品id为134加入购物车的body参数
AddToCart134 = {
"goods": '{"quick": 1, "spec": [], "goods_id": 134, "number": "1", "parent": 0}'
}
# 查看购物车的params参数
Cart = {
"step": "cart"
}
# 结算中心的params参数
Check = {
"step": "checkout"
}
# 提交订单的params参数
Done = {
"step": "done"
}
# 提交订单的body参数
DoneBody = {
"shipping": 1,
"payment": 1,
"bonus": 0,
"bonus_sn": [],
"postscript": [],
"how_oos": 0,
"x": 50,
"y": 40,
"step": "done"
}
# 使用requests模块中的Session方法构建一个Session对象,命名为RequestSession,使用RequestSession可以保持登录状态
RequestSession = requests.Session()
# 使用RequestSession对象的post方法向登录页发送post请求
RequestSession.post(url = Url, data = LoginBody)
# 保持登录状态下使用get方法取得指定商品id的商品展示页
RequestSession.get(url=GoodsUrl, params=GoodNum134)
# 将商品id为134的商品加入购物车
RequestSession.post(url = AddToCartAndCheck, params = ParAddInCart, data = AddToCart134)
# 进入结算中心
RequestSession.get(url = AddToCartAndCheck, params = Check)
# 提交订单
RequestSession.post(url=AddToCartAndCheck, params=Done, data = DoneBody)