Example #1
0
class TestRegisterApi(Base):
    """注册接口"""
    test_data = do_excel.get_name_tuple_all_value(
        do_conf('SheetName', 'Register'))

    @data(*test_data)
    def test_register(self, value):
        row = value.CaseId + 1  # 用例ID所在行号
        title = value.Title  # 用例标题
        url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
        request_value = value.Data  # 请求参数
        request_method = value.Method  # 请求方法
        log.info('开始执行注册-"{}"测试用例'.format(title))
        # 转json的目的是防止期望结果和实际结果的字符串形式匹配不上(excel 存储的期望结果有空格)
        expected = HandleJson.json_to_python(value.Expected)  # 期望结果
        not_exist_phone = self.mysql.get_not_exist_phone()  # 正向用例的注册账号
        request_value = register_login_parameters(not_exist_phone,
                                                  request_value)
        response = self.request(request_method, url=url, data=request_value)
        actual_result = response.json()
        do_excel.write_cell(do_conf('SheetName', 'Register'), row,
                            do_conf('ExcelNum', 'Actual_Column'),
                            response.text)
        try:
            self.assertEqual(expected,
                             actual_result,
                             msg='测试{}失败'.format(title))
        except AssertionError as e:
            do_excel.write_cell(do_conf('SheetName', 'Register'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Fail'),
                                color=RED)
            log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
                inspect.stack()[0][3], title, e))
            raise e
        else:
            do_excel.write_cell(do_conf('SheetName', 'Register'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Pass'),
                                color=GREEN)
            log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
        log.info('执行注册-测试用例"{}"结束'.format(title))
Example #2
0
class TestAddApi(Base):
    """加标接口"""
    test_data = do_excel.get_name_tuple_all_value(do_conf('SheetName', 'add'))

    def setUp(self):
        # 管理员登录加标
        login.login_api(method='post',
                        url=do_conf('URL', 'Host_Url') + '/member/login',
                        data={
                            "mobilephone": str(do_user('Admin',
                                                       'mobilephone')),
                            "pwd": (do_user('Admin', 'pwd'))
                        })

    @data(*test_data)
    def test_add(self, value):
        row = value.CaseId + 1  # 用例ID所在行号
        precondition = value.Precondition  # excel用例的前置条件
        title = value.Title  # 用例标题
        url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
        request_method = value.Method  # 请求方法
        request_value = value.Data  # 请求参数
        select_sql = value.Sql  # 查询数据库中不存在的member id
        add_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
        if precondition == '借款人用户ID不存在':
            not_exist_loan_member_id = str(
                int(self.mysql(select_sql)['Id']) - 1)
            request_value = add_parameters(not_exist_loan_member_id,
                                           request_value)
        else:
            request_value = add_parameters('', request_value)
        log.info('执行加标-测试用例"{}"开始'.format(title))
        response = request(request_method, url=url, data=request_value)
        actual_result = response.json()
        do_excel.write_cell(do_conf('SheetName', 'Add'), row,
                            do_conf('ExcelNum', 'Actual_Column'),
                            response.text)
        try:
            self.assertEqual(add_expected,
                             actual_result,
                             msg='测试{}失败'.format(title))
        except AssertionError as e:
            do_excel.write_cell(do_conf('SheetName', 'Add'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Fail'),
                                color=RED)
            log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
                inspect.stack()[0][3], title, e))
            raise e
        else:
            do_excel.write_cell(do_conf('SheetName', 'Add'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Pass'),
                                color=GREEN)
            log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
        log.info('执行加标-测试用例"{}"结束'.format(title))

    def tearDown(self):
        login.close()
Example #3
0
class TestBidLoanApi(Base):
    """竞标接口"""
    test_data = do_excel.get_name_tuple_all_value(
        do_conf('SheetName', 'invest'))

    @classmethod
    def setUpClass(cls):
        cls.mysql = HandleMysql()
        # 管理人员登录
        login.login_api(method='post',
                        url=do_conf('URL', 'Host_Url') + '/member/login',
                        data={
                            "mobilephone": str(do_user('Admin',
                                                       'mobilephone')),
                            "pwd": (do_user('Admin', 'pwd'))
                        })
        # 管理人加标
        add.add_loan_api(method='post',
                         url=do_conf('URL', 'Host_Url') + '/loan/add',
                         data={
                             "memberId": str(do_user('Invest', 'memberid')),
                             "title": "超哥专属标的",
                             "amount": 1000000,
                             "loanRate": 10,
                             "loanTerm": 3,
                             "loanDateType": 0,
                             "repaymemtWay": 4,
                             "biddingDays": 5
                         })
        sql = 'SELECT Id FROM loan WHERE MemberID={0} ORDER BY CreateTime DESC LIMIT 1;'.format(
            str(do_user('Invest', 'memberid')))
        loan_id = str(cls.mysql(sql=sql)['Id'])
        setattr(DataReplace, 'loan_id', loan_id)
        # 管理人审核
        audit.audit_loan_api(method='post',
                             url=do_conf('URL', 'Host_Url') + '/loan/audit',
                             data={
                                 "id": loan_id,
                                 "status": 4
                             })
        # 投资人登录
        login.login_api(method='post',
                        url=do_conf('URL', 'Host_Url') + '/member/login',
                        data={
                            "mobilephone": str(do_user('Invest',
                                                       'mobilephone')),
                            "pwd": (('Invest', 'pwd'))
                        })

    @data(*test_data)
    def test_bid_loan(self, value):
        row = value.CaseId + 1  # 用例ID所在行号
        precondition = value.Precondition  # excel用例的前置条件
        title = value.Title  # 用例标题
        url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
        request_method = value.Method  # 请求方法
        request_value = value.Data  # 请求参数
        select_sql = value.Sql
        audit_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
        if precondition == '投资人不存在':
            not_exist_member_id = str(int(self.mysql(select_sql)['Id']) - 1)
            setattr(DataReplace, 'non_exist_member_id', not_exist_member_id)
            request_value = invest_parameters(request_value)
        elif precondition == '标的不存在':
            not_exist_loan_id = str(int(self.mysql(select_sql)['Id']) - 1)
            setattr(DataReplace, 'non_exist_loan_id', not_exist_loan_id)
            request_value = invest_parameters(request_value)
        elif precondition == '标的非竞标状态':
            # 设置标的为非竞标状态
            audit.audit_loan_api(method='post',
                                 url=do_conf('URL', 'Host_Url') +
                                 '/loan/audit',
                                 data={
                                     "id": getattr(DataReplace, 'loan_id'),
                                     "status": 1
                                 })
            request_value = invest_parameters(request_value)
        elif precondition == '标的金额不足':
            audit.audit_loan_api(method='post',
                                 url=do_conf('URL', 'Host_Url') +
                                 '/loan/audit',
                                 data={
                                     "id": getattr(DataReplace, 'loan_id'),
                                     "status": 4
                                 })
            request_value = invest_parameters(request_value)
        elif precondition == '标的满标':  # 这里不确定测试的对不对
            sql = invest_parameters(select_sql)
            remain_amount = float(
                self.mysql(sql=sql)["invest_amount"])  # 标的剩余金额
            setattr(DataReplace, 'remain_amount',
                    remain_amount)  # 给DataReplace添加一个剩余金额类属性
            request_value = invest_parameters(request_value)
            request(request_method, url=url, data=request_value)
        else:
            request_value = invest_parameters(request_value)
        log.info('执行竞标-测试用例"{}"开始'.format(title))
        response = request(request_method, url=url, data=request_value)
        actual_result = response.json()
        do_excel.write_cell(do_conf('SheetName', 'invest'), row,
                            do_conf('ExcelNum', 'Actual_Column'),
                            response.text)
        try:
            self.assertEqual(audit_expected,
                             actual_result,
                             msg='测试{}失败'.format(title))
        except AssertionError as e:
            do_excel.write_cell(do_conf('SheetName', 'invest'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Fail'),
                                color=RED)
            log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
                inspect.stack()[0][3], title, e))
            raise e
        else:
            do_excel.write_cell(do_conf('SheetName', 'invest'),
                                row,
                                do_conf('ExcelNum', 'Result_Column'),
                                do_conf('Result', 'Pass'),
                                color=GREEN)
            log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
        log.info('执行竞标-测试用例"{}"结束'.format(title))

    @classmethod
    def tearDownClass(cls):
        login.close()
        cls.mysql.close()
