def test_recharge(self, case): # 必须传输一条case my_logger = MyLog() data = DoRegex.replace(case.data) # 首先从excel中取出来,然后做正则 data = json.loads(data) # 然后在loads if hasattr(Context, 'cookies'): # 第一次登陆没有cookies,所以要判断 # 参数化处理 cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) # 判断有没有cookies if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies()) my_logger.debug(res.get_json()) try: self.assertEqual(str(case.expected), res.get_json()['code']) except AssertionError as e: my_logger.error("{} not found".format(e)) raise e if res.get_json()['msg'] == '充值成功': try: self.assertEqual(str(self.leaveamount + 10), res.get_json()['data']['leaveamount']) except AssertionError as a: my_logger.error("余额不正确,报错{}".format(a))
def test_withdraw(self, case): my_logger = MyLog() my_logger.debug("执行第{}条案例".format(case.case_id)) data = DoRegex.replace(case.data) data = json.loads(data) if hasattr(Context, 'cookies'): cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies()) my_logger.debug(res.get_json()) try: self.assertEqual(case.expected, int(res.get_json()['code'])) except AssertionError as e: my_logger.error("断言失败!") raise e if res.get_json()['msg'] == '取现成功': expected = float(self.start_amount) - float(data['amount']) actual = self.mysql.fetch_one(self.sql)['LeaveAmount'] try: self.assertEqual(expected, actual) except AssertionError as e: raise e else: expected = float(self.start_amount) actual = self.mysql.fetch_one(self.sql)['LeaveAmount'] self.assertEqual(expected, actual)
def test_list(self, case): my_logger = MyLog() if case.data != None: data = DoRegex.replace(case.data) # 正则调用,替换正则表达式的数据 data = json.loads(data) if hasattr(Context, 'cookies'): cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) print(res.get_json()) if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies())
def test_getInvestsByMemberId(self, case): # 必须传输一条case my_logger = MyLog() data = DoRegex.replace(case.data) # 首先从excel中取出来,然后做正则 data = json.loads(data) # 然后在loads if hasattr(Context, 'cookies'): # 第一次登陆没有cookies,所以要判断 cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) # 判断有没有cookies if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies()) my_logger.debug(res.get_json()) try: self.assertEqual(str(case.expected), res.get_json()['code']) except AssertionError as e: my_logger.error("断言失败") raise e resp_dict = res.get_json() if resp_dict['msg'] == '获取用户投资列表成功': my_logger.debug("获取用户投资列表成功")
def test_generateRepayments(self, case): # 必须传输一条case my_logger = MyLog() data = DoRegex.replace(case.data) # 首先从excel中取出来,然后做正则 print(type(data)) data = json.loads(data) # 然后在loads print(data) if hasattr(Context, 'cookies'): # 第一次登陆没有cookies,所以要判断 cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) # 判断有没有cookies if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies()) my_logger.debug(res.get_json()) try: self.assertEqual(str(case.expected), res.get_json()['code']) except AssertionError as e: my_logger.error("断言失败") raise e
def test_add(self, case): # 必须传输一条case my_logger = MyLog() data = DoRegex.replace(case.data) # 首先从excel中取出来,然后做正则 data = json.loads(data) # 然后在loads if hasattr(Context, 'cookies'): # 第一次登陆没有cookies,所以要判断 cookies = getattr(Context, 'cookies') else: cookies = None res = Request(method=case.method, url=case.url, data=data, cookies=cookies) # 判断有没有cookies if res.get_cookies(): setattr(Context, 'cookies', res.get_cookies()) my_logger.debug(res.get_json()) try: self.assertEqual(str(case.expected), res.get_json()['code']) except AssertionError as e: my_logger.error("断言失败") raise e resp_dict = res.get_json() if resp_dict['msg'] == '加标成功': select_loan = 'select * from future.loan where memberId = {0} order by createtime desc limit 1'.format( Context.loan_member_id_1) loan = self.mysql.fetch_one(select_loan) if loan is not None: # 如果从数据库里面查询出来不是空,则创建标的成功 # 判断数据库里面的标的详情是否与测试数据一致 self.assertEqual(data['amount'], loan['Amount']) # 多个字段一致才assert通过 # 其他的自己加 # 将创建成功的标的ID写入到上下文中,用于之后投资用 setattr(Context, 'loan_id', str(loan['Id'])) # 放一个str类型的进去,以备后面正则替换 else: raise AssertionError # 如果数据库里面没有数据,就测试失败