class TestGetFinanceLogList(unittest.TestCase):

    def setUp(self):
        self.mysql = MysqlUtil()

    @data(*cases)
    def test_getFinanceLogList(self, case):
        data = DoRegex.replace(case.data)  # 参数化处理
        data = json.loads(data)  # 将测试数据由字符串序列化成字典

        if hasattr(Context, 'cookies'):  # 判断是否有cookies
            cookies = getattr(Context, 'cookies')  # 获取放到上下文里面的cookies
        else:
            cookies = None
        # Request封装类请求
        resp = Request(method=case.method, url=case.url, data=data, cookies=cookies)
        resp_dict = resp.get_json()  # 获取请求响应,字典
        # 判断返回里面是否有cookies(有说明是登录接口)
        if resp.get_cookies():  # 判断返回里面是否有cookies
            setattr(Context, 'cookies', resp.get_cookies())  # 放入到上下文中

        print("status_code:", resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected, int(resp_dict['code']))  # 判断返回的code是否与期望结果一致

        # 数据库校验
        if resp_dict['msg'] == "获取用户流水记录成功!":
            # 从数据库查financelog表中某个用户的全部流水记录
            sql_select_financelog = "SELECT * FROM future.financelog WHERE PayMemberID = {} ORDER BY Id DESC;".format(Context.invest_member_id)
            invest_list = self.mysql.fetch_all(sql_select_financelog)
            # 根据用户ID获取financelog表中某用户的流水记录的最大行数
            sql_select_row = "SELECT COUNT(Id) FROM future.financelog WHERE PayMemberID = {};".format(Context.invest_member_id)
            max_row = self.mysql.fetch_one(sql_select_row)['COUNT(Id)']

            if invest_list is not None:
                for i in range(0, max_row):  # 每一行数据校验
                    MyLog.info("正在校验第{}行数据".format(i))
                    # 判断请求返回的数据详情与数据库里面的详情是否一致
                    # 多个字段一致才assert通过
                    self.assertEqual(int(resp_dict['data'][i]['id']), invest_list[i]['Id'])
                    self.assertEqual(int(resp_dict['data'][i]['payMemberId']), invest_list[i]['PayMemberId'])
                    self.assertEqual(int(resp_dict['data'][i]['incomeMemberId']), invest_list[i]['IncomeMemberId'])
                    self.assertEqual(float(resp_dict['data'][i]['amount']), invest_list[i]['Amount'])
                    # 注意:钱是空值时!!! --- 还需再改!
                    # self.assertEqual(float(resp_dict['data'][i]['incomeMemberMoney']), invest_list[i]['IncomeMemberMoney'])
                    # self.assertEqual(float(resp_dict['data'][i]['payMemberMoney']), float(invest_list[i]['PayMemberMoney']))
                    self.assertEqual(int(resp_dict['data'][i]['status']), invest_list[i]['Status'])
                    self.assertEqual(resp_dict['data'][i]['createTime'][0:19], invest_list[i]['CreateTime'].strftime("%Y-%m-%d %H:%M:%S"))
                    MyLog.info("校验结果:PASS")

    def tearDown(self):
        self.mysql.close()
