ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] **接口测试实战-人员+部门操作** ## 1. 人员操作 ``` # -*- encoding: utf-8 -*- ''' user/addUserWithId.html user/delete.html user/update_by_login.html user/get_info.html ''' import requests import random # (1)user/addUserWithId 新增人员(传入用户id) addUserWithId_url = 'http://192.168.0.212:8000/api/user/addUserWithId.html' # (2)user/delete 删除人员 delete_url = 'http://192.168.0.212:8000/api/user/delete.html' def post(url, data): response = requests.post(url, data) res = str(response.content, encoding="utf-8") return res str_random = str(random.randint(200, 999)) for i in range(1000): # user/addUserWithId 新增人员(传入用户id) data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "dept_id": "557", "id": str_random + str(i), "user_login": "ff" + str_random + str(i), "user_name": "ff" + str_random + str(i), # "user_name": "ff", "user_pwd": "1", "user_pwd_type": "1", "user_order_id": "1000" } print(post(addUserWithId_url, data)) # user/delete 删除人员 for i in range(5): data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "user_login": "qq" + str_random + str(i), # "user_login": "zs", } print(post(delete_url, data)) # (3)user/update_by_login 更新人员 url = 'http://192.168.0.212:8000/api/user/update_by_login.html' data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "dept_id": "121", "update_user_login": "qq", } print(post(url, data)) # (4)user/get_info 查看人员 url = 'http://192.168.0.212:8000/api/user/get_info.html' data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "dept_id": "121", "user_login": "admin", } print(post(url, data)) ``` <br /> ## 2. 部门操作 ``` # -*- encoding: utf-8 -*- ''' dept/add_by_id.html dept/delete_by_id.html dept/all_dept_list.html ''' # import json import requests # requests请求方式 # (1)dept/add_by_id 根据部门id新增部门 url = 'http://192.168.0.212:8000/api/dept/add_by_id.html' data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "dept_id": "21", "dept_name": "ceshi65", "dept_parent_id": "120", } response = requests.post(url, data) res = str(response.content, encoding="utf-8") print(res) # (2)dept/delete_by_id 根据部门id删除部门 url = 'http://192.168.0.212:8000/api/dept/delete_by_id.html' data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", "dept_id": "21", } response = requests.post(url, data) res = str(response.content, encoding="utf-8") print(res) # (3)dept/all_dept_list 所有部门结构 url = 'http://192.168.0.212:8000/api/dept/all_dept_list.html' data = {"uid": 4, "app_id": "system", "authen": "0cc0820da3686a981af77a992d18345229a79b607c47f0462c870a5ccfa887eb", } response = requests.get(url, data) res = str(response.content, encoding="utf-8") print(res) ```