Example #4
0
class TestAddApi(Base):
    """添加班级接口"""
    test_data = do_excel.get_name_tuple_all_value("class")
    pc_two = ParseConfigFile()
    method = pc_two.getConfValue(CONFIG_PATH, "DeleteClass", "method")
    url = pc_two.getConfValue(CONFIG_PATH, "DeleteClass", "url")
    request_value = pc_two.getConfValue(CONFIG_PATH, "DeleteClass", "data")

    def setUp(self):
        method = self.pc_two.getConfValue(CONFIG_PATH, "ClassSetUp", "method")
        url = self.pc_two.getConfValue(CONFIG_PATH, "ClassSetUp", "url")
        data = self.pc_two.getConfValue(CONFIG_PATH, "ClassSetUp", "data")
        try:
            response = self.request(method, url, data=data)
            log.info(response.json())
        except Exception as e:
            raise e
            log.info("添加班级失败")

    @data(*test_data)
    def test_add_class(self, value):
        pc = ParseConfigFile()
        row = value.CaseId + 1  #测试用列的编号
        title = value.Precondition  #用列标题
        # url = pc.getConfValue(CONFIG_PATH,"URL","Host_Url") + value.URL #用例URL
        url = "http://ci.ytesting.com/api/3school/school_classes"
        # log.info(url)
        request_value = value.Data  #请求参数
        log.info(request_value)
        request_method = value.Method  #请求方法
        exist = value.Exist
        log.info("exist的值为{},数据类型为{}".format(exist, type(exist)))
        log.info('开始执行班级-"{}"测试用例'.format(title))
        if request_method == "get" or request_method == "post":
            response = self.request(request_method, url, data=request_value)
            request_value = HandleJson.json_to_python(
                request_value)  # 将传输的数据变成Python格式的数据
            second_response = classManage.get_class_invitecode_and_id(
                request_value["grade"])  # 获取添加之后的invitecode和id的值
            expect_text = value.Expected  # 得到期望值
            last_expect = register_add_class(str(second_response[0]),
                                             str(second_response[1]),
                                             expect_text)
            last_expect = HandleJson.json_to_python(last_expect)
        elif request_method == "put":
            if exist:
                exist_Id = HandleJson.json_to_python(exist)
                url = classManage.modify_class_manage(data=exist,
                                                      grade=exist_Id["grade"])
            else:
                url = classManage.modify_class_manage()
            log.info("修改班级之前获取到的{}和现有的班级{}".format(
                url, classManage.get_class_invitecode_and_id()))
            response = self.request(request_method, url, data=request_value)
            expect_text = value.Expected
            last_expect = HandleJson.json_to_python(expect_text)
        else:
            self.request(self.method, self.url, data=self.request_value)
            request = HandleJson.json_to_python(self.request_value)
            classId = (classManage.get_class_invitecode_and_id(
                request["grade"])[1])
            log.info("获取删除的calssId{}".format(classId))
            if exist:
                response = classManage.delete_add_class(classId, exist)
                log.info("当exist不为空的时候返回的值为{},response的值为{}".format(
                    response.json, response))
            else:
                response = classManage.delete_add_class(classId)
                log.info("exist的值为resposne的值为{}".format(response))
            last_expect = value.Expected  #得到期望值
            last_expect = HandleJson.json_to_python(last_expect)
        log.info(response.text)
        actual_result = response.json()
        do_excel.write_cell(
            pc.getConfValue(CONFIG_PATH, "SheetName", "Class"), int(row),
            int(pc.getConfValue(CONFIG_PATH, "ExcelNum", "Actual_Column")),
            response.text)
        try:
            self.assertEqual(last_expect,
                             actual_result,
                             msg="测试{}失败".format(title))
        except AssertionError as e:
            do_excel.write_cell(
                pc.getConfValue(CONFIG_PATH, "SheetName", "Class"),
                int(row),
                int(pc.getConfValue(CONFIG_PATH, "ExcelNum", "Result_Column")),
                pc.getConfValue(CONFIG_PATH, "Result", 'Fail'),
                color=RED)
            log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
                inspect.stack()[0][3], title, e))
            raise e

        else:
            do_excel.write_cell(
                pc.getConfValue(CONFIG_PATH, "SheetName", "Class"),
                int(row),
                int(pc.getConfValue(CONFIG_PATH, "ExcelNum", "Result_Column")),
                pc.getConfValue(CONFIG_PATH, "Result", 'Pass'),
                color=GREEN)
            log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
        log.info('执行班级-测试用例"{}"结束'.format(title))

    def tearDown(self):
        clament = classManage.get_class_invitecode_and_id()
        for one in clament["retlist"]:
            if one["studentnumber"] is None:
                pass
            else:
                classManage.delete_add_class(one["id"])
