class TestOrganizationFindOrganizationTree(object):
    """
    组织架构-树查询接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '组织架构',
                                               '查询树结构成功'))
    def test_organization_findOrganizationTree_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_tree = getter.organization_findOrganizationTree(
                cookies=cookies,
                code=request_parameters['code'],
                label=request_parameters['label'],
                mobileType=2,
                token=token,
                userid=userId)
            assert rsp_tree.status_code == 200
            assert rsp_tree.json()['data'] is not None
            assert rsp_tree.json()['message'] == expected_response['message']
            assert rsp_tree.json()['status'] == expected_response['status']

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '组织架构',
                                               '查询失败'))
    def test_organization_findOrganizationTree_fail(self, request_parameters,
                                                    expected_response):
        pass
コード例 #2
0
class TestUserUpdate(object):
    """
    修改用户信息接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '修改用户信息成功'))
    def test_user_update_success(self, request_parameters, expected_response):
        pass

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '修改用户信息失败'))
    def test_user_update_fail(self, request_parameters, expected_response):
        pass
コード例 #3
0
class TestUserList(object):
    """
    用户列表接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '查询用户列表成功'))
    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_user_list_fail(self):
        pass
コード例 #4
0
class TestLogout(object):
    """
    退出登录接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '注销成功'))
    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']
コード例 #5
0
class TestLogin(object):
    """
    登录接口测试
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '登录成功'))
    def test_login_success(self, request_parameters, expected_response):
        with allure.step("step1: 步骤1 ==>> 使用正确用户名密码登录系统"):
            rsp_login = getter.user_login(
                phone=request_parameters['phone'],
                password=request_parameters['password'],
                rememberMe=request_parameters['rememberMe'],
                mobileType=2,
            )
            logger.info(
                f"本次测试登录账号为{request_parameters['phone']}========>接口返回状态码为{rsp_login.status_code},"
                f"message为{rsp_login.json()['message']},status为{rsp_login.json()['status']}"
            )

        assert rsp_login.status_code == 200
        assert rsp_login.json()['data'] is not None
        assert rsp_login.json()['message'] == expected_response['message']
        assert rsp_login.json()['status'] == expected_response['status']

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '登录失败'))
    def test_login_fail(self, request_parameters, expected_response):
        with allure.step("step1: 步骤1 ==>> 使用错误用户名密码登录系统"):
            rsp_login = getter.user_login(
                phone=request_parameters['phone'],
                password=request_parameters['password'],
                rememberMe=request_parameters['rememberMe'],
                mobileType=2,
            )
            logger.info(
                f"本次测试登录账号为{request_parameters['phone']}========>接口返回状态码为{rsp_login.status_code},"
                f"message为{rsp_login.json()['message']},status为{rsp_login.json()['status']}"
            )

        assert rsp_login.status_code == 200
        assert rsp_login.json()['data'] is None
        assert rsp_login.json()['message'] in expected_response['message']
        assert rsp_login.json()['status'] == expected_response['status']
コード例 #6
0
class TestUserDetail(object):
    """
    用户详情接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '获取用户详情成功'))
    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_userDetail_fail(self):
        pass
コード例 #7
0
class TestUserFindProject(object):
    """
    查询所有项目
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理',
                                               '查询项目成功'))
    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_user_findProject_fail(self):
        pass
コード例 #8
0
class TestUserDelete(object):
    """
    删除用户接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '删除用户成功'))
    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

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '删除用户失败'))
    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']
コード例 #9
0
class TestUserSave(object):
    """
    用户管理-新增接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '新增用户成功'))
    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']

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '用户管理', '新增用户失败'))
    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']
コード例 #10
0
class TestOrganizationSave(object):
    """
    组织架构新增接口
    """
    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '组织架构', '公司新增'))
    def test_organization_save_equative(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', mobileType=2, token=token, userid=userId)
            company_id = rsp_tree.json()['data']['list'][0]['id']

        with allure.step("step3: 步骤3 ==>> 添加组织架构"):
            rsp_add = getter.organization_save(cookies=cookies, label=request_parameters['label'], pid=company_id,
                                               type=request_parameters['type'], mobileType=2, token=token, userid=userId)
            logger.info(f"添加返回结果为:{rsp_add.json()}")

        with allure.step("step4: 步骤4 ==>> 查询当前组织架构,验证是否添加成功"):
            rsp_select = getter.organization_findDivision(cookies=cookies, mobileType=2, 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']

    @pytest.mark.parametrize(('request_parameters', 'expected_response'),
                             getter.load_excel('监理api接口自动化测试用例.xls', '组织架构', '部门新增'))
    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']