20230525_接口自动化测试_作业

信计2002-杨佳宜 yangjiayi: 666666666666

信计2001马琪https://gitee.com/maqivt74/mq200350114.git

信计2002刘硕+https://gitee.com/liu-shuo-129/xinji-2002-liu-shuo-3.git

数据2102崔鑫通

信计2002朱丽棋接口自动化测试: 接口自动化测试111111

信计2002刘硕https://gitee.com/liu-shuo-129/xinji-2002-liu-shuo-3.git

信计2002王一诺:https://gitee.com/xinji-2002-wang-yinuo/wyn2.git

########zscaichifan: 实训代码

dgf

11

信计2001刘雨曦
liuyuxi-pytestday3: 刘雨曦200350106第三次作业

信计2001韦文博-----a1https://gitee.com/Micale_Wonderful/weiwenbo.git

信计2001何洪坤ahttps://gitee.com/he-hongkun/wang-wang-xiaoku.git

信计2001张欣如

信计2001 王大铸 200350118 接口自动化作业: wangdazhu: 信计2001王大铸200350118

信计2001 翟佳树

-- coding: utf-8 --

import requests
import allure
import json

class TestPet:
@staticmethod
def setup_class():

初始化测试数据

global test_pet_id
test_pet_id = 0

@staticmethod
def teardown_class():
#删除测试数据
url = f"https://petstore.swagger.io/v2/pet/{test_pet_id}"
res = requests.delete(url)
assert res.status_code == 200

@allure.step(“新增宠物”)
def test_add_pet(self):
url = “https://petstore.swagger.io/v2/pet
headers = {‘Content-Type’: ‘application/json’}
data = {“id”: 0000, “category”:
{“id”: 0000, “name”: “string”}, “name”: “testpet”, “photoUrls”:
[“string”], “tags”:
[{“id”: 0, “name”: “string”}], “status”: “available”}
res = requests.post(url, headers=headers,
data=json.dumps(data))
assert res.status_code == 200 or res.status_code == 201,
f"新增宠物接口异常,状态码为{res.status_code}"
global test_pet_id
test_pet_id =
res.json().get(‘id’) # 记录新增宠物id
allure.attach(str(data), “请求参数”)
allure.attach(str(res.json()), “响应结果”)

@allure.step(“查询宠物”)
def test_query_pet(self):
url = f"https://petstore.swagger.io/v2/pet/findByStatus?status=available"
res = requests.get(url)
assert res.status_code == 200, f"查询宠物接口异常,状态码为{res.status_code}"
allure.attach(str(res.json()), “查询返回结果”)