Exemplo n.º 1
0
 def setUpClass(cls):
     cls.conf = ReadConfig()
     sql = 'SELECT * FROM future.member WHERE MobilePhone = "{}"'.format(getattr(contex, 'normal_user'))
     mysql = MySql()
     value = mysql.fet_one(sql=sql)
     setattr(contex, 'normal_user_id', str(value['Id']))
     cls.url = cls.conf.get('url', 'url')
Exemplo n.º 2
0
 def setUpClass(cls):
     conf = ReadConfig()
     cls.mylog = MyLog()
     mysql = MySql()
     options = conf.getoptions('test_user')
     for item in options:
         memberId_sql = 'SELECT Id from future.member WHERE MobilePhone = "{0}"'.format(
             conf.getstr('test_user', item)['user'])
         cls.mylog.info('初始化用户数据sql:{}'.format(memberId_sql))
         memberId = mysql.fet_one(memberId_sql)
         setattr(contex, item + '_id', str(memberId['Id']))
         cls.mylog.info('获取到{},的id是{}'.format(conf.getstr('test_user', item)['user'], memberId['Id']))
Exemplo n.º 3
0
class LoadAdd(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.conf = ReadConfig()
        sql = 'SELECT * FROM future.member WHERE MobilePhone = "{}"'.format(getattr(contex, 'normal_user'))
        mysql = MySql()
        value = mysql.fet_one(sql=sql)
        setattr(contex, 'normal_user_id', str(value['Id']))
        cls.url = cls.conf.get('url', 'url')

    def setUp(self):
        self.mysql = MySql()
        new_title = self.conf.get('project', 'new_title')
        new_title2 = new_title[:4] + str(int(new_title[4::1]) + 1)
        self.conf.set('project', 'new_title', new_title2)

    @data(*data_case)
    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)
Exemplo n.º 4
0
 def setUp(self):
     self.mysql = MySql()
     sql = DoRegex().replace(conf.get('sql', 'sql'))
     val = self.mysql.fet_one(sql)
     if val:  # 将借款标id写入到contex中
         setattr(contex, 'loanid', str(val['Id']))
         sql1 = DoRegex().replace(conf.get('sql', 'sql1'))
         print('执行sql:', sql1)
         sel_value = self.mysql.fet_one(sql1)
         if sel_value['投资人账号余额']:  # 下面将 投资改标的 以投资金额, 投资人信息 写入到contex类
             setattr(contex, '投资人账号余额', sel_value['投资人账号余额'])
             Balance = int(sel_value['借款金额']) - int(sel_value['已投资总额'])
             setattr(contex, '剩余可投金额', Balance)
             setattr(contex, '已投资总额', sel_value['已投资总额'])
             self.mylog.info('投资人账号余额:{},已投资总额:{},剩余可投金额:{}'.format(getattr(contex, '投资人账号余额'), getattr(contex, '已投资总额'),
                                                            getattr(contex, '剩余可投金额')))
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
class LidLoan(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        conf = ReadConfig()
        cls.mylog = MyLog()
        mysql = MySql()
        options = conf.getoptions('test_user')
        for item in options:
            memberId_sql = 'SELECT Id from future.member WHERE MobilePhone = "{0}"'.format(
                conf.getstr('test_user', item)['user'])
            cls.mylog.info('初始化用户数据sql:{}'.format(memberId_sql))
            memberId = mysql.fet_one(memberId_sql)
            setattr(contex, item + '_id', str(memberId['Id']))
            cls.mylog.info('获取到{},的id是{}'.format(conf.getstr('test_user', item)['user'], memberId['Id']))

    def setUp(self):
        self.mysql = MySql()
        sql = DoRegex().replace(conf.get('sql', 'sql'))
        val = self.mysql.fet_one(sql)
        if val:  # 将借款标id写入到contex中
            setattr(contex, 'loanid', str(val['Id']))
            sql1 = DoRegex().replace(conf.get('sql', 'sql1'))
            print('执行sql:', sql1)
            sel_value = self.mysql.fet_one(sql1)
            if sel_value['投资人账号余额']:  # 下面将 投资改标的 以投资金额, 投资人信息 写入到contex类
                setattr(contex, '投资人账号余额', sel_value['投资人账号余额'])
                Balance = int(sel_value['借款金额']) - int(sel_value['已投资总额'])
                setattr(contex, '剩余可投金额', Balance)
                setattr(contex, '已投资总额', sel_value['已投资总额'])
                self.mylog.info('投资人账号余额:{},已投资总额:{},剩余可投金额:{}'.format(getattr(contex, '投资人账号余额'), getattr(contex, '已投资总额'),
                                                               getattr(contex, '剩余可投金额')))

    @data(*data_case)
    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)

    def tearDown(self):
        self.mysql.mysql_close()
Exemplo n.º 8
0
 def setUp(self):
     self.mysql = MySql()
     new_title = self.conf.get('project', 'new_title')
     new_title2 = new_title[:4] + str(int(new_title[4::1]) + 1)
     self.conf.set('project', 'new_title', new_title2)
Exemplo n.º 9
0
 def setUp(self):
     sql = 'SELECT * FROM future.member WHERE MobilePhone = "{}" '.format(
         getattr(contex, 'loanid_user'))
     value = MySql().fet_one(sql=sql)
     setattr(contex, 'LeaveAmount', value['LeaveAmount'])