def test_update(self, cas): url = conf.get('env', 'url') + cas['url'] method = cas['method'] cas['data'] = replace_data(cas['data']) data = eval(cas['data']) headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 respones = request(url=url, method=method, json=data, headers=headers) res = respones.json() try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) #判断数据库中是否更新昵称 if cas['check_sql']: sql = replace_data(cas['check_sql']) s = self.bb.find_one(sql)['reg_name'] self.assertEqual(data['reg_name'], s) except AssertionError as e: log.error('该用例{}报错'.format(cas['title'])) log.exception(e) self.exce.write(row=row, column=8, value='不通过') raise e else: log.info('该用例{}通过'.format(cas['title'])) self.exce.write(row=row, column=8, value='通过')
def test_register(self, cas): url = cas['url'] method = cas['method'] if '#phone#' in cas['data']: phon = self.phone_replace() setattr(EnvData, 'mobile_phone', phon) cas['data'] = replace_data(cas['data']) data = eval(cas['data']) headers = eval(conf.get('env', 'headers')) expected = eval(cas['expected']) row = cas['case_id'] + 1 respones = request(url=url, method=method, json=data, headers=headers) res = respones.json() try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) if cas['check_sql']: sql = replace_data(cas['check_sql']) f = self.my.find_count(sql) self.assertEqual(1, f) except AssertionError as e: log.error('这条用例{}报错'.format(cas['title'])) log.exception(e) self.exce.write(row=row, column=8, value='不通过') raise e else: log.info('这条用例{}通过了'.format(cas['title'])) self.exce.write(row=row, column=8, value='通过')
def test_audit(self, cas): url = conf.get('env', 'url') + cas['url'] method = cas['method'] data = eval(replace_data(cas['data'])) headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'admin_token') expected = eval(cas['expected']) row = cas['case_id'] + 1 respones1 = request(url=url, method=method, json=data, headers=headers) res1 = respones1.json() if cas['title'] == '审核通过' and res1['msg'] == 'OK': setattr(EnvData, 'pass_loan_id', str(data['loan_id'])) print('预期结果:', expected) print('实际结果:', res1) try: self.assertEqual(expected['code'], res1['code']) self.assertEqual(expected['msg'], res1['msg']) #判断审核状态是否符合预期的结果 if cas['check_sql']: sql = replace_data(cas['check_sql']) status = self.bb.find_one(sql)['status'] self.assertEqual(expected['status'], status) except AssertionError as e: log.error('这条用例{}没有通过'.format(cas['title'])) log.exception(e) self.exce.write(row=row, column=8, value='不通过') raise e else: log.info('这条用例{}执行通过'.format(cas['title'])) self.exce.write(row=row, column=8, value='通过')
def test_loans(self, cas): cas['url'] = replace_data(cas['url']) url = conf.get('env', 'url') + cas['url'] headers = eval(conf.get('env', 'headers')) headers["Authorization"] = getattr(EnvData, "token") method = cas['method'] expected = eval(cas['expected']) row = cas['case_id'] + 1 respones = request(url=url, method=method, headers=headers) res = respones.json() try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: log.error('用例--{}--未通过'.format(cas['title'])) log.debug('预期结果{}'.format(expected)) log.debug('实际结果{}:'.format(res)) log.exception(e) self.execl.write(row=row, column=8, value='不通过') raise e else: log.info('用例--{}--通过'.format(cas['title'])) self.execl.write(row=row, column=8, value='通过')
def test_audit(self, cas): # 准备数据 url = conf.get('env', 'url') + cas['url'] # 判断是否需要替换为审核通过的标id if "#pass_loan_id#" in cas['data']: cas['data'] = replace_data(cas['data']) cas['data'] = replace_data(cas['data']) data = eval(cas['data']) method = cas['method'] headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'admin_token') expected = eval(cas['expected']) row = cas['case_id'] + 1 # 获取实际结果 response = request(url=url, method=method, json=data, headers=headers) rese = response.json() print('预期结果:', expected) print('实际结果:', rese) # 判断是否是审核通过的用例,并且审核成功 if cas['title'] == '审核通过' and rese['msg'] == 'OK': setattr(EnvData, 'pass_loan_id', str(data['loan_id'])) try: self.assertEqual(expected['code'], rese['code']) self.assertEqual(expected['msg'], rese['msg']) if cas['check_sql']: sql = replace_data(cas['check_sql']) status = self.bb.find_one(sql)['status'] self.assertEqual(expected['status'], status) print(status, type(status)) except AssertionError as e: log.error('用例--{}--未通过'.format(cas['title'])) log.debug('预期结果{}'.format(expected)) log.debug('实际结果{}:'.format(rese)) log.exception(e) self.excel.write(row=row, column=8, value='不通过') raise e else: log.info('用例--{}--通过'.format(cas['title'])) self.excel.write(row=row, column=8, value='通过')
def test_add(self, cas): # 准备用例数据 url = conf.get('env', 'url') + cas['url'] cas['data'] = replace_data(cas['data']) data = eval(cas['data']) method = cas['method'] headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 # 请求之前查询用户标的数量 if cas['check_sql']: sql = replace_data(cas['check_sql']) st = self.bb.find_count(sql) print('请求之前的标数:', st) response = request(url=url, method=method, json=data, headers=headers) res = response.json() print('预期结果:', expected) print('实际结果:', res) # 请求后查询用户标的数量 try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) if cas['check_sql']: sql = replace_data(cas['check_sql']) end = self.bb.find_count(sql) print('请求之后标数', end) self.assertEqual(1, end - st) except AssertionError as e: log.error('用例--{}--未通过'.format(cas['title'])) log.debug('预期结果{}'.format(expected)) log.debug('实际结果{}:'.format(res)) log.exception(e) self.excel.write(row=row, column=8, value='不通过') raise e else: log.info('用例--{}--通过'.format(cas['title'])) self.excel.write(row=row, column=8, value='通过')
def test_register(self,cas): url = conf.get('env','url2') + '/user/register/' method = cas['method'] expected = eval(cas['expected']) if '#username#' in cas['data']: username = self.usernam_data() setattr(EnvData,'username',username) cas['data'] = replace_data(cas['data']) if '#email#' in cas['data']: email = self.email_data() setattr(EnvData,'email',email) cas['data'] = replace_data(cas['data']) data = eval(cas['data']) respones = request(url=url,method=method,json=data) res = respones.json() #判断用户名是否注册 url3 = 'http://api.keyou.site:8000/keyou1/count/' try: self.assertEqual(res[ ])
def test_add(self, cas): url = conf.get('env', 'url') + cas['url'] method = cas['method'] cas['data'] = replace_data(cas['data']) data = eval(cas['data']) headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 #查询添加项目之前的标的数量 if cas['check_sql']: sql = replace_data(cas['check_sql']) f = self.bb.find_count(sql) respones = request(url=url, method=method, json=data, headers=headers) res = respones.json() print('预期结果:', expected) print('实际结果:', res) try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) #查询加标后标的数量 if cas['check_sql']: sql = replace_data(cas['check_sql']) q = self.bb.find_count(sql) self.assertEqual(1, q - f) except AssertionError as e: log.error('该用例{}错误'.format(cas['title'])) log.exception(e) self.exce.write(row=row, column=8, value='不通过') raise e else: log.info('该用例{}通过'.format('通过')) self.exce.write(row=row, column=8, value='通过')
def test_withdraw(self,cas): url = conf.get('env','url') + cas['url'] method = cas['method'] #替换用例中中的#member_id# cas['data'] = replace_data(cas['data']) data = eval(cas['data']) headers = eval(conf.get('env','headers')) headers['Authorization'] = getattr(EnvData,'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 #查询取现之前的金额 if cas['check_sql']: sql = replace_data(cas['check_sql']) money_start = self.bb.find_one(sql)['leave_amount'] respons = request(url=url,method=method,json=data,headers=headers) res = respons.json() try: self.assertEqual(expected['code'],res['code']) self.assertEqual(expected['msg'],res['msg']) #查询取现之后账户的金额 if cas['check_sql']: sql = replace_data(cas['check_sql']) money_end = self.bb.find_one(sql)['leave_amount'] #将用例数据的金额数值类型转换为decimal f = decimal.Decimal(str(data['amount'])) self.assertEqual(f,money_start-money_end) except AssertionError as e: log.error('该用例{}未通过'.format(cas['title'])) log.exception(e) self.exce.write(row=row,column=8,value='不通过') raise e else: log.info('该用例{}通过'.format(cas['title'])) self.exce.write(row=row,column=8,value='不通过')
def test_recharge(self, cas): url = conf.get('env', 'url') + cas['url'] method = cas['method'] headers = eval(conf.get('env', 'headers')) headers['Authorization'] = getattr(EnvData, 'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 #替换用例中的数据 cas['data'] = replace_data(cas['data']) data = eval(cas['data']) #查询充值之前的账户金额 if cas['check_sql']: sql = replace_data(cas['check_sql']) money_start = self.bb.find_one(sql)['leave_amount'] response = request(url=url, method=method, json=data, headers=headers) res1 = response.json() try: self.assertEqual(expected['code'], res1['code']) self.assertEqual(expected['msg'], res1['msg']) #查询充值后的账户金额 if cas['check_sql']: sql = replace_data(cas['check_sql']) money_end = self.bb.find_one(sql)['leave_amount'] #将用例数据中的金额值类型转换,因为数据库中的数据类型是decimal s = decimal.Decimal(str(data['amount'])) self.assertEqual(s, money_end - money_start) except AssertionError as e: log.error('这条用例{}没有通过'.format(cas['title'])) log.exception(e) self.exce.write(row=row, column=8, value='不通过') raise e else: log.info('这条用例{}执行通过'.format(cas['title'])) self.exce.write(row=row, column=8, value='通过')
def test_invest(self, cas): url = conf.get('env', 'url') + cas['url'] method = cas['method'] data = eval(replace_data(cas['data'])) headers = eval(conf.get('env', 'headers')) if cas['interface'] != 'login': #如果不是登录的接口需要添加token headers['Authorization'] = getattr(EnvData, 'token') expected = eval(cas['expected']) row = cas['case_id'] + 1 respones = request(url=url, method=method, json=data, headers=headers) res = respones.json() if cas['interface'] == 'login': #如果是登录接口,需要提取id和token token = 'Bearer' + ' ' + jsonpath.jsonpath(res, '$..token')[0] member_id = str(jsonpath.jsonpath(res, '$..id')[0]) setattr(EnvData, 'token', token) setattr(EnvData, 'member_id', member_id) if cas['interface'] == 'add': #如果是加标接口,需要获取加标后的标id loan_id = str(jsonpath.jsonpath(res, '$..id')[0]) setattr(EnvData, 'loan_id', loan_id) print('预期结果:', expected) print('实际结果:', res) try: self.assertEqual(expected['code'], res['code']) self.assertEqual(expected['msg'], res['msg']) except AssertionError as e: log.error('这是{}用例未通过'.format(cas['title'])) log.debug('预期结果{}'.format(expected)) log.debug('实际结果{}'.format(res)) log.exception(e) self.excel.write(row=row, column=8, value='不通过') raise e else: log.info('用例{}通过'.format(cas['title'])) self.excel.write(row=row, column=8, value='通过')