Example #5
0
class TestRechargeApi(Base):
    """充值接口"""
    test_data = do_excel.get_name_tuple_all_value(do_conf('SheetName', 'Recharge'))

    def setUp(self):
        # 投资人登录充值
        login.login_api(method='post',
                        url=do_conf('URL', 'Host_Url') + '/member/login',
                        data={"mobilephone": str(do_user('Invest', 'mobilephone')),
                              "pwd": (do_user('Invest', 'pwd'))}
                        )

    @data(*test_data)
    def test_recharge(self, value):
        row = value.CaseId + 1  # 用例ID所在行号
        precondition = value.Precondition  # excel用例的前置条件
        title = value.Title  # 用例标题
        url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
        request_value = value.Data  # 请求参数
        request_method = value.Method  # 请求方法
        select_sql = value.Sql  # 查询充值结果的sql语句
        replace_sql = recharge_parameters(select_sql)
        recharge_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
        log.info('执行充值-测试用例"{}"开始'.format(title))
        request_value = recharge_parameters(request_value)
        before_amount = self.mysql(sql=replace_sql)['LeaveAmount']  # 充值前的金额
        # 切换会话
        if precondition == '用户未登录':
            response = self.request(request_method, url=url, data=request_value)
        else:
            response = request(request_method, url=url, data=request_value)
        after_amount = self.mysql(sql=replace_sql)['LeaveAmount']  # 充值后的金额
        actual_amount = str(after_amount - before_amount)  # 实际金额
        actual_code = response.json()['code']  # 实际code
        # 构造个实际结果的字典
        actual_result = dict(leaveamount=actual_amount, code=actual_code)
        do_excel.write_cell(
            do_conf('SheetName', 'Recharge'),
            row,
            do_conf('ExcelNum', 'Actual_Column'),
            HandleJson.python_to_json(actual_result)
        )
        try:
            self.assertEqual(recharge_expected, actual_result, msg='测试{}失败'.format(title))
        except AssertionError as e:
            do_excel.write_cell(
                do_conf('SheetName', 'Recharge'),
                row,
                do_conf('ExcelNum', 'Result_Column'),
                do_conf('Result', 'Fail'),
                color=RED)
            log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(inspect.stack()[0][3], title, e))
            raise e
        else:
            do_excel.write_cell(
                do_conf('SheetName', 'Recharge'),
                row,
                do_conf('ExcelNum', 'Result_Column'),
                do_conf('Result', 'Pass'),
                color=GREEN)
            log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
        log.info('执行登录-测试用例"{}"结束'.format(title))

    def tearDown(self):
        login.close()