├── code ├── api │ ├── __init__.py │ ├── login.py │ ├── contract.py │ └── course.py ├── common │ └── __init__.py ├── script │ ├── __init__.py │ ├── test01_image.py │ ├── report │ │ ├── 00542a27-12e9-4db6-a344-f0aef59dca31-container.json │ │ ├── b4fac1bb-e83e-43cb-bc1a-5ab60c88582d-container.json │ │ ├── d5787547-2b82-4f0a-8af8-c81549ecf446-container.json │ │ ├── 04c60729-b332-48d0-b4e0-d08b2a926c8b-container.json │ │ ├── 32164697-ce7b-4681-8db7-a7fcd2db5397-container.json │ │ ├── 3e5b6eff-f34b-4dcf-b342-2fad5ed8aab5-container.json │ │ ├── 761b319c-d661-4c3a-9e59-fb0b60bb76de-container.json │ │ ├── f82c7055-9fa2-4044-a124-14f9a7d54768-container.json │ │ ├── 513f539d-fe27-4621-94da-653deb706fe4-result.json │ │ ├── 7b89561b-1378-4829-b9b1-7bad68bdd4da-result.json │ │ ├── 1178b8f9-2767-4699-beaa-2da2ef31e893-result.json │ │ ├── 36e874da-be6e-41e8-a618-46b649b672d7-result.json │ │ ├── 190737dd-78bb-4745-8a7e-6fe6bc8bbd76-result.json │ │ ├── 513d417f-51fa-4253-8171-a8cc8dedf29a-result.json │ │ ├── 9292056e-52b3-45af-aa01-8fc973c0d080-result.json │ │ └── 8449758d-80bb-45ae-9472-3548a5796024-result.json │ ├── test02_login.py │ ├── test07_select_course.py │ ├── test09_delete_course.py │ ├── test06_add_course.py │ ├── test08_update_course.py │ ├── test04_login.py │ ├── test05_login_params.py │ └── test03_contract_business.py ├── data │ ├── test.pdf │ └── login.json ├── pytest.ini ├── .idea │ ├── .gitignore │ ├── vcs.xml │ ├── misc.xml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── modules.xml │ └── code.iml └── config.py ├── code.zip ├── 登录.xmind ├── 课程修改.xmind ├── 课程列表查询.xmind ├── 课程删除.xmind ├── 课程添加.xmind ├── 合同新增业务流程.xmind ├── 接口测试用例KT.xlsx ├── 接口自动化测试-w.pdf └── 客达天下API文档-w.pdf /code/api/__init__.py: -------------------------------------------------------------------------------- 1 | # 存放被封装的接口信息 -------------------------------------------------------------------------------- /code/common/__init__.py: -------------------------------------------------------------------------------- 1 | # 封装公共代码,如数据库操作工具类、日志等 -------------------------------------------------------------------------------- /code/script/__init__.py: -------------------------------------------------------------------------------- 1 | # 调用被封装的接口信息,实现对应的接口测试用例自动化 -------------------------------------------------------------------------------- /code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/code.zip -------------------------------------------------------------------------------- /登录.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/登录.xmind -------------------------------------------------------------------------------- /课程修改.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/课程修改.xmind -------------------------------------------------------------------------------- /课程列表查询.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/课程列表查询.xmind -------------------------------------------------------------------------------- /课程删除.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/课程删除.xmind -------------------------------------------------------------------------------- /课程添加.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/课程添加.xmind -------------------------------------------------------------------------------- /合同新增业务流程.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/合同新增业务流程.xmind -------------------------------------------------------------------------------- /接口测试用例KT.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/接口测试用例KT.xlsx -------------------------------------------------------------------------------- /接口自动化测试-w.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/接口自动化测试-w.pdf -------------------------------------------------------------------------------- /客达天下API文档-w.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/客达天下API文档-w.pdf -------------------------------------------------------------------------------- /code/data/test.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shuhongfan/QA/HEAD/code/data/test.pdf -------------------------------------------------------------------------------- /code/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts=-s --alluredir report 3 | testpaths=./script 4 | python_files=test03_contract_business.py 5 | python_classes=Test* 6 | python_functions=test* -------------------------------------------------------------------------------- /code/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /code/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /code/config.py: -------------------------------------------------------------------------------- 1 | # 存放被测试项目基本信息,如URL地址等 2 | 3 | # 导包 4 | import os 5 | 6 | # 设置项目环境域名 7 | BASE_URL = "http://kdtx-test.itheima.net" 8 | 9 | # 获取项目根路径 10 | BASE_PATH = os.path.dirname(__file__) 11 | print(BASE_PATH) 12 | -------------------------------------------------------------------------------- /code/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /code/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /code/script/test01_image.py: -------------------------------------------------------------------------------- 1 | # 获取图片验证码 2 | 3 | # 导包 4 | import requests 5 | 6 | # 发送请求 7 | response = requests.get(url="http://kdtx-test.itheima.net/api/captchaImage") 8 | 9 | # 查看响应 10 | print(response.status_code) 11 | print(response.text) 12 | 13 | -------------------------------------------------------------------------------- /code/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /code/data/login.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "username": "manager", 4 | "password": "123456", 5 | "status": 200, 6 | "message": "成功", 7 | "code": 200 8 | }, 9 | { 10 | "username": "", 11 | "password": "123456", 12 | "status": 200, 13 | "message": "错误", 14 | "code": 500 15 | }, 16 | { 17 | "username": "jack666", 18 | "password": "123456", 19 | "status": 200, 20 | "message": "错误", 21 | "code": 500 22 | } 23 | ] -------------------------------------------------------------------------------- /code/script/report/00542a27-12e9-4db6-a344-f0aef59dca31-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "04adf37d-8421-4e63-b8cc-ff6d6205cc77", "children": ["7d785ef9-52e7-4561-aed1-16eca8528e1b"], "befores": [{"name": "_xunit_setup_method_fixture_TestLoginAPI", "status": "passed", "start": 1688556814461, "stop": 1688556814601}], "afters": [{"name": "_xunit_setup_method_fixture_TestLoginAPI::0", "status": "passed", "start": 1688556814866, "stop": 1688556814866}], "start": 1688556814461, "stop": 1688556814866} -------------------------------------------------------------------------------- /code/script/report/b4fac1bb-e83e-43cb-bc1a-5ab60c88582d-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "b54fbf8f-307c-4d18-9ff5-4d8344edf52b", "children": ["7760be16-67eb-4579-b009-b51453c6298e"], "befores": [{"name": "_xunit_setup_method_fixture_TestLoginAPI", "status": "passed", "start": 1688556813948, "stop": 1688556814101}], "afters": [{"name": "_xunit_setup_method_fixture_TestLoginAPI::0", "status": "passed", "start": 1688556814459, "stop": 1688556814459}], "start": 1688556813948, "stop": 1688556814459} -------------------------------------------------------------------------------- /code/script/report/d5787547-2b82-4f0a-8af8-c81549ecf446-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "1bfe4240-724c-4629-958b-73dadf40036e", "children": ["347f4de4-b95f-4bc3-a23e-d70ef7d2588f"], "befores": [{"name": "_xunit_setup_method_fixture_TestLoginAPI", "status": "passed", "start": 1688556814870, "stop": 1688556815001}], "afters": [{"name": "_xunit_setup_method_fixture_TestLoginAPI::0", "status": "passed", "start": 1688556815268, "stop": 1688556815268}], "start": 1688556814870, "stop": 1688556815268} -------------------------------------------------------------------------------- /code/script/report/04c60729-b332-48d0-b4e0-d08b2a926c8b-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "eb834412-f643-4c27-8696-e88c9a29c913", "children": ["9a627396-fbfe-4d37-9029-c29a244e6c74"], "befores": [{"name": "_xunit_setup_method_fixture_TestContractBusiness", "status": "passed", "start": 1688555811453, "stop": 1688555811453}], "afters": [{"name": "_xunit_setup_method_fixture_TestContractBusiness::0", "status": "passed", "start": 1688555811583, "stop": 1688555811583}], "start": 1688555811453, "stop": 1688555811583} -------------------------------------------------------------------------------- /code/script/report/32164697-ce7b-4681-8db7-a7fcd2db5397-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "975a25e4-2ee4-4d26-9ae2-debdfe1e8766", "children": ["2ea56a37-d9f5-4b57-9ddb-385e84c800ad"], "befores": [{"name": "_xunit_setup_method_fixture_TestContractBusiness", "status": "passed", "start": 1688555835746, "stop": 1688555835746}], "afters": [{"name": "_xunit_setup_method_fixture_TestContractBusiness::0", "status": "passed", "start": 1688555835875, "stop": 1688555835875}], "start": 1688555835746, "stop": 1688555835875} -------------------------------------------------------------------------------- /code/script/report/3e5b6eff-f34b-4dcf-b342-2fad5ed8aab5-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "8d62241c-6457-4aca-96de-81fea5228358", "children": ["80b3b4dc-fd7a-4d28-883d-857289d4ffcf"], "befores": [{"name": "_xunit_setup_method_fixture_TestContractBusiness", "status": "passed", "start": 1688555828246, "stop": 1688555828246}], "afters": [{"name": "_xunit_setup_method_fixture_TestContractBusiness::0", "status": "passed", "start": 1688555828946, "stop": 1688555828946}], "start": 1688555828246, "stop": 1688555828946} -------------------------------------------------------------------------------- /code/script/report/761b319c-d661-4c3a-9e59-fb0b60bb76de-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "a62382d2-3c9a-4c8a-b615-e77b38ea6b79", "children": ["015c2623-1ec0-4821-a00c-2ec332d3e95f"], "befores": [{"name": "_xunit_setup_method_fixture_TestContractBusiness", "status": "passed", "start": 1688555849055, "stop": 1688555849055}], "afters": [{"name": "_xunit_setup_method_fixture_TestContractBusiness::0", "status": "passed", "start": 1688555849169, "stop": 1688555849169}], "start": 1688555849055, "stop": 1688555849169} -------------------------------------------------------------------------------- /code/script/report/f82c7055-9fa2-4044-a124-14f9a7d54768-container.json: -------------------------------------------------------------------------------- 1 | {"uuid": "fbdc0a65-d1a1-414d-9d76-10ba8025f839", "children": ["e463b86b-e1d6-4022-8fe8-8e7f20992705"], "befores": [{"name": "_xunit_setup_method_fixture_TestContractBusiness", "status": "passed", "start": 1688555509957, "stop": 1688555509958}], "afters": [{"name": "_xunit_setup_method_fixture_TestContractBusiness::0", "status": "passed", "start": 1688555510426, "stop": 1688555510426}], "start": 1688555509957, "stop": 1688555510426} -------------------------------------------------------------------------------- /code/.idea/code.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /code/script/test02_login.py: -------------------------------------------------------------------------------- 1 | # 需求:登录成功 2 | 3 | # 导包 4 | import requests 5 | 6 | # 发送请求 7 | url = "http://kdtx-test.itheima.net/api/login" 8 | header_data = { 9 | "Content-Type": "application/json" 10 | } 11 | login_data = { 12 | "username": "admin", 13 | "password": "HM_2023_test", 14 | "code": 2, 15 | "uuid": "7db7bff9b00b45b498b8f96219105ae4" 16 | } 17 | response = requests.post(url=url, headers=header_data, json=login_data) 18 | 19 | # 查看响应 20 | print(response.status_code) 21 | print(response.json()) 22 | 23 | -------------------------------------------------------------------------------- /code/script/report/513f539d-fe27-4621-94da-653deb706fe4-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test02_without_username", "status": "passed", "start": 1688556814601, "stop": 1688556814865, "uuid": "7d785ef9-52e7-4561-aed1-16eca8528e1b", "historyId": "6c298d2dad33f5e0f0261d48e41e1c91", "testCaseId": "6c298d2dad33f5e0f0261d48e41e1c91", "fullName": "script.test04_login.TestLoginAPI#test02_without_username", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test04_login"}, {"name": "subSuite", "value": "TestLoginAPI"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "9576-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test04_login"}]} -------------------------------------------------------------------------------- /code/script/report/7b89561b-1378-4829-b9b1-7bad68bdd4da-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test03_username_not_exist", "status": "passed", "start": 1688556815001, "stop": 1688556815268, "uuid": "347f4de4-b95f-4bc3-a23e-d70ef7d2588f", "historyId": "7bef02533a3dd979b6d5af9c1a084088", "testCaseId": "7bef02533a3dd979b6d5af9c1a084088", "fullName": "script.test04_login.TestLoginAPI#test03_username_not_exist", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test04_login"}, {"name": "subSuite", "value": "TestLoginAPI"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "9576-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test04_login"}]} -------------------------------------------------------------------------------- /code/script/report/1178b8f9-2767-4699-beaa-2da2ef31e893-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test02_add_course", "status": "passed", "start": 1688555811453, "stop": 1688555811582, "uuid": "9a627396-fbfe-4d37-9029-c29a244e6c74", "historyId": "1203b4b9b5df66032d0b7d8da77c82ff", "testCaseId": "1203b4b9b5df66032d0b7d8da77c82ff", "fullName": "script.test03_contract_business.TestContractBusiness#test02_add_course", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test03_contract_business"}, {"name": "subSuite", "value": "TestContractBusiness"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "14236-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test03_contract_business"}]} -------------------------------------------------------------------------------- /code/script/report/36e874da-be6e-41e8-a618-46b649b672d7-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test02_add_course", "status": "passed", "start": 1688555835747, "stop": 1688555835874, "uuid": "2ea56a37-d9f5-4b57-9ddb-385e84c800ad", "historyId": "1203b4b9b5df66032d0b7d8da77c82ff", "testCaseId": "1203b4b9b5df66032d0b7d8da77c82ff", "fullName": "script.test03_contract_business.TestContractBusiness#test02_add_course", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test03_contract_business"}, {"name": "subSuite", "value": "TestContractBusiness"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "7900-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test03_contract_business"}]} -------------------------------------------------------------------------------- /code/script/report/190737dd-78bb-4745-8a7e-6fe6bc8bbd76-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test01_login_success", "status": "passed", "start": 1688555509958, "stop": 1688555510425, "uuid": "e463b86b-e1d6-4022-8fe8-8e7f20992705", "historyId": "5321a9ff1d67564571903ae3b2ae375a", "testCaseId": "5321a9ff1d67564571903ae3b2ae375a", "fullName": "script.test03_contract_business.TestContractBusiness#test01_login_success", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test03_contract_business"}, {"name": "subSuite", "value": "TestContractBusiness"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "4144-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test03_contract_business"}]} -------------------------------------------------------------------------------- /code/script/report/513d417f-51fa-4253-8171-a8cc8dedf29a-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test01_login_success", "status": "passed", "start": 1688555828246, "stop": 1688555828945, "uuid": "80b3b4dc-fd7a-4d28-883d-857289d4ffcf", "historyId": "5321a9ff1d67564571903ae3b2ae375a", "testCaseId": "5321a9ff1d67564571903ae3b2ae375a", "fullName": "script.test03_contract_business.TestContractBusiness#test01_login_success", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test03_contract_business"}, {"name": "subSuite", "value": "TestContractBusiness"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "19364-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test03_contract_business"}]} -------------------------------------------------------------------------------- /code/script/report/9292056e-52b3-45af-aa01-8fc973c0d080-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test03_upload_contract", "status": "passed", "start": 1688555849055, "stop": 1688555849169, "uuid": "015c2623-1ec0-4821-a00c-2ec332d3e95f", "historyId": "58093b10fd55c732974702139a09443e", "testCaseId": "58093b10fd55c732974702139a09443e", "fullName": "script.test03_contract_business.TestContractBusiness#test03_upload_contract", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test03_contract_business"}, {"name": "subSuite", "value": "TestContractBusiness"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "5968-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test03_contract_business"}]} -------------------------------------------------------------------------------- /code/api/login.py: -------------------------------------------------------------------------------- 1 | # 接口信息: 2 | # 验证码: 3 | # 地址:http://kdtx-test.itheima.net/api/captchaImage 4 | # 方法:get 5 | # 6 | # 登录: 7 | # 地址:http://kdtx-test.itheima.net/api/login 8 | # 方法:Post 9 | # 请求数据: 10 | # 请求头:Content-Type: application/json 11 | # 请求体:{"username":”admin", "password": " admin123","code":"2", "uuid":"验证码接口返回数据"} 12 | # 13 | 14 | # 接口封装时,重点是依据接口文档封装接口信息,需要使用的测试数据是从测试用例传递的、接口方法被调用时需要返回对应的响应结果 15 | 16 | # 导包 17 | import requests 18 | import config 19 | 20 | 21 | # 创建接口类 22 | class LoginAPI: 23 | # 初始化 24 | def __init__(self): 25 | # 指定url基本信息 26 | # self.url_verify = "http://kdtx-test.itheima.net/api/captchaImage" 27 | self.url_verify = config.BASE_URL + "/api/captchaImage" 28 | # self.url_login = "http://kdtx-test.itheima.net/api/login" 29 | self.url_login = config.BASE_URL + "/api/login" 30 | 31 | # 验证码 32 | def get_verify_code(self): 33 | return requests.get(url=self.url_verify) 34 | 35 | # 登录 36 | def login(self, test_data): 37 | return requests.post(url=self.url_login, json=test_data) 38 | 39 | -------------------------------------------------------------------------------- /code/api/contract.py: -------------------------------------------------------------------------------- 1 | # URL: http://kdtx-test.itheima.net/api/common/upload 2 | # 方法:Post 3 | # 请求数据: 4 | # 请求头:{ "Content-Type ": " multipart/form-data ", "Authorization": "xxx " } 5 | # 请求体:{" file " : 合同文件"} 6 | 7 | # 接口信息: 8 | # 新增合同: 9 | # 地址:http://kdtx-test.itheima.net/api/contract 10 | # 方法:Post 11 | # 请求数据: 12 | # 请求头:{ "Content-Type ": "application/json ", "Authorization": "xxx " } 13 | # 请求体:{ "name": "测试888", "phone": "13612345678", "contractNo": "HT10012003", "subject": "6", "courseId": " 99", "channel": "0", "activityId": 77, "fileName": "xxx"} 14 | 15 | 16 | # 导包 17 | import requests 18 | import config 19 | 20 | 21 | # 创建接口类 22 | class ContractAPI: 23 | # 初始化 24 | def __init__(self): 25 | # self.url_upload = "http://kdtx-test.itheima.net/api/common/upload" 26 | self.url_upload = config.BASE_URL + "/api/common/upload" 27 | # self.add_contrat = "http://kdtx-test.itheima.net/api/contract" 28 | self.add_contrat = config.BASE_URL + "/api/contract" 29 | 30 | # 合同上传接口 31 | def upload_contract(self, test_data, token): 32 | return requests.post(url=self.url_upload, files={"file": test_data}, headers={"Authorization": token}) 33 | 34 | # 合同新增 35 | def add_contract(self, test_data, token): 36 | return requests.post(url=self.add_contrat, json=test_data, headers={"Authorization": token}) -------------------------------------------------------------------------------- /code/api/course.py: -------------------------------------------------------------------------------- 1 | # 课程模块接口封装:核心在于依据接口文档实现接口信息封装、重点关注接口如何被调用 2 | # 接口信息: 3 | # URL:http://kdtx-test.itheima.net/api/clues/course 4 | # 方法:Post 5 | # 请求数据: 6 | # 请求头:{ "Content-Type ": "application/json ", "Authorization": "xxx " } 7 | # 请求体:{ "name": "测试开发提升课01", "subject": "6","price": 899,"applicablePerson": "2", "info": "测试开发提升课01"} 8 | 9 | # 导包 10 | import requests 11 | import config 12 | 13 | 14 | # 创建接口类 15 | class CourseAPI: 16 | # 初始化 17 | def __init__(self): 18 | # self.url_add_course = "http://kdtx-test.itheima.net/api/clues/course" 19 | self.url_add_course = config.BASE_URL + "/api/clues/course" 20 | # self.url_select_course = "http://kdtx-test.itheima.net/api/clues/course/list" 21 | self.url_select_course = config.BASE_URL + "/api/clues/course/list" 22 | 23 | # 课程添加 24 | def add_course(self, test_data, token): 25 | return requests.post(url=self.url_add_course, json=test_data, headers={"Authorization": token}) 26 | 27 | # 查询课程列表 28 | def select_course(self, test_data, token): 29 | return requests.get(url=self.url_select_course + f"/{test_data}", headers={"Authorization": token}) 30 | 31 | # 修改课程 32 | def update_course(self, test_data, token): 33 | return requests.put(url=self.url_add_course, json=test_data, headers={"Authorization": token}) 34 | 35 | # 删除课程 36 | def delete_course(self, course_id, token): 37 | return requests.delete(url=self.url_add_course + f"/{course_id}", headers={"Authorization": token}) 38 | 39 | 40 | -------------------------------------------------------------------------------- /code/script/report/8449758d-80bb-45ae-9472-3548a5796024-result.json: -------------------------------------------------------------------------------- 1 | {"name": "test01_success", "status": "failed", "statusDetails": {"message": "AssertionError: assert '成功' in '{\"msg\":\"用户不存在/密码错误\",\"code\":500}'\n + where '{\"msg\":\"用户不存在/密码错误\",\"code\":500}' = .text", "trace": "self = \n\n def test01_success(self):\n login_data = {\n \"username\": \"manager\",\n \"password\": \"123456\",\n \"code\": \"2\",\n \"uuid\": TestLoginAPI.uuid\n }\n response = self.login_api.login(test_data=login_data)\n # 断言响应状态码为200\n assert 200 == response.status_code\n # 断言响应数据包含'成功'\n> assert '成功' in response.text\nE assert '成功' in '{\"msg\":\"用户不存在/密码错误\",\"code\":500}'\nE + where '{\"msg\":\"用户不存在/密码错误\",\"code\":500}' = .text\n\ntest04_login.py:37: AssertionError"}, "start": 1688556814102, "stop": 1688556814378, "uuid": "7760be16-67eb-4579-b009-b51453c6298e", "historyId": "a22aabc11a3519f6d551a0d3731aa154", "testCaseId": "a22aabc11a3519f6d551a0d3731aa154", "fullName": "script.test04_login.TestLoginAPI#test01_success", "labels": [{"name": "parentSuite", "value": "script"}, {"name": "suite", "value": "test04_login"}, {"name": "subSuite", "value": "TestLoginAPI"}, {"name": "host", "value": "SHFHP"}, {"name": "thread", "value": "9576-MainThread"}, {"name": "framework", "value": "pytest"}, {"name": "language", "value": "cpython3"}, {"name": "package", "value": "script.test04_login"}]} -------------------------------------------------------------------------------- /code/script/test07_select_course.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | from api.course import CourseAPI 4 | 5 | 6 | # 创建测试类 7 | class TestCourseAPI: 8 | # 初始化 9 | TOKEN = None 10 | 11 | # 前置处理 12 | def setup(self): 13 | # 初始化接口类 14 | self.login_api = LoginAPI() 15 | self.course_api = CourseAPI() 16 | # 登录成功 17 | # 获取验证码 18 | res_v = self.login_api.get_verify_code() 19 | # 登录 20 | login_data = { 21 | "username": "admin", 22 | "password": "admin123", 23 | "code": "2", 24 | "uuid": res_v.json().get("uuid") 25 | } 26 | res_l = self.login_api.login(test_data=login_data) 27 | # 提取登录成功的token数据并保存 28 | TestCourseAPI.TOKEN = res_l.json().get("token") 29 | print(TestCourseAPI.TOKEN) 30 | 31 | # 查询存在的课程 32 | def test01_select_success(self): 33 | response = self.course_api.select_course(test_data="?name=测试开发提升课01", token=TestCourseAPI.TOKEN) 34 | print(response.json()) 35 | # 断言响应状态码 36 | assert 200 == response.status_code 37 | # 断言msg中包含指定的文字 38 | assert "成功" in response.text 39 | # 断言json返回数据中code值 40 | assert 200 == response.json().get("code") 41 | 42 | # 查询失败(用户未登录) 43 | def test02_select_fail(self): 44 | response = self.course_api.select_course(test_data="?subject=6", token="xxx") 45 | print(response.json()) 46 | # 断言响应状态码 47 | assert 200 == response.status_code 48 | # 断言msg中包含指定的文字 49 | assert "认证失败" in response.text 50 | # 断言json返回数据中code值 51 | assert 401 == response.json().get("code") 52 | -------------------------------------------------------------------------------- /code/script/test09_delete_course.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | from api.course import CourseAPI 4 | 5 | 6 | # 创建测试类 7 | class TestCourseAPI: 8 | # 初始化 9 | TOKEN = None 10 | 11 | # 前置处理 12 | def setup(self): 13 | # 初始化接口类 14 | self.login_api = LoginAPI() 15 | self.course_api = CourseAPI() 16 | # 登录成功 17 | # 获取验证码 18 | res_v = self.login_api.get_verify_code() 19 | # 登录 20 | login_data = { 21 | "username": "admin", 22 | "password": "admin123", 23 | "code": "2", 24 | "uuid": res_v.json().get("uuid") 25 | } 26 | res_l = self.login_api.login(test_data=login_data) 27 | # 提取登录成功的token数据并保存 28 | TestCourseAPI.TOKEN = res_l.json().get("token") 29 | print(TestCourseAPI.TOKEN) 30 | 31 | # 课程删除成功 32 | def test01_delete_success(self): 33 | response = self.course_api.delete_course(course_id=110, token=TestCourseAPI.TOKEN) 34 | print(response.json()) 35 | # 断言响应状态码 36 | assert 200 == response.status_code 37 | # 断言返回消息 38 | assert "成功" in response.text 39 | # 断言code值 40 | assert 200 == response.json().get("code") 41 | 42 | # 课程删除失败(课程id不存在) 43 | def test02_delete_fail_id_not_exist(self): 44 | response = self.course_api.delete_course(course_id=666, token=TestCourseAPI.TOKEN) 45 | print(response.json()) 46 | # 断言响应状态码 47 | assert 200 == response.status_code 48 | # 断言返回消息 49 | assert "失败" in response.text 50 | # 断言code值 51 | assert 500 == response.json().get("code") 52 | 53 | # 课程删除失败(用户未登录) 54 | def test03_delete_fail(self): 55 | response = self.course_api.delete_course(course_id=110, token="xxx") 56 | print(response.json()) 57 | # 断言响应状态码 58 | assert 200 == response.status_code 59 | # 断言返回消息 60 | assert "认证失败" in response.text 61 | # 断言code值 62 | assert 401 == response.json().get("code") 63 | -------------------------------------------------------------------------------- /code/script/test06_add_course.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | from api.course import CourseAPI 4 | 5 | 6 | # 创建测试类 7 | class TestCourseAPI: 8 | # 初始化 9 | TOKEN = None 10 | 11 | # 前置处理 12 | def setup(self): 13 | # 初始化接口类 14 | self.login_api = LoginAPI() 15 | self.course_api = CourseAPI() 16 | # 登录成功 17 | # 获取验证码 18 | res_v = self.login_api.get_verify_code() 19 | # 登录 20 | login_data = { 21 | "username": "admin", 22 | "password": "admin123", 23 | "code": "2", 24 | "uuid": res_v.json().get("uuid") 25 | } 26 | res_l = self.login_api.login(test_data=login_data) 27 | # 提取登录成功的token数据并保存 28 | TestCourseAPI.TOKEN = res_l.json().get("token") 29 | print(TestCourseAPI.TOKEN) 30 | 31 | # 后置处理 32 | def teardown(self): 33 | pass 34 | 35 | # 课程添加成功 36 | def test01_add_success(self): 37 | add_data = { 38 | "name": "测试开发提升课01", 39 | "subject": "6", 40 | "price": 899, 41 | "applicablePerson": "2" 42 | } 43 | response = self.course_api.add_course(test_data=add_data, token=TestCourseAPI.TOKEN) 44 | print(response.json()) 45 | # 断言响应状态码 46 | assert 200 == response.status_code 47 | # 断言返回数据中包含指定的文字 48 | assert "成功" in response.text 49 | # 断言json返回数据code值 50 | assert 200 == response.json().get("code") 51 | 52 | # 课程添加失败(未登录) 53 | def test02_add_fail(self): 54 | add_data = { 55 | "name": "测试开发提升课02", 56 | "subject": "6", 57 | "price": 899, 58 | "applicablePerson": "2" 59 | } 60 | response = self.course_api.add_course(test_data=add_data, token="xxx") 61 | print(response.json()) 62 | # 断言响应状态码 63 | assert 200 == response.status_code 64 | # 断言返回数据中包含指定的文字 65 | assert "认证失败" in response.text 66 | # 断言json返回数据code值 67 | assert 401 == response.json().get("code") 68 | 69 | -------------------------------------------------------------------------------- /code/script/test08_update_course.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | from api.course import CourseAPI 4 | 5 | 6 | # 创建测试类 7 | class TestCourseAPI: 8 | # 初始化 9 | TOKEN = None 10 | 11 | # 前置处理 12 | def setup(self): 13 | # 初始化接口类 14 | self.login_api = LoginAPI() 15 | self.course_api = CourseAPI() 16 | # 登录成功 17 | # 获取验证码 18 | res_v = self.login_api.get_verify_code() 19 | # 登录 20 | login_data = { 21 | "username": "admin", 22 | "password": "admin123", 23 | "code": "2", 24 | "uuid": res_v.json().get("uuid") 25 | } 26 | res_l = self.login_api.login(test_data=login_data) 27 | # 提取登录成功的token数据并保存 28 | TestCourseAPI.TOKEN = res_l.json().get("token") 29 | print(TestCourseAPI.TOKEN) 30 | 31 | # 课程修改成功 32 | def test01_update_success(self): 33 | update_data = { 34 | "id": 109, 35 | "name": "接口测试001", 36 | "subject": "6", 37 | "price": 998, 38 | "applicablePerson": "2", 39 | "info": "课程介绍001" 40 | } 41 | response = self.course_api.update_course(test_data=update_data, token=TestCourseAPI.TOKEN) 42 | print(response.json()) 43 | # 断言响应状态码 44 | assert 200 == response.status_code 45 | # 断言返回消息 46 | assert "成功" in response.text 47 | # 断言code值 48 | assert 200 == response.json().get("code") 49 | 50 | # 课程修改失败(未登录) 51 | def test02_update_fail(self): 52 | update_data = { 53 | "id": 109, 54 | "name": "接口测试001", 55 | "subject": "6", 56 | "price": 998, 57 | "applicablePerson": "2", 58 | "info": "课程介绍001" 59 | } 60 | response = self.course_api.update_course(test_data=update_data, token="xxx") 61 | print(response.json()) 62 | # 断言响应状态码 63 | assert 200 == response.status_code 64 | # 断言返回消息 65 | assert "认证失败" in response.text 66 | # 断言code值 67 | assert 401 == response.json().get("code") 68 | -------------------------------------------------------------------------------- /code/script/test04_login.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | 4 | 5 | # 创建测试类 6 | class TestLoginAPI: 7 | # 初始化 8 | uuid = None 9 | 10 | # 前置处理 11 | def setup(self): 12 | # 实例化接口类 13 | self.login_api = LoginAPI() 14 | # 获取验证码 15 | response = self.login_api.get_verify_code() 16 | print(response.json()) 17 | # 提取验证码接口返回的uuid参数值 18 | TestLoginAPI.uuid = response.json().get("uuid") 19 | print(TestLoginAPI.uuid) 20 | 21 | # 后置处理 22 | def teardown(self): 23 | pass 24 | 25 | # 登录成功 26 | def test01_success(self): 27 | login_data = { 28 | "username": "manager", 29 | "password": "123456", 30 | "code": "2", 31 | "uuid": TestLoginAPI.uuid 32 | } 33 | response = self.login_api.login(test_data=login_data) 34 | # 断言响应状态码为200 35 | assert 200 == response.status_code 36 | # 断言响应数据包含'成功' 37 | assert '成功' in response.text 38 | # 断言响应json数据中code值 39 | assert 200 == response.json().get("code") 40 | 41 | # 登录失败(用户名为空) 42 | def test02_without_username(self): 43 | login_data = { 44 | "username": "", 45 | "password": "123456", 46 | "code": "2", 47 | "uuid": TestLoginAPI.uuid 48 | } 49 | response = self.login_api.login(test_data=login_data) 50 | # 断言响应状态码为200 51 | assert 200 == response.status_code 52 | # 断言响应数据包含'错误' 53 | assert '错误' in response.text 54 | # 断言响应json数据中code值 55 | assert 500 == response.json().get("code") 56 | 57 | # 登录失败(未注册用户) 58 | def test03_username_not_exist(self): 59 | login_data = { 60 | "username": "jack666", 61 | "password": "123456", 62 | "code": "2", 63 | "uuid": TestLoginAPI.uuid 64 | } 65 | response = self.login_api.login(test_data=login_data) 66 | # 断言响应状态码为200 67 | assert 200 == response.status_code 68 | # 断言响应数据包含'错误' 69 | assert '错误' in response.text 70 | # 断言响应json数据中code值 71 | assert 500 == response.json().get("code") 72 | 73 | -------------------------------------------------------------------------------- /code/script/test05_login_params.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | from api.login import LoginAPI 3 | import pytest 4 | import json 5 | import config 6 | 7 | 8 | # # 测试数据 9 | # test_data = [ 10 | # ("manager", "123456", 200, '成功', 200), 11 | # ("", "123456", 200, '错误', 500), 12 | # ("jack666", "123456", 200, '错误', 500), 13 | # ] 14 | 15 | # 读取json文件 16 | def build_data(json_file): 17 | # 定义空列表 18 | test_data = [] 19 | # 打开json文件 20 | with open(json_file, "r") as f: 21 | # 加载json文件数据 22 | json_data = json.load(f) 23 | # 循环遍历测试数据 24 | for case_data in json_data: 25 | # 转换数据格式[{},{}] ==> [(),()] 26 | username = case_data.get("username") 27 | password = case_data.get("password") 28 | status = case_data.get("status") 29 | message = case_data.get("message") 30 | code = case_data.get("code") 31 | test_data.append((username, password, status, message, code)) 32 | # 返回处理之后测试数据 33 | return test_data 34 | 35 | 36 | # 创建测试类 37 | class TestLoginAPI: 38 | # 初始化 39 | uuid = None 40 | 41 | # 前置处理 42 | def setup(self): 43 | # 实例化接口类 44 | self.login_api = LoginAPI() 45 | # 获取验证码 46 | response = self.login_api.get_verify_code() 47 | print(response.json()) 48 | # 提取验证码接口返回的uuid参数值 49 | TestLoginAPI.uuid = response.json().get("uuid") 50 | print(TestLoginAPI.uuid) 51 | 52 | # 后置处理 53 | def teardown(self): 54 | pass 55 | 56 | # 登录成功 57 | # @pytest.mark.parametrize("username, password, status, message, code", build_data(json_file="../data/login.json")) 58 | @pytest.mark.parametrize("username, password, status, message, code", build_data(json_file=config.BASE_PATH + "/data/login.json")) 59 | def test01_success(self, username, password, status, message, code): 60 | login_data = { 61 | "username": username, 62 | "password": password, 63 | "code": "2", 64 | "uuid": TestLoginAPI.uuid 65 | } 66 | response = self.login_api.login(test_data=login_data) 67 | # 断言响应状态码为200 68 | assert status == response.status_code 69 | # 断言响应数据包含'成功' 70 | assert message in response.text 71 | # 断言响应json数据中code值 72 | assert code == response.json().get("code") 73 | 74 | -------------------------------------------------------------------------------- /code/script/test03_contract_business.py: -------------------------------------------------------------------------------- 1 | # 导包 2 | import config 3 | from api.login import LoginAPI 4 | from api.course import CourseAPI 5 | from api.contract import ContractAPI 6 | 7 | 8 | # 创建测试类 9 | class TestContractBusiness: 10 | # 初始化 11 | token = None 12 | 13 | # 前置处理 14 | def setup(self): 15 | # 实例化接口对象 16 | self.login_api = LoginAPI() 17 | self.course_api = CourseAPI() 18 | self.contract_api = ContractAPI() 19 | 20 | # 后置处理 21 | def teardown(self): 22 | pass 23 | 24 | # 1、登录成功 25 | def test01_login_success(self): 26 | # 获取验证码 27 | res_v = self.login_api.get_verify_code() 28 | print(res_v.status_code) 29 | print(res_v.json()) 30 | # 打印uuid数据 31 | print(res_v.json().get("uuid")) 32 | 33 | # 登录 34 | login_data = { 35 | "username": "admin", 36 | "password": "HM_2023_test", 37 | "code": "2", 38 | "uuid": res_v.json().get("uuid") 39 | } 40 | res_l = self.login_api.login(test_data=login_data) 41 | print(res_l.status_code) 42 | print(res_l.json()) 43 | # 提取登录成功之后的token数据并保存在类的属性中 44 | TestContractBusiness.token = res_l.json().get("token") 45 | print(TestContractBusiness.token) 46 | 47 | # 2、课程新增成功 48 | def test02_add_course(self): 49 | add_data = { "name": "测试开发提升课01", "subject": "6","price": 899,"applicablePerson": "2", "info": "测试开发提升课01"} 50 | response = self.course_api.add_course(test_data=add_data, token=TestContractBusiness.token) 51 | print(response.json()) 52 | 53 | # 3、上传合同成功 54 | def test03_upload_contract(self): 55 | # 读取pdf文件数据 56 | # f = open("../data/test.pdf", "rb") 57 | f = open(config.BASE_PATH + "/data/test.pdf", "rb") 58 | response = self.contract_api.upload_contract(test_data=f, token=TestContractBusiness.token) 59 | print(response.json()) 60 | 61 | # 4、合同新增成功 62 | def test04_add_contract(self): 63 | # contractNo: 数据唯一 64 | add_data = { "name": "测试888", "phone": "13612345678", "contractNo": "HT20230007", "subject": "6", "courseId": " 99", "channel": "0", "activityId": 77, "fileName": "xxx"} 65 | response = self.contract_api.add_contract(test_data=add_data, token=TestContractBusiness.token) 66 | print(response.json()) 67 | 68 | 69 | 70 | 71 | 72 | --------------------------------------------------------------------------------