def test_userDetail_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies( request_parameters['phone'], request_parameters['password'], mobileType=2) with allure.step("step2: 步骤2 ==>> 获取需要查询用户id"): select_info = [] rsp_list = getter.user_list(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) for i, item in enumerate(rsp_list.json()['data']['list']): if item['name'] == '测试添加账号1': select_info.append(item) break select_id = select_info[0]['id'] logger.info(f"select_info为{select_info},select_id为{select_id}") with allure.step("step3: 步骤3 ==>>查询用户详情"): rsp_detail = getter.user_detail(cookies=cookies, mobileType=2, id=select_id, token=token, userid=userId) assert rsp_detail.status_code == 200 assert rsp_detail.json()['data'] is not None assert rsp_detail.json()['message'] == expected_response['message'] assert rsp_detail.json()['status'] == expected_response['status'] assert select_info[0] == rsp_detail.json()['data']
def test_user_delete_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies(request_parameters['phone'], request_parameters['password'], mobileType=2) logger.info(f"当前获取到的token:{token},userId:{userId}") with allure.step("step2: 步骤2 ==>> 获取被删除用户id"): delete_id = [] rsp_list1 = getter.user_list(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) for i, item in enumerate(rsp_list1.json()['data']['list']): if item['name'] == f'测试添加账号{i+1}': if request_parameters['deleteInfo'] == '删除单个用户': delete_id.append(item['id']) break elif request_parameters['deleteInfo'] == '批量删除用户': delete_id.append(item['id']) logger.info(f"被删除用户id为{delete_id}") with allure.step("step3: 步骤3 ==>>删除用户"): rsp_delete = getter.user_delete(cookies=cookies, mobileType=2, id=delete_id, userid=userId, token=token) logger.info(f"删除结果为{rsp_delete.json()['message']}") with allure.step("step4: 步骤4 ==>>查询所有用户列表"): rsp_list2 = getter.user_list(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) assert rsp_delete.status_code == 200 assert rsp_delete.json()['data'] is None assert rsp_delete.json()['message'] == expected_response['message'] assert rsp_delete.json()['status'] == expected_response['status'] assert rsp_list2.json()['data'] is not None for i in delete_id: assert re.search(i, str(rsp_list2.json()['data'])) is None
def test_user_delete_fail(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies(request_parameters['phone'], request_parameters['password'], mobileType=2) logger.info(f"当前获取到的token:{token},userId:{userId}") with allure.step("step2: 步骤2 ==>> 根据用例获取对应用户id/cookies"): rsp_list1 = getter.user_list(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) delete_id = [] if request_parameters['deleteInfo'] == 'id不存在': delete_id = '123213123213' if request_parameters['deleteInfo'] == 'id为空': delete_id = '' if request_parameters['deleteInfo'] == '批量删除用户': for i, item in enumerate(rsp_list1.json()['data']['list']): if item['name'] == f'测试添加账号{i + 1}': delete_id.append(item['id']) delete_id.append('12312312343241') if request_parameters['deleteInfo'] == '未登录删除用户': for i, item in enumerate(rsp_list1.json()['data']['list']): if item['name'] == f'测试添加账号{i+1}': delete_id.append(item['id']) break with allure.step("step3: 步骤3 ==>> 根据对应信息删除用户"): if request_parameters['deleteInfo'] == '未登录删除用户': rsp_delete = getter.user_delete(id=delete_id, mobileType=2, token=token, userid=userId) else: rsp_delete = getter.user_list(cookies=cookies, mobileType=2, id=delete_id, token=token, userid=userId) assert rsp_delete.status_code == 200 assert rsp_delete.json()['data'] is None assert rsp_delete.json()['message'] == expected_response['message'] assert rsp_delete.json()['status'] == expected_response['status']
def test_user_save_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies(request_parameters['phone'], request_parameters['password'], mobileType=2) with allure.step("step2: 步骤2 ==>> 获取所有部门id列表"): rsp_data1 = getter.user_findDivision(cookies=cookies, mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) branch_id = jsonpath.jsonpath(rsp_data1.json(), '$..id') with allure.step("step3: 步骤3 ==>> 根据部门id获取部门下所有项目id"): rsp_data2 = getter.user_findProject(cookies=cookies, divIds=branch_id[0], mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) project_ids = jsonpath.jsonpath(rsp_data2.json(), '$..id') with allure.step("step4: 步骤4 ==>> 获取岗位id"): rsp_data3 = getter.user_findJob(cookies=cookies, mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) jobId = rsp_data3.json()['data']['list'][0]['id'] with allure.step("step5: 步骤5 ==>> 新增用户"): rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='13200000001', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) assert rsp_branch.status_code == 200 assert rsp_branch.json()['data'] is None assert rsp_branch.json()['message'] == expected_response['message'] assert rsp_branch.json()['status'] == expected_response['status']
def addOrganization(): """ 新增测试使用组织架构数据 :return: """ token, userId, cookies = getter.get_login_token_cookies('admin', 'admin') rsp_tree = getter.organization_findOrganizationTree(cookies=cookies, mobileType=2, code='01', token=token, userid=userId) branch_id = rsp_tree.json()['data']['list'][0]['children'][0]['id'] getter.organization_save(cookies=cookies, label='test事业部', pid=branch_id, type=1, mobileType=2, token=token, userid=userId) yield rsp_tree = getter.organization_findOrganizationTree(cookies=cookies, mobileType=2, code='01', token=token, userid=userId) delete_branch_id = rsp_tree.json()['data']['list'][0]['children'][0]['id'] getter.organization_delete(cookies=cookies, mobileType=2, id=delete_branch_id, token=token, userid=userId)
def test_user_findProject_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies( request_parameters['phone'], request_parameters['password'], mobileType=2) with allure.step("step2: 步骤2 ==>> 获取事业部id"): rsp_ids = getter.user_findDivision(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) branch_id = rsp_ids.json()['data']['list'][0]['id'] with allure.step("step3: 步骤3 ==>> 查询所有事业部下项目"): rsp_data = getter.user_findProject(cookies=cookies, divIds=[branch_id], pageNum=1, pageSize=1000, mobileType=2, token=token, userid=userId) assert rsp_data.status_code == 200 assert rsp_data.json()['data'] is not None assert rsp_data.json()['message'] == expected_response['message'] assert rsp_data.json()['status'] == expected_response['status']
def test_organization_save_subset(self, request_parameters, expected_response): """ 新增下级组织 :param request_parameters:请求参数列表 :param expected_response:预期响应结果列表 :return: """ with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies(request_parameters['phone'], request_parameters['password']) logger.info(f"当前获取到的token:{token},userId:{userId}") with allure.step("step2: 步骤2 ==>> 获取部门节点id"): rsp_tree = getter.organization_findOrganizationTree(cookies=cookies, code='01', token=token, userid=userId) branch_id = rsp_tree.json()['data']['list'][0]['children'][0]['id'] with allure.step("step3: 步骤3 ==>> 添加组织架构"): rsp_add = getter.organization_save(cookies=cookies, label=request_parameters['label'], pid=branch_id, type=request_parameters['type'], token=token, userid=userId) logger.info(f"添加返回结果为:{rsp_add.json()}") with allure.step("step4: 步骤4 ==>> 查询当前组织架构,验证是否添加成功"): rsp_select = getter.organization_findDivision(cookies=cookies, token=token, userid=userId) logger.info(f"查询返回结果为:{rsp_select.json()}") assert rsp_add.status_code == 200 assert rsp_add.json()['message'] == expected_response['message'] assert rsp_add.json()['status'] == expected_response['status'] assert request_parameters['label'] == rsp_select.json()['data']['list'][0]['label']
def addOrganization(): token, userId, cookies = getter.get_login_token_cookies('admin', 'admin') parentId = getter.organization_findOrganizationTree( cookies=cookies, code='01', token=token, mobileType=2, userid=userId).json()['data']['list'][0]['id'] getter.organization_save(cookies=cookies, label='测试部门1', pid=parentId, mobileType=2, remarks='测试专用', token=token, userid=userId, type=2)
def test_organization_findDivision_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies( request_parameters['phone'], request_parameters['password']) logger.info(f"当前获取到的token:{token},userId:{userId}") with allure.step("step2: 步骤2 ==>> 请求获取所有事业部信息"): rsp_branch = getter.organization_findDivision(cookies=cookies, mobileType=2, token=token, userid=userId) assert rsp_branch.status_code == 200 assert rsp_branch.json()['data'] is not None assert rsp_branch.json()['message'] == expected_response['message'] assert rsp_branch.json()['status'] == expected_response['status']
def test_user_list_success(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies( request_parameters['phone'], request_parameters['password'], mobileType=2) with allure.step("step2: 步骤2 ==>> 查询用户列表"): rsp_list = getter.user_list(cookies=cookies, mobileType=2, pageNum=1, pageSize=1000, token=token, userid=userId) assert rsp_list.status_code == 200 assert rsp_list.json()['data'] is not None assert rsp_list.json()['message'] == expected_response['message'] assert rsp_list.json()['status'] == expected_response['status'] for i in range(3): assert re.findall(f'测试添加账号{i+1}', rsp_list.json()) is not None
def test_logout(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies( request_parameters['phone'], request_parameters['password'], mobileType=2) logger.info(f"当前获取到的token:{token},userId:{userId}") with allure.step("step2: 步骤2 ==>> 使用当前获取到的信息退出登录"): rsp_logout = getter.user_logout(cookies=cookies, mobileType=2, token=token, userid=userId) print(rsp_logout.json()) logger.info( f"本次测试登录账号为{request_parameters['phone']}========>接口返回状态码为{rsp_logout.status_code}," f"message为{rsp_logout.json()['message']},status为{rsp_logout.json()['status']}" ) assert rsp_logout.status_code == 200 assert rsp_logout.json()['data'] is None assert rsp_logout.json()['message'] == expected_response['message'] assert rsp_logout.json()['status'] == expected_response['status']
def preposition_login(): token, userId, cookies = getter.get_login_token_cookies( '13100000001', '123', 2) return [token, userId, cookies]
def test_user_save_fail(self, request_parameters, expected_response): with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统获取对应token与userId"): token, userId, cookies = getter.get_login_token_cookies(request_parameters['phone'], request_parameters['password'], mobileType=2) with allure.step("step2: 步骤2 ==>> 获取所有部门id列表"): if request_parameters['addInfo'] == '事业部未传': branch_id = [] else: rsp_data1 = getter.user_findDivision(cookies=cookies, mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) branch_id = jsonpath.jsonpath(rsp_data1.json(), '$..id') with allure.step("step3: 步骤3 ==>> 根据部门id获取部门下所有项目id"): if request_parameters['addInfo'] == '项目权限未传': project_ids = [] elif request_parameters['addInfo'] == '事业部与所选项目不符合': rsp_data2 = getter.user_findProject(cookies=cookies, divIds=branch_id[1], mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) project_ids = jsonpath.jsonpath(rsp_data2.json(), '$..id') else: rsp_data2 = getter.user_findProject(cookies=cookies, divIds=branch_id[0], mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) project_ids = jsonpath.jsonpath(rsp_data2.json(), '$..id') with allure.step("step4: 步骤4 ==>> 获取岗位id"): if request_parameters['addInfo'] == '岗位id系统中不存在': jobId = '123123123123432' elif request_parameters['addInfo'] == '岗位未传': jobId = '' else: rsp_data3 = getter.user_findJob(cookies=cookies, mobileType=2, pageNum=1, pageSize=10000, token=token, userid=userId) jobId = rsp_data3.json()['data']['list'][0]['id'] with allure.step("step5: 步骤5 ==>> 新增用户"): if request_parameters['addInfo'] == '用户名未传': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='', password='******', phone='13200000001', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) elif request_parameters['addInfo'] == '手机号未传': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) elif request_parameters['addInfo'] == '手机号格式不是手机号': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='19864800001', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) elif request_parameters['addInfo'] == '手机号重复': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='13168775547', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) elif request_parameters['addInfo'] == '密码未传': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='', phone='13200000001', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) elif request_parameters['addInfo'] == '在职状态未传': rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='13200000001', projectIds=project_ids, status='', token=token, userid=userId, mobileType=2) else: rsp_branch = getter.user_save(cookies=cookies, divisionId=branch_id[0], jobId=jobId, name='测试用户001', password='******', phone='13200000001', projectIds=project_ids, status=1, token=token, userid=userId, mobileType=2) assert rsp_branch.status_code == 200 assert rsp_branch.json()['data'] is None assert rsp_branch.json()['message'] == expected_response['message'] assert rsp_branch.json()['status'] == expected_response['status']
from API.api_get_data import getter import jsonpath token, userId, cookies = getter.get_login_token_cookies('13168775547', '123', 2) # print(token, userId) rsp_data1 = getter.user_findDivision(cookies=cookies, pageNum=1, pageSize=10000, mobileType=2, token=token, userid=userId) # print(rsp_data1.json()) branch_id = jsonpath.jsonpath(rsp_data1.json(), '$..id') print(branch_id) rsp_data2 = getter.user_findProject(cookies=cookies, divIds=branch_id[0], pageNum=1, mobileType=2, pageSize=10000, token=token, userid=userId) project_ids = jsonpath.jsonpath(rsp_data2.json(), '$..id') print(project_ids)
from API.api_get_data import getter from common.logger import logger import pytest token, userId, cookies = getter.get_login_token_cookies('admin', 'admin', mobileType=2) @pytest.fixture() def add_organization(): """ 添加测试部门数据 :return: """ try: rsp_tree = getter.organization_findOrganizationTree(cookies=cookies, code='01', mobileType=2, token=token, userid=userId) company_id = rsp_tree.json()['data']['list'][0]['id'] for i in range(3): getter.organization_save(cookies=cookies, label=f'测试部门{i+1}', pid=company_id, mobileType=2, type='2', token=token, userid=userId) yield rsp_bm = getter.organization_findDivision(cookies=cookies, mobileType=2, token=token, userid=userId) for i, item in enumerate(rsp_bm.json()['data']['list']): if item['label'] == f'测试部门{i+1}': branch_id = item['id'] getter.organization_delete(cookies=cookies, mobileType=2, id=branch_id, token=token, userid=userId) except Exception as e: logger.error(f"添加组织前置执行失败,错误为{e}") @pytest.fixture() def add_project(): """