class TestList(unittest.TestCase):
    def setUp(self):
        self.mysql = MysqlUtil()

    @data(*cases)
    def test_list(self, case):
        data = DoRegex.replace(case.data)
        data = json.loads(data)

        # 先判断有没有cookies
        if hasattr(Context, 'cookies'):
            cookies = getattr(Context, 'cookies')
        else:
            cookies = None
        # 通过封装的Request类来完成接口的调用
        resp = Request(method=case.method,
                       url=case.url,
                       data=data,
                       cookies=cookies)
        # 判断返回里面是否有cookies(有说明是登录接口)
        if resp.get_cookies():
            setattr(Context, 'cookies', resp.get_cookies())  # cookies放入到上下文中

        print("status_code:", resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected,
                         int(resp_dict['code']))  # 判断返回的code是否与期望结果一致

        # 完成数据库校验
        if resp_dict['msg'] == "获取用户列表成功":
            # 从数据库查到member表全部用户的信息
            # member_list是一个列表,列表是按照用户ID顺序排序。其中的元素是一个个字典。
            # resp_dict['data'] 也是一个列表,列表是按照用户ID顺序排序。其中的元素是一个个字典。
            sql_select_member = "SELECT * FROM future.member WHERE Id != '' ORDER BY Id ASC;"
            member_list = self.mysql.fetch_all(sql_select_member)
            # 获取member表最大行数
            sql_select_row = "SELECT COUNT(Id) FROM future.member;"
            max_row = self.mysql.fetch_one(sql_select_row)['COUNT(Id)']
            if member_list is not None:  # 如果从数据库里面查询出来不是空
                for i in range(0, max_row):  # 每一行数据校验
                    # 判断请求返回的数据详情与数据库里面的详情是否与一致
                    # 多个字段一致才assert通过
                    self.assertEqual(resp_dict['data'][i]['id'],
                                     member_list[i]['Id'])
                    self.assertEqual(resp_dict['data'][i]['mobilephone'],
                                     member_list[i]['MobilePhone'])
                    self.assertEqual(resp_dict['data'][i]['pwd'],
                                     member_list[i]['Pwd'])
                    self.assertEqual(resp_dict['data'][i]['regname'],
                                     member_list[i]['RegName'])
                    self.assertEqual(
                        float(resp_dict['data'][i]['leaveamount']),
                        float(member_list[i]['LeaveAmount']))
                    self.assertEqual(
                        resp_dict['data'][i]['regtime'][0:19], member_list[i]
                        ['RegTime'].strftime("%Y-%m-%d %H:%M:%S"))
                    self.assertEqual(int(resp_dict['data'][i]['type']),
                                     member_list[i]['Type'])

    def tearDown(self):
        self.mysql.close()
Beispiel #3
0
class TestGetLoanList(unittest.TestCase):
    def setUp(self):
        self.mysql = MysqlUtil()

    @data(*cases)
    def test_getLoanList(self, case):
        data = DoRegex.replace(case.data)  # 参数化处理
        data = json.loads(data)  # 字符串序列化为字典
        # 先判断有没有cookies
        if hasattr(Context, 'cookies'):
            cookies = getattr(Context, 'cookies')
        else:
            cookies = None
        # 通过封装的Request类来完成接口的调用
        resp = Request(method=case.method,
                       url=case.url,
                       data=data,
                       cookies=cookies)
        # 判断返回里面是否有cookies(有说明是登录接口)
        if resp.get_cookies():
            setattr(Context, 'cookies', resp.get_cookies())  # cookies放入到上下文中
        print("status_code:", resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected,
                         int(resp_dict['code']))  # 判断返回的code是否与期望结果一致

        # 完成数据库校验
        if resp_dict['msg'] == "获取标列表成功":
            # 从数据库查到loan表全部标的信息
            # loan_list是一个列表,列表是按照标的ID顺序排序。其中的元素是一个个字典。
            # resp_dict['data'] 也是一个列表,列表是按照标的ID顺序排序。其中的元素是一个个字典。
            sql_select_loan = "SELECT * FROM future.loan WHERE Id != '' ORDER BY Id ASC;"
            loan_list = self.mysql.fetch_all(sql_select_loan)
            # 获取loan表最大行数
            sql_select_row = "SELECT COUNT(Id) FROM future.loan;"
            max_row = self.mysql.fetch_one(sql_select_row)['COUNT(Id)']
            if loan_list is not None:  # 如果从数据库里面查询出来不是空
                for i in range(0, max_row):  # 每一行数据校验
                    # 判断数据库里面的标的详情是否与请求返回的数据详情一致
                    # 多个字段一致才assert通过
                    self.assertEqual(int(resp_dict['data'][i]['id']),
                                     loan_list[i]['Id'])
                    self.assertEqual(int(resp_dict['data'][i]['memberId']),
                                     loan_list[i]['MemberID'])
                    self.assertEqual(resp_dict['data'][i]['title'],
                                     loan_list[i]['Title'])
                    self.assertEqual(float(resp_dict['data'][i]['amount']),
                                     float(loan_list[i]['Amount']))
                    self.assertEqual(float(resp_dict['data'][i]['loanRate']),
                                     float(loan_list[i]['LoanRate']))
                    self.assertEqual(int(resp_dict['data'][i]['loanTerm']),
                                     loan_list[i]['LoanTerm'])
                    self.assertEqual(int(resp_dict['data'][i]['loanDateType']),
                                     loan_list[i]['LoanDateType'])
                    self.assertEqual(int(resp_dict['data'][i]['repaymemtWay']),
                                     loan_list[i]['RepaymemtWay'])
                    self.assertEqual(int(resp_dict['data'][i]['biddingDays']),
                                     loan_list[i]['BiddingDays'])
                    self.assertEqual(int(resp_dict['data'][i]['status']),
                                     loan_list[i]['Status'])
                    self.assertEqual(
                        resp_dict['data'][i]['createTime'][0:19], loan_list[i]
                        ['CreateTime'].strftime("%Y-%m-%d %H:%M:%S"))
                    # 时间是空值时,怎么校验???
                    # self.assertEqual(resp_dict['data'][i]['biddingStartTime'][0:19], loan_list[i]['BiddingStartTime'].strftime("%Y-%m-%d %H:%M:%S"))
                    # self.assertEqual(resp_dict['data'][i]['fullTime'][0:19],loan_list[i]['FullTime'].strftime("%Y-%m-%d %H:%M:%S"))
                    MyLog.info("正在校验数据库第{}行数据,结果:PASS".format(i + 1))

    def tearDown(self):
        self.mysql.close()
