FINN
(FINN)
22
202041404219 吴泽祺
import requests
from requests import Session
class TestPet:
def setup(self):
self.proxys = {
“http”: “127.0.0.1: 7890”,
“https”: “127.0.0.1: 7890”
}
self.verify = False
# self.session = Session()
# self.session.proxies = {
# "http": "127.0.0.1: 7890",
# "https": "127.0.0.1: 7890"
# }
# self.session.verify = False
self.pet_json={
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.base_url="https://petstore.swagger.io/v2/pet"
def test_pet_get(self):
except_number = 10
# 获取宠物信息
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(resp.json()) >= except_number
def test_pet_add(self):
# 添加宠物信息
pet_name_add = "dog111111"
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = pet_name_add
resp = requests.post(pet_add_url,json=pet_add_json,verify=self.verify)
assert resp.json()["name"] == pet_name_add
def test_pet_update(self):
dog_name_update = "dog222222"
# 更新宠物信息之前先添加宠物信息
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "dog111111"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
resp = requests.put(pet_update_url,json=pet_update_json,verify=self.verify)
print(resp.json())
assert resp.json()["name"] == dog_name_update
def test_pet_delete(self):
# 删除宠物信息之前先添加宠物信息
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "dog111111"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = requests.delete(pet_delete_url,verify=self.verify)
assert resp.json()["message"] == str(pet_id)
彭子晴 202041404120
import requests
from requests import Session
class TestPet:
def setup(self):
self.pet_json = {
“id”: 202041404120,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “pzq202041404120”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
# self.proxys = {
# “http”: “127.0.0.1:8888”,
# “https”: “127.0.0.1:8888”
# }
self.base_url = “https://petstore.swagger.io/v2/pet”
self.verify = False
def test_pet_get(self):
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify, )
assert len(resp.json()) >= except_number
def test_pet_add(self):
dog_name = "pzq202041404120"
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = dog_name
resp = requests.post(pet_add_url, json=pet_add_json, verify=self.verify)
assert resp.json()["name"] == dog_name
def test_pet_update(self):
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "pzq202041404120"
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "pzq202041404120"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
pet_update_json["id"] = pet_id
pet_update_json["name"] = "pzq202041404120"
resp = requests.put(pet_update_url, json=pet_update_json, verify=self.verify)
assert resp.json()["name"] == dog_name_update
def test_pet_delete(self):
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "pzq"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = requests.delete(pet_delete_url, verify=self.verify)
assert resp.json()["message"] == str(pet_id)
Huzz
(Huzz)
25
202041404109 胡智
def setup(self):
self.session = Session()
self.session.verify = False
self.base_url = “https://petstore.swagger.io/v2/pet”
self.base_json = {
“id”: 0,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
def test_pet_get(self):
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
“status”: “available”,
}
resp = self.session.get(pet_get_url, params=url_param)
print(resp.text)
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
resp = self.session.post(pet_add_url, json=pet_add_json)
assert resp.status_code == 200
def test_pet_update(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.base_json
pet_update_json['id'] = pet_id
pet_update_json['name'] = "dog"
resp = self.session.put(pet_update_url, json=pet_update_json, verify=False)
assert resp.json()['name'] == "dog"
def test_pet_delete(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
# 删除宠物信息
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = self.session.delete(pet_delete_url)
assert resp.status_code == 200
Andy2
(Andy)
26
202041404214刘均豪
import requests
from requests import Session
class TestPet:
def setup(self):
self.proxys = {
“http”:“127.0.0.1: 7890”,
“https”:“127.0.0.1: 7890”
}self.verify = False
# self.session = Session()
# self.session.proxies = {
# "http": "127.0.0.1: 7890",
# "https": "127.0.0.1: 7890"
# }
# self.session.verify = False
self.pet_json={
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.base_url="https://petstore.swagger.io/v2/pet"
def test_pet_get(self):
except_number = 10
# 获取宠物信息
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
“status”: “available”
}
resp = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(resp.json()) >= except_number
def test_pet_add(self):
# 添加宠物信息
pet_name_add = “dog111111”
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
pet_add_json[“name”] = pet_name_add
resp = requests.post(pet_add_url,json=pet_add_json,verify=self.verify)
assert resp.json()[“name”] == pet_name_add
import requests
class TestPet:
def setup(self):
self.base_url = "https://petstore.swagger.io/v2/pet"
self.verify = False
self.pet_json = {
"id": 202041412221,
"category": {
"id": 0,
"name": "string"
},
"name": "202041412221rkl",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
# 获取宠物信息
def test_pet_get(self):
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
response = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(response.json()) >= except_number
# 添加宠物信息
def test_pet_add(self):
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
dog_name = "202041412221rkl"
pet_add_json["name"] = dog_name
response = requests.post(pet_add_url, json=pet_add_json, verify=self.verify)
assert response.json()["name"] == dog_name
# 更新宠物信息
def test_pet_update(self):
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "dog"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041412221rkl"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 根据用户id修改用户name
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
response = requests.put(pet_update_url, json=pet_update_json, verify=self.verify)
assert response.json()["name"] == dog_name_update
# 新增宠物用于更新
def test_pet_delete(self):
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041412221rkl"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
response = requests.delete(pet_delete_url, verify=self.verify)
# 判断是否删除成功
assert response.json()["message"] == str(pet_id)
JS1
(JS)
30
202041404213 刘建升
import requests
from requests import Session
class TestPet:
def setup(self):
self.proxys = {
“http”: “127.0.0.1:8888”,
“https”: “127.0.0.1:8888”
}
self.pet_json = {
“id”: 202041404213,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “ljs202041404213”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
self.base_url = “https://petstore.swagger.io/v2/pet”
self.verify = False
# self.verify = False
# self.session = Session()
# self.session.proxies = {
#
# }
# self.session.verify = False
def test_pet_get(self):
# 获取宠物信息
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify, proxies=self.proxys)
assert len(resp.json()) >= except_number
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
dog_name = "ljs202041404213"
pet_add_json["name"] = dog_name
resp = requests.post(pet_add_url, json=pet_add_json, verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == dog_name
def test_pet_update(self):
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "dog"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "ljs202041404213"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 根据用户id修改用户name
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
resp = requests.put(pet_update_url, json=pet_update_json, verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == dog_name_update
def test_pet_delete(self):
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "ljs202041404213"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = requests.delete(pet_delete_url, verify=self.verify, proxies=self.proxys)
# 判断是否删除成功
assert resp.json()["message"] == str(pet_id)
zzz1
31
202041404218 吴宏杰
import requests
from requests import Session
class Test_pet():
def setup(self):
self.proxys={
“http”: “127.0.0.1:8888”,
“https”: “127.0.0.1:8888”
}
self.verify=False
self.basr_url=“https://petstore.swagger.io/v2/pet”
self.pet_json = {
“id”: 0,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “zzz1”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
self.url_param = {
“status”: “available”
}
def test_pet_get(self):
获取宠物信息
pet_get_url = f"{self.basr_url}/findByStatus"
resp = requests.get(pet_get_url, self.url_param, verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.status_code == 200
def test_pet_add(self):
添加宠物信息
pet_add_json = self.pet_json.copy()
pet_add_json[“id”] = 0
pet_add_json[“name”] = “monkey”
resp = requests.post(self.basr_url,json=pet_add_json,verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()[“name”] == pet_add_json[“name”]
def test_pet_update(self):
# 更新宠物信息
pet_update_json=self.pet_json.copy()
pet_update_json["id"]=559
pet_update_json["name"]="dog"
resp = requests.put(self.basr_url,json=pet_update_json,verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()["name"]==pet_update_json["name"]
def test_pet_delete(self):
# 删除宠物信息
pet_add_json = self.pet_json.copy()
pet_id = requests.post(self.basr_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
pet_delete_url = f"{self.basr_url}/{pet_id}"
resp = requests.delete(pet_delete_url,verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()["message"]==str(pet_id)
gscsd
(gscsd)
33
202041404211 李范佑
import requests
from requests import Session
class TestPet:
def setup(self):
self.proxys = {
"http": "127.0.0.1:8888",
"https": "127.0.0.1:8888"
}
self.pet_json = {
"id": 202041404211,
"category": {
"id": 0,
"name": "string"
},
"name": "lfy",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.base_url = "https://petstore.swagger.io/v2/pet"
self.verify = False
# self.verify = False
# self.session = Session()
# self.session.proxies = {
#
# }
# self.session.verify = False
def test_pet_get(self):
# 获取宠物信息
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify, proxies=self.proxys)
assert len(resp.json()) >= except_number
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
dog_name = "ncf202041412218"
pet_add_json["name"] = dog_name
resp = requests.post(pet_add_url, json=pet_add_json, verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == dog_name
def test_pet_update(self):
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "dog"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "ncf202041412218"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 根据用户id修改用户name
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
resp = requests.put(pet_update_url, json=pet_update_json, verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == dog_name_update
def test_pet_delete(self):
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "ncf202041412218"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = requests.delete(pet_delete_url, verify=self.verify, proxies=self.proxys)
# 判断是否删除成功
assert resp.json()["message"] == str(pet_id)
CJX
34
202041404202陈杰选
test_pet.py
import requests
class TestPet:
def setup(self):
self.base_url = "https://petstore.swagger.io/v2/pet"
self.proxys = {
"http": "127.0.0.1:8888",
"https": "127.0.0.1:8888"
}
self.pet_json = {
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "cjx202041404202",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.verify = False
def test_pet_get(self):
# 获取宠物信息
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify, proxies=self.proxys)
print(resp.json())
assert len(resp.json()) >= 1
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
pet_add_json = self.pet_json
resp = requests.post(pet_add_url, json=pet_add_json, verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()["name"] == "cjx202041404202"
def test_pet_update(self):
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.pet_json
pet_name_update = "pet"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "cjx202041404202"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 根据id修改name
pet_update_json["id"] = pet_id
pet_update_json["name"] = pet_name_update
resp = requests.put(pet_update_url, json=pet_update_json, verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()["name"] == pet_name_update
def test_pet_delete(self):
# 新增宠物用于删除
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "cjx202041404202"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
# 删除宠物信息
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = requests.delete(pet_delete_url, verify=self.verify, proxies=self.proxys)
print(resp.json())
assert resp.json()["message"] == str(pet_id)
JS1
(JS)
35
202041404213 刘建升
def setup(self):
self.session = Session()
self.session.verify = False
self.base_url = “https://petstore.swagger.io/v2/pet”
self.base_json = {
“id”: 0,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
def test_pet_get(self):
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
“status”: “available”,
}
resp = self.session.get(pet_get_url, params=url_param)
print(resp.text)
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
resp = self.session.post(pet_add_url, json=pet_add_json)
assert resp.status_code == 200
def test_pet_update(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.base_json
pet_update_json['id'] = pet_id
pet_update_json['name'] = "dog"
resp = self.session.put(pet_update_url, json=pet_update_json, verify=False)
assert resp.json()['name'] == "dog"
def test_pet_delete(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
# 删除宠物信息
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = self.session.delete(pet_delete_url)
assert resp.status_code == 200
202041404217 万晋江
class TestPet:
def setup(self):
self.base_url = "https://petstore.swagger.io/v2/pet"
self.verify = False
self.pet_json = {
"id": 202041412221,
"category": {
"id": 0,
"name": "string"
},
"name": "202041412221rkl",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
# 获取宠物信息
def test_pet_get(self):
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
response = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(response.json()) >= except_number
# 添加宠物信息
def test_pet_add(self):
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
dog_name = "202041404217"
pet_add_json["name"] = dog_name
response = requests.post(pet_add_url, json=pet_add_json, verify=self.verify)
assert response.json()["name"] == dog_name
# 更新宠物信息
def test_pet_update(self):
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "dog"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041412221rkl"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 根据用户id修改用户name
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
response = requests.put(pet_update_url, json=pet_update_json, verify=self.verify)
assert response.json()["name"] == dog_name_update
# 新增宠物用于更新
def test_pet_delete(self):
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041404217"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
response = requests.delete(pet_delete_url, verify=self.verify)
# 判断是否删除成功
assert response.json()["message"] == str(pet_id)
黄枝沛202041404206
http”:“127.0.0.1: 7890”,
“https”:“127.0.0.1: 7890”
}self.verify = False
# self.session = Session()
# self.session.proxies = {
# "http": "127.0.0.1: 7890",
# "https": "127.0.0.1: 7890"
# }
# self.session.verify = False
self.pet_json={
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.base_url="https://petstore.swagger.io/v2/pet"
def test_pet_get(self):
except_number = 10
获取宠物信息
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
“status”: “available”
}
resp = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(resp.json()) >= except_number
def test_pet_add(self):
添加宠物信息
pet_name_add = “dog111111”
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
pet_add_json[“name”] = pet_name_add
resp = requests.post(pet_add_url,json=pet_add_json,verify=self.verify)
assert resp.json()[“name”] == pet_name_add
XThron
(XThron)
38
谢世龙 202041412121
import requests
class TestPet:
def setup(self):
self.base_url = "https://petstore.swagger.io/v2/pet"
self.verify = False
self.pet_json = {
"id": 202041412221,
"category": {
"id": 0,
"name": "string"
},
"name": "202041412221rkl",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
# 获取宠物信息
def test_pet_get(self):
except_number = 10
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
"status": "available"
}
response = requests.get(pet_get_url, url_param, verify=self.verify)
assert len(response.json()) >= except_number
# 添加宠物信息
def test_pet_add(self):
pet_add_url = self.base_url
pet_add_json = self.pet_json.copy()
dog_name = "202041412221rkl"
pet_add_json["name"] = dog_name
response = requests.post(pet_add_url, json=pet_add_json, verify=self.verify)
assert response.json()["name"] == dog_name
# 更新宠物信息
def test_pet_update(self):
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
dog_name_update = "dog"
# 新增宠物用于更新
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041412221rkl"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 根据用户id修改用户name
pet_update_json["id"] = pet_id
pet_update_json["name"] = dog_name_update
response = requests.put(pet_update_url, json=pet_update_json, verify=self.verify)
assert response.json()["name"] == dog_name_update
# 新增宠物用于更新
def test_pet_delete(self):
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "202041412221rkl"
pet_id = requests.post(self.base_url, json=pet_add_json, verify=self.verify).json()["id"]
# 删除宠物信息
pet_id = pet_id
pet_delete_url = f"{self.base_url}/{pet_id}"
response = requests.delete(pet_delete_url, verify=self.verify)
# 判断是否删除成功
assert response.json()["message"] == str(pet_id)
202041413221 叶磊
import requests
from requests import Session
class TestPet:
def setup(self):
self.base_url = "https://petstore.swagger.io/v2/pet"
self.pet_json = {
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
self.proxys = {
"http": "127.0.0.1:8888",
"https": "127.0.0.1:8888"
}
self.verify = False
# self.session = Session()
# self.session.proxies = {
# "http": "127.0.0.1:8888",
# "https": "127.0.0.1:8888"
# }
# self.session.verify = False
def test_pet_get(self):
# 获取宠物信息
pet_get_url = self.base_url + "/findByStatus"
url_param = {
"status": "available"
}
resp = requests.get(pet_get_url, url_param, verify=self.verify, proxies=self.proxys)
assert resp.status_code == 200
def test_pet_add(self):
# 添加宠物信息
pet_add_url = self.base_url
#深拷贝
pet_add_json = self.pet_json.copy()
pet_add_json["name"] = "dog"
resp = requests.post(pet_add_url,json=pet_add_json,verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == pet_add_json["name"]
def test_pet_update(self):
# 更新宠物信息
pet_update_url = self.base_url
pet_update_json = self.pet_json.copy()
pet_update_json["name"] = "dog and cat"
pet_add_json = self.pet_json.copy()
pet_update_json["id"] = requests.post(self.base_url, json=pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
resp = requests.put(pet_update_url,json=pet_update_json,verify=self.verify, proxies=self.proxys)
assert resp.json()["name"] == pet_update_json["name"]
def test_pet_delete(self):
# 删除宠物信息
pet_add_json = self.pet_json.copy()
pet_id = requests.post(self.base_url, json= pet_add_json, verify=self.verify, proxies=self.proxys).json()["id"]
pet_delete_url = self.base_url + f"/{pet_id}"
resp = requests.delete(pet_delete_url,verify=self.verify, proxies=self.proxys)
#message的id为string, pet_id为int
assert resp.json()["message"] == str(pet_id)
201941412218 魏峰
def setup(self):
self.session = Session()
self.session.verify = False
self.base_url = “https://petstore.swagger.io/v2/pet”
self.base_json = {
“id”: 0,
“category”: {
“id”: 0,
“name”: “string”
},
“name”: “”,
“photoUrls”: [
“string”
],
“tags”: [
{
“id”: 0,
“name”: “string”
}
],
“status”: “available”
}
def test_pet_get(self):
pet_get_url = f"{self.base_url}/findByStatus"
url_param = {
“status”: “available”,
}
resp = self.session.get(pet_get_url, params=url_param)
print(resp.text)
def test_pet_add(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
resp = self.session.post(pet_add_url, json=pet_add_json)
assert resp.status_code == 200
def test_pet_update(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
pet_update_url = self.base_url
pet_update_json = self.base_json
pet_update_json['id'] = pet_id
pet_update_json['name'] = "dog"
resp = self.session.put(pet_update_url, json=pet_update_json, verify=False)
assert resp.json()['name'] == "dog"
def test_pet_delete(self):
pet_add_url = self.base_url
pet_add_json = self.base_json
pet_add_json[“name”] = “dog123”
pet_id = self.session.post(pet_add_url, json=pet_add_json).json()[‘id’]
pet_delete_url = f"{self.base_url}/{pet_id}"
resp = self.session.delete(pet_delete_url)
assert resp.status_code == 200