class TestRegister(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() # 注册请求 # @parameterized.expand(read_register_files) @parameterized.expand( read_param_data( "register.json", "test_register", "phone,pwd,verifycode,phone_code,dy_server,invitephone,status_code,status,description" )) def test_register_success(self, phone, pwd, imgcode, phone_code, dy_server, invite_phone, status_code, status, description): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(status_code, response.status_code) # 获取短信验证码 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, pwd, imgcode, phone_code, dy_server, invite_phone) assert_utils(self, response, status_code, status, description) logging.info("register-response{}".format(response.json())) @classmethod def setUpClass(cls) -> None: sql1 = "delete log.* from mb_member_login_log log inner join mb_member ber on log.member_id = ber.id where log.member_name in ('18212345670','18212345671','18212345672','18212345673','18212345674','18212345675','18212345676');" DBUtils.execute_sql(sql1) logging.info("sql1={}".format(sql1)) sql2 = "delete reg.* from mb_member_register_log reg inner join mb_member ber on reg.member_name = ber.phone where reg.phone in ('18212345670','18212345671','18212345672','18212345673','18212345674','18212345675','18212345676');" DBUtils.execute_sql(sql2) logging.info("sql2={}".format(sql2)) sql3 = "delete fo.* from mb_member_info fo left join mb_member ber on fo.member_id = ber.id where fo.member_name in ('18212345670','18212345671','18212345672','18212345673','18212345674','18212345675','18212345676');" DBUtils.execute_sql(sql3) logging.info("sql3={}".format(sql3)) sql4 = "delete from mb_member where name in ('18212345670','18212345671','18212345672','18212345673','18212345674','18212345675','18212345676');" DBUtils.execute_sql(sql4) logging.info("sql4={}".format(sql4))
class TestGetImgVerifCode(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() # 获取验证码方法 @parameterized.expand(read_imgcode_files) def test_get_imgverifycode_success(self, type, status_code): if type == "float": r = str(random.random()) elif type == "int": r = str(random.randint(100000, 9999999)) elif type == "kong": r = "" elif type == "char": r = ''.join(random.sample("biagjkbskjnsd", 6)) # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, r) self.assertEqual(status_code, response.status_code)
def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session()
class TestLoginAll(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() # 定义获取验证码方法,随机数为小数 def test01_get_imgverifycode_success(self): r = random.random() print(r) # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 随机数为整数 def test02_get_imgverifycode_success(self): r = random.randint(10000, 999999) print(r) # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 随机数为空 def test03_get_imgverifycode_None(self): # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, "") # 断言 self.assertEqual(404, response.status_code) # 随机数为字母 def test04_get_imgverifycode_error(self): r_list = random.sample("ndjhiubjnkn", 7) r = "".join(r_list) print(r) # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, r) # 断言 self.assertEqual(400, response.status_code) # 获取短信验证码成功 def test05_get_phone_code_success(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE1 response = self.loginapi.get_phonecode(self.session, phone) # 断言 assert_utils(self, response, 200, 200, "短信发送成功") print(response.json()) # 获取短信验证码失败,图片验证码错误 def test06_get_phone_code_error(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone_data = { "phone": "18212345670", "imgVerifyCode": "1111", "type": "reg" } response = self.loginapi.get_phonecode(self.session, phone_data) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) self.assertIn("图片验证码错误", response.json().get("description")) # 获取短信验证码失败,未获取图片验证码 def test07_get_phone_code_error(self): # 先获取图片验证码 # 获取短信验证码 phone_data = { "phone": "18212345670", "imgVerifyCode": "8888", "type": "reg" } response = self.loginapi.get_phonecode(self.session, phone_data) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) self.assertIn("图片验证码错误", response.json().get("description")) # 获取短信验证码失败,手机号为空 def test08_get_phone_code_error(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone_data = {"phone": "", "imgVerifyCode": "8888", "type": "reg"} response = self.loginapi.get_phonecode(self.session, phone_data) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) # 获取短信验证码失败,图片验证码为空 def test09_get_phone_code_error(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone_data = { "phone": "18212345670", "imgVerifyCode": "", "type": "reg" } response = self.loginapi.get_phonecode(self.session, phone_data) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) self.assertIn("图片验证码错误", response.json().get("description")) # 填写所有必填参数,注册成功 def test01_register_success(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE1 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone) assert_utils(self, response, 200, 200, "注册成功") logging.info("register-response{}".format(response.json())) # 填写所有全部参数,注册成功 def test02_register_success(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE2 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, "13312345678") assert_utils(self, response, 200, 200, "注册成功") logging.info("register-response{}".format(response.json())) # 图片验证码为空,注册失败 def test03_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE3 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, imgcode='') assert_utils(self, response, 200, 100, "短信验证码不能为空") logging.info("register-response{}".format(response.json())) # 短信验证码为空,注册失败 def test04_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE3 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, phone_code="") assert_utils(self, response, 200, 100, "验证码不能为空!") logging.info("register-response{}".format(response.json())) # 图片验证码错误时,注册失败 def test05_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) # 断言 self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE3 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, imgcode='1111') assert_utils(self, response, 200, 100, "验证码错误!") logging.info("register-response{}".format(response.json())) # 短信验证码错误时,注册失败 def test06_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE3 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, phone_code='555555') assert_utils(self, response, 200, 100, "验证码错误") logging.info("register-response{}".format(response.json())) # 手机号已存在时,注册失败 def test07_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE1 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone) assert_utils(self, response, 200, 100, "手机已存在!") logging.info("register-response{}".format(response.json())) # 密码为空时,注册失败 def test08_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE3 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, pwd='') assert_utils(self, response, 200, 100, "密码不能为空") logging.info("register-response{}".format(response.json())) # 不同意注册条款时,注册失败 def test09_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE4 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, dy_server='off') assert_utils(self, response, 200, 100, "请同意我们的条款") logging.info("register-response{}".format(response.json())) # 邀请人手机号错误,注册失败 def test10_register_fail(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE5 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone, invite_phone="error") assert_utils(self, response, 200, 100, "推荐人不存在") logging.info("register-response{}".format(response.json())) # 填写所有必填参数,注册成功(备用注册手机号码) def test11_register_success(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE6 response = self.loginapi.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.loginapi.register(self.session, phone) assert_utils(self, response, 200, 200, "注册成功") logging.info("register-response{}".format(response.json())) # 登录成功 def test01_login_success(self): # 登录请求 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 登录失败,未注册账号 def test02_login_fail(self): response = self.loginapi.login(self.session, phone='19856231254') assert_utils(self, response, 200, 100, "用户不存在") logging.info("login-response{}".format(response.json())) # 登录失败,密码为空 def test03_login_fail(self): response = self.loginapi.login(self.session, pwd="") assert_utils(self, response, 200, 100, "密码不能为空") logging.info("login-response{}".format(response.json())) # 登录失败,手机号账号 def test04_login_fail(self): response = self.loginapi.login(self.session, "") assert_utils(self, response, 200, 100, "用户名不能为空") logging.info("login-response{}".format(response.json())) # 登录失败,密码错误 def test05_login_fail(self): # 第一次密码错误尝试登录 response = self.loginapi.login(self.session, pwd="123") assert_utils(self, response, 200, 100, "密码错误1次,达到3次将锁定账户") logging.info("login-response{}".format(response.json())) # 第二次密码错误尝试登录 response = self.loginapi.login(self.session, pwd="123") assert_utils(self, response, 200, 100, "密码错误2次,达到3次将锁定账户") logging.info("login-response{}".format(response.json())) # 第三次密码错误尝试登录 response = self.loginapi.login(self.session, pwd="123") assert_utils(self, response, 200, 100, "由于连续输入错误密码达到上限,账号已被锁定,请于1.0分钟后重新登录") logging.info("login-response{}".format(response.json())) # 三次密码错误之后,输入正确用户名和密码,登录失败 response = self.loginapi.login(self.session) assert_utils(self, response, 200, 100, "由于连续输入错误密码达到上限,账号已被锁定,请于1.0分钟后重新登录") logging.info("login-response{}".format(response.json())) # 三次密码错误之后,1分钟解锁之后输入正确用户名和密码,登录成功 time.sleep(61) response = self.loginapi.login(self.session) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 判断是否登录 response = self.loginapi.islogin(self.session) assert_utils(self, response, 200, 200, "OK") logging.info("login-response{}".format(response.json())) # 未登录时,判断是否登录 def test06_islogin_fail(self): response = self.loginapi.islogin(self.session) assert_utils(self, response, 200, 250, "您未登陆!") logging.info("login-response{}".format(response.json()))
class Business_Process_Loan(unittest.TestCase): def setUp(self) -> None: self.hmlc_api = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() @classmethod def tearDownClass(cls) -> None: sql1 = "delete log.* from mb_member_login_log log inner join mb_member ber on log.member_id = ber.id where log.member_name = '18212345676';" DBUtils.execute_sql(sql1) sql2 = "delete reg.* from mb_member_register_log reg inner join mb_member ber on reg.member_name = ber.phone where reg.phone = '18212345676';" DBUtils.execute_sql(sql2) sql3 = "delete fo.* from mb_member_info fo left join mb_member ber on fo.member_id = ber.id where fo.member_name = '18212345676';" DBUtils.execute_sql(sql3) sql4 = "delete from mb_member where name = '18212345676';" DBUtils.execute_sql(sql4) def test01_business_process_loan_success(self): # 先获取图片验证码 r = random.random() # 调用图片验证码接口 response = self.hmlc_api.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 获取短信验证码 phone = PHONE_x response = self.hmlc_api.get_phonecode(self.session, phone) assert_utils(self, response, 200, 200, "短信发送成功") # 注册请求 response = self.hmlc_api.register(self.session, phone) assert_utils(self, response, 200, 200, "注册成功") logging.info("register-response{}".format(response.json())) # 登录请求 phone = PHONE_x response = self.hmlc_api.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.hmlc_api.approve(self.session, "胡翠花", "320412198409047436") assert_utils(self, response, 200, 200, "提交成功!") logging.info("login-response{}".format(response.json())) # 发送获取认证信息请求 response = self.hmlc_api.get_approve(self.session) self.assertEqual(200, response.status_code) # 发送开户请求 response = self.hmlc_api.account(self.session) logging.info("account response={}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方开户接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("UserRegister OK", response.text) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.hmlc_api.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.hmlc_api.recharge(self.session, "100") logging.info("recharge response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方充值接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("NetSave OK", response.text) # 获取存在的项目详情 response = self.hmlc_api.loaninfo(self.session) logging.info("loaninfo-response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 进行投资 response = self.hmlc_api.tender(self.session) logging.info("loan response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方投资接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("InitiativeTender OK", response.text) # 查询我的投资列表 response = self.hmlc_api.mytenderlist(self.session) self.assertEqual(200, response.status_code)
class TestApprove(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() # 正确姓名和身份证号,提交成功 def test01_pprove_success(self): # 先登录账号 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.loginapi.approve(self.session, "甘道夫", "440307199008077699") assert_utils(self, response, 200, 200, "提交成功!") logging.info("login-response{}".format(response.json())) # 发送获取认证信息请求 response = self.loginapi.get_approve(self.session) self.assertEqual(200, response.status_code) # 姓名为空,提交失败 def test02_pprove_fail(self): # 先登录账号 phone = PHONE2 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.loginapi.approve(self.session, "", "440307199008077699") assert_utils(self, response, 200, 100, "姓名不能为空") logging.info("login-response{}".format(response.json())) # 身份证号为空,提交失败 def test03_pprove_fail(self): # 先登录账号 phone = PHONE2 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.loginapi.approve(self.session, "甘道夫", "") assert_utils(self, response, 200, 100, "身份证号不能为空") logging.info("login-response{}".format(response.json())) # 身份证号错误,提交失败 def test04_pprove_fail(self): # 先登录账号 phone = PHONE3 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.loginapi.approve(self.session, "甘道夫", "error") assert_utils(self, response, 200, 100, "身份证号不能为空") logging.info("login-response{}".format(response.json())) # 已认证身份证号,提交失败 def test05_pprove_fail(self): # 先登录账号 phone = PHONE4 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 提交认证 response = self.loginapi.approve(self.session, "王富贵", "440307199008077699") assert_utils(self, response, 200, 100, "重复") logging.info("login-response{}".format(response.json()))
class TestLoan(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() # 输入产品id,获取该投资产品详情 def test01_get_loaninfo(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response = {}".format(response.json())) # 获取存在的项目详情 response = self.loginapi.loaninfo(self.session) logging.info("loaninfo-response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 获取不存在的项目 response = self.loginapi.loaninfo(self.session, loan_id='999') logging.info("loaninfo-response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) # 输入金额进行投资 def test02_tender_success(self): # 已充值的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 进行投资 response = self.loginapi.tender(self.session) logging.info("loan response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方投资接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("InitiativeTender OK", response.text) # 查询我的投资列表 response = self.loginapi.mytenderlist(self.session) self.assertEqual(200, response.status_code) # 投资金额为空,投资失败 def test03_tender_fail(self): # 已充值的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 进行投资 response = self.loginapi.tender(self.session, amount='') logging.info("loan response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(100, response.json().get("status")) # 投资金额为0,投资失败 def test04_tender_fail(self): # 已充值的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 进行投资 response = self.loginapi.tender(self.session, amount="0") logging.info("loan response = {}".format(response.json())) assert_utils(self, response, 200, 100, "投标金额不能低于最低投标金额") # 投资密码为空,投资失败 def test05_tender_fail(self): # 已充值的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 进行投资 response = self.loginapi.tender(self.session, password="") logging.info("loan response = {}".format(response.json())) assert_utils(self, response, 200, 100, "投资密码不能为空") # 投资自己发的借款,投资失败 def test06_tender_fail(self): # 已充值的账号登录 response = self.loginapi.login(self.session, phone='13312345678', pwd='123456aa') assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 进行投资 response = self.loginapi.tender(self.session) logging.info("loan response = {}".format(response.json())) assert_utils(self, response, 200, 100, "不能投自己的标") # 发送第三方投资接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("InitiativeTender OK", response.text)
class TestAccount(unittest.TestCase): def setUp(self) -> None: self.loginapi = LoginApi() self.session = requests.Session() def tearDown(self) -> None: self.session.close() def test01_account_success(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 发送开户请求 response = self.loginapi.account(self.session) logging.info("account response={}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方开户接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("UserRegister OK", response.text) # 填写所有全部参数,充值成功 def test02_recharge_success(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.loginapi.recharge(self.session, "100") logging.info("recharge response = {}".format(response.json())) self.assertEqual(200, response.status_code) self.assertEqual(200, response.json().get("status")) # 发送第三方充值接口请求 form_data = response.json().get("description").get("form") response = third_request_api(form_data) self.assertEqual(200, response.status_code) self.assertEqual("NetSave OK", response.text) # 验证码错误,充值失败 def test03_recharge_fail(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.loginapi.recharge(self.session, "100", code='1111') assert_utils(self, response, 200, 100, "验证码错误") logging.info("recharge response = {}".format(response.json())) # 验证码为空,充值失败 def test04_recharge_fail(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.loginapi.recharge(self.session, "100", code='') assert_utils(self, response, 200, 100, "验证码错误") logging.info("recharge response = {}".format(response.json())) # 输入金额为0,充值失败 def test05_recharge_fail(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.loginapi.recharge(self.session, "0") assert_utils(self, response, 200, 100, "充值金额必须大于0") logging.info("recharge response = {}".format(response.json())) # 充值金额为空 def test06_recharge_fail(self): # 认证成功的账号登录 phone = PHONE1 response = self.loginapi.login(self.session, phone) assert_utils(self, response, 200, 200, "登录成功") logging.info("login-response{}".format(response.json())) # 获取验证码 r = random.random() # 调用图片验证码接口 response = self.loginapi.get_imgverifycode(self.session, str(r)) self.assertEqual(200, response.status_code) # 进行充值 response = self.loginapi.recharge(self.session, "") assert_utils(self, response, 200, 100, "充值金额不能为空") logging.info("recharge response = {}".format(response.json()))