class TestFetInvestsByLoanId(unittest.TestCase):
    def setUp(self):
        self.mysql = MysqlUtil()

    @data(*cases)
    def test_getInvestsByLoanId(self, case):
        data = DoRegex.replace(case.data)  # 参数化处理
        data = json.loads(data)  # 将测试数据由字符串序列化成字典

        if hasattr(Context, 'cookies'):  # 判断是否有cookies
            cookies = getattr(Context, 'cookies')  # 获取放到上下文里面的cookies
        else:
            cookies = None
        # Request封装类请求
        resp = Request(method=case.method,
                       url=case.url,
                       data=data,
                       cookies=cookies)
        resp_dict = resp.get_json()  # 获取请求响应,字典
        # 判断返回里面是否有cookies(有说明是登录接口)
        if resp.get_cookies():  # 判断返回里面是否有cookies
            setattr(Context, 'cookies', resp.get_cookies())  # 放入到上下文中

        print("status_code:", resp.get_status_code())  # 打印响应码
        resp_dict = resp.get_json()  # 获取请求响应,字典
        self.assertEqual(case.expected,
                         int(resp_dict['code']))  # 判断返回的code是否与期望结果一致

        # 数据库校验
        if resp_dict['msg'] == "获取记录成功":
            # 从数据库查invest表中某个标的/项目的全部投资记录
            sql_select_invest = "SELECT * FROM future.invest WHERE LoanId = {} ORDER BY Id DESC;".format(
                Context.invest_List_by_loan_id)
            invest_list = self.mysql.fetch_all(sql_select_invest)
            # 根据标的/项目ID获取invest表中某个标的/项目的投资记录的最大行数
            sql_select_row = "SELECT COUNT(Id) FROM future.invest WHERE LoanId = {};".format(
                Context.invest_List_by_loan_id)
            max_row = self.mysql.fetch_one(sql_select_row)['COUNT(Id)']

            if invest_list is not None:
                for i in range(0, max_row):  # 每一行数据校验
                    MyLog.info("正在校验第{}行数据".format(i))
                    # 判断请求返回的数据详情与数据库里面的详情是否一致
                    # 多个字段一致才assert通过
                    self.assertEqual(int(resp_dict['data'][i]['id']),
                                     invest_list[i]['Id'])
                    self.assertEqual(int(resp_dict['data'][i]['memberId']),
                                     invest_list[i]['MemberID'])
                    self.assertEqual(int(resp_dict['data'][i]['loanId']),
                                     invest_list[i]['LoanId'])
                    self.assertEqual(float(resp_dict['data'][i]['amount']),
                                     invest_list[i]['Amount'])
                    self.assertEqual(int(resp_dict['data'][i]['isValid']),
                                     invest_list[i]['IsValid'])
                    self.assertEqual(
                        resp_dict['data'][i]['createTime'][0:19],
                        invest_list[i]['CreateTime'].strftime(
                            "%Y-%m-%d %H:%M:%S"))
                    MyLog.info("校验结果:PASS")

    def tearDown(self):
        self.mysql.close()