Beispiel #1
0
 def test_withdraw(self, item):
     result = None
     params = json.loads(DoRegex().replace(item.params))  # 处理初始化数据
     url = getattr(contex, 'url') + item.url
     if hasattr(contex, 'COOKIES'):  # 处理COOKIES
         COOKIES = getattr(contex, 'COOKIES')
     else:
         COOKIES = None
     resp = Request(method=item.method,
                    url=url,
                    data=params,
                    cookies=COOKIES)  # 开始HTTP请求
     if resp.cookies():
         setattr(contex, 'COOKIES', resp.cookies())
     # withdraw_title = item['title'][0:4]
     # if withdraw_title == '成功取现':
     if resp.get_json()['msg'] == '取现成功':
         sql = 'SELECT * FROM future.member WHERE MobilePhone = {} '.format(
             params['mobilephone'])
         value = MySql().fet_one(sql)
         data_LeaveAmount = value['LeaveAmount']  # 数据库中的金额
         contex_LeaveAmount = getattr(contex,
                                      'LeaveAmount')  # 反射类contex中的金额
         actual_value = Decimal(contex_LeaveAmount) - Decimal(
             params['amount'])  # 预期金额等于 contex金额减请求参数中的金额
         request_value = resp.get_json()
         excepted_value = json.loads(item.expected)
         print('data_LeaveAmount:', data_LeaveAmount)
         print('actual_value:', actual_value)
         try:  # 判断数据库金额是否等于预期金额 | 预期结果和响应报文中的值是否一致
             assert data_LeaveAmount == actual_value
             result = 'Pass'
         except Exception as e:
             result = 'Failed'
             raise e
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
     elif resp.get_json()['msg'] == '充值成功':
         result = 'Pass'
         read.write_result(item.caseid + 1, 7, resp.get_txt())
         read.write_result(item.caseid + 1, 8, result)
     else:
         try:
             self.assertEqual(resp.get_txt(), item.expected)
             result = 'Pass'
         except Exception as e:
             result = 'Failed'
             raise e
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
Beispiel #2
0
 def test_recharge(self, item):
     '''通过反射查看是否有COOKIES的值'''
     if hasattr(contex, 'COOKIES'):
         COOKIES = getattr(contex, 'COOKIES')
     else:
         COOKIES = None
     params = item.params
     '''通过读取配置文件替换params中的用户名或密码,并序列化'''
     params = json.loads(DoRegex().replace(params))
     url = getattr(contex, 'url') + item.url
     resp = Request(method=item.method,
                    url=url,
                    data=params,
                    cookies=COOKIES)
     '''登陆成功后将获取到的值通过反射写入到配置类中'''
     if resp.cookies():
         setattr(contex, 'COOKIES', resp.cookies())
     result = None
     actual = resp.get_txt()
     if resp.get_json()['msg'] == '充值成功':
         sql = 'SELECT * FROM future.member WHERE MobilePhone = "{}" '.format(
             params['mobilephone'])
         value = MySql().fet_one(sql=sql)
         actual_value = value['LeaveAmount']  # 获取充值后的金额
         excetp = actual_value - Decimal(params['amount'])  # 预期用户金额
         excepted = json.loads(item.expected)
         request_actual = resp.get_json()
         try:
             assert Decimal(excetp) == Decimal(getattr(contex,'LeaveAmount')) and int(value['MobilePhone']) == int(params['mobilephone']) \
                    and request_actual['code'] == excepted['code']and request_actual['msg'] == excepted['msg'] \
                    and request_actual['status'] == excepted['status']
             result = 'Pass'
         except Exception as e:
             result = 'Failed'
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
     else:  # 充值失败的值校验响应报文
         try:
             self.assertEqual(actual, item.expected)
             result = 'Pass'
         except Exception as e:
             result = 'Failed'
             myloger1.mylog.error(e)
             raise e
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
Beispiel #3
0
    def test_loadadd(self, item):
        global result
        if hasattr(contex, 'COOKIES'):
            COOKIES = getattr(contex, 'COOKIES')
        else:
            COOKIES = None
        url = self.url + item.url
        params = json.loads(DoRegex().replace(item.params))
        if item.caseid > 1:
            params['title'] = self.conf.get('project', 'new_title')
        resp = Request(method=item.method, url=url, data=params, cookies=COOKIES)
        if resp.cookies():
            COOKIES = setattr(contex,'COOKIES',resp.cookies())

        try:

            self.assertEqual(resp.get_txt(), item.expected)
            if resp.get_json()['msg'] == '加标成功':
                sql = 'SELECT * FROM future.loan WHERE MemberID = "{}" AND Title = "{}"'.format(
                    getattr(contex, 'normal_user_id'), params['title'])
                check_db = self.mysql.fet_one(sql=sql)
                self.assertEqual(check_db['Title'],params['title'])
            elif resp.get_json()['msg'] == '登录成功':
                print('这是登录')
            else:
                sql = 'SELECT * FROM future.loan WHERE MemberID = "{}" AND Title = "{}"'.format(
                    getattr(contex, 'normal_user_id'), params['title'])
                check_db = self.mysql.fet_one(sql=sql)
                self.assertEqual(check_db, None)
            result = 'Pass'
        except Exception as e:
            result = 'Failed'
            raise e
        finally:
            read.write_result(item.caseid+1, 7,resp.get_txt())
            read.write_result(item.caseid+1, 8,result)
Beispiel #4
0
 def test_lidLoan(self, item):
     global result, check_db
     # 处理登录用户的COOKIES
     if hasattr(contex, 'COOKIES'):
         COOKIES = getattr(contex, 'COOKIES')
     else:
         COOKIES = None
     self.mylog.info('获取到用户登录COOKIES:{}'.format(COOKIES))
     params = item.params
     params = json.loads(DoRegex().replace(params))
     url = getattr(contex,'url')+item.url
     self.mylog.info('测试数据请求初始化{}'.format(params))
     if item.title == '投资金额大于标的余额':  # 执行投资金额大于标的余额的用例
         Balance = getattr(contex, '剩余可投金额') + Decimal(1000)
         params['amount'] = Balance
         resp = Request(method=item.method, url=url, data=params, cookies=COOKIES)
         excepted = json.loads(item.expected)
         actual = resp.get_json()
         try:
             assert actual['status'] == excepted['status'] and actual['code'] == excepted['code']
             result = 'Pass'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
         except Exception as e:
             result = 'Failed'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
             self.mylog.error(e)
             raise e
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
     elif item.title == '将标投满':  # 执行将表注满的用例
         Balance = getattr(contex, '剩余可投金额')
         params['amount'] = Balance
         resp = Request(method=item.method, url=url, data=params, cookies=COOKIES)
         if resp.cookies():
             setattr(contex, 'COOKIES', resp.cookies())
         try:
             self.assertEqual(resp.get_txt(), item.expected)
             result = 'Pass'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
         except Exception as e:
             result = 'Failed'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
             self.mylog.error(e)
             raise
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)
     else:  # 执行其他用例
         resp = Request(method=item.method, url=url, data=params, cookies=COOKIES)
         if resp.cookies():
             setattr(contex, 'COOKIES', resp.cookies())
         try:
             self.assertEqual(resp.get_txt(), item.expected)
             result = 'Pass'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
         except Exception as e:
             result = 'Failed'
             self.mylog.info('{}用例执行结果:{}'.format(item.title, result))
             self.mylog.error(e)
             raise
         finally:
             read.write_result(item.caseid + 1, 7, resp.get_txt())
             read.write_result(item.caseid + 1, 8, result)