class TestLogin(unittest.TestCase): excel = do_excel.DoExcel(contant.case_file, 'recharge') cases = excel.get_cases() @classmethod def setUpClass(cls): cls.http_request = http_request.HttpRequest() cls.mysql = do_mysql.MySql() @data(*cases) def test_register(self, case): logger.info('开始执行用例:{0}----------'.format(case.title)) if case.sql is not None: sql = eval(case.sql)['sql1'] member = self.mysql.fetch_one_dict(sql) before_amount = member['LeaveAmount'] resp = self.http_request.http_request(case.method, case.url, case.data) actual_code = resp.json()['code'] try: self.assertEqual(case.expected, int(actual_code)) self.excel.write(case.case_id + 1, resp.text, 'PASS') if case.sql is not None: sql = eval(case.sql)['sql1'] member = self.mysql.fetch_one_dict(sql) after_amount = member['LeaveAmount'] recharge_amount = int(eval(case.data)['amount']) self.assertEqual(before_amount + recharge_amount, after_amount) except AssertionError as e: self.excel.write(case.case_id + 1, resp.text, 'FASLE') raise e logger.info('用例执行完成----------')
class TestLogin(unittest.TestCase): excel = do_excel.DoExcel(contant.case_file, 'invest') cases = excel.get_cases() @classmethod def setUpClass(cls): cls.http_request = http_request.HttpRequest() cls.mysql = do_mysql.MySql() @data(*cases) def test_register(self, case): logger.info('开始执行用例:{0}----------'.format(case.title)) case.data = context.replace(case.data) resp = self.http_request.http_request(case.method, case.url, case.data) logger.info('请求返回的结果:{0}----------'.format(resp.text)) actual_code = resp.json()['code'] try: self.assertEqual(case.expected, int(actual_code)) self.excel.write(case.case_id + 1, resp.text, 'PASS') #判断加标成功之后,查询数据库,取到load_id if resp.json()['msg'] == '加标成功': sql = "select id from future.loan where memberid = 801 order by id desc limit 1" loan_id = self.mysql.fetch_one_dict(sql)['id'] logger.info('标的ID:{0}'.format(loan_id)) setattr(Context, "loan_id", str(loan_id)) except AssertionError as e: self.excel.write(case.case_id + 1, resp.text, 'FASLE') logger.error('和预期结果对比报错,错误为{0}'.format(e)) logger.info('用例执行完成----------') @classmethod def tearDownClass(cls): cls.http_request.close() cls.mysql.close()
class TestResgiter(unittest.TestCase): excel = do_excel.DoExcel(contant.case_file, 'register') cases = excel.get_cases() @classmethod def setUpClass(cls): cls.http_request = http_request.HttpRequest() cls.mysql = do_mysql.MySql() @data(*cases) def test_register(self, case): logger.info('开始执行用例:{0}----------'.format(case.title)) if case.data.find('register_mobile') > -1: #判断参数化标识 sql = 'select max(mobilephone) from future.member' max_phone = self.mysql.fetch_one_tuple(sql)[0] #最大手机号码加1 max_phone = int(max_phone) + 1 case.data = case.data.replace('register_mobile', str(max_phone)) resp = self.http_request.http_request(case.method, case.url, case.data) try: self.assertEqual(case.expected, resp.text) self.excel.write(case.case_id + 1, resp.text, 'PASS') except AssertionError as e: self.excel.write(case.case_id + 1, resp.text, 'FASLE') raise e logger.info('用例执行完成----------')
class TestLogin(unittest.TestCase): excel = do_excel.DoExcel(contant.case_file, 'add') cases = excel.get_cases() @classmethod def setUpClass(cls): cls.http_request = http_request.HttpRequest() @data(*cases) def test_register(self, case): logger.info('开始执行用例:{0}----------'.format(case.title)) case.data = context.replace(case.data) resp = self.http_request.http_request(case.method, case.url, case.data) actual_code = resp.json()['code'] try: self.assertEqual(case.expected, int(actual_code)) self.excel.write(case.case_id + 1, resp.text, 'PASS') except AssertionError as e: self.excel.write(case.case_id + 1, resp.text, 'FASLE') raise e logger.info('用例执行完成----------') @classmethod def tearDownClass(cls): cls.http_request.close()