接口测试
数据2102崔鑫通
接口测试
信计2002刘冬冬
import requests
import pytest
import allure
PET_BASE_URL = 'https://example.com/pet'
FIND_BY_STATUS_URL = PET_BASE_URL + '/findByStatus'
@pytest.fixture
def pet_data():
return {
"name": "cute dog",
"photoUrls": ["https://example.com/photo/1", "https://example.com/photo/2"],
"status": "available"
}
@allure.step('发送新增宠物请求')
def create_pet(pet_data):
response = requests.post(PET_BASE_URL, json=pet_data)
return response
@allure.step('发送查询宠物请求')
def find_pet(status='available'):
params = {'status': status}
response = requests.get(FIND_BY_STATUS_URL, params=params)
return response
def test_create_pet(pet_data):
response = create_pet(pet_data)
assert response.status_code == 200
assert response.json()['name'] == pet_data['name']
def test_find_pet():
response = find_pet()
assert response.status_code == 200
@allure.feature('宠物管理')
@allure.story('新增宠物')
def test_create_pet_with_allure(pet_data):
"""测试新增宠物接口,使用Allure报告记录测试步骤"""
with allure.step('发送新增宠物请求'):
response = create_pet(pet_data)
with allure.step('断言状态码为200'):
assert response.status_code == 200
with allure.step('断言返回结果中的name字段与请求中的相同'):
assert response.json()['name'] == pet_data['name']
@allure.feature('宠物管理')
@allure.story('查询宠物')
def test_find_pet_with_allure():
"""测试查询宠物接口,使用Allure报告记录测试步骤"""
with allure.step('发送查询宠物请求'):
response = find_pet()
with allure.step('断言状态码为200'):
assert response.status_code == 200
信计2002刘冬冬
数据2102王平安
数据2101江博伦
数据2101袁冬颖aaahttps://gitee.com/yuandongying/yuandongying1.git