def send_prize(detail_id, win_amount): """ 派奖 # 传入detail_id 和 中奖金额 :param detail_id: :param win_amount: :return: """ ticket_no = int(str(detail_id) + str(random.randint(111110, 999990))) if win_amount == 0: bouns_status = 0 else: bouns_status = 1 lottery_url = settings.API_BASE_URL + '/notify/bonus?amount={0}&deviceId=123&ticketNo={1}&detailId={2}&bonusStatus={3}'.format( win_amount, ticket_no, detail_id, bouns_status) response = requests.get(url=lottery_url) response_content = json.loads(response.text) if response_content['code'] == '200': image_url = 'https://vlottery-hd1.oss-cn-hangzhou.aliyuncs.com/detail/1526548921421.jpg' try: MysqlHelper().send_prize_after(image_url=image_url,detail_id=detail_id,is_upload=1) return True except: return False else: return False
def test_withdraw_apply_amount_max_than_5000(self): """ 测试提现额度不足 :return: """ Redis().fix_user_withdraw_money_today(self.auth_id, 500) Redis().fix_user_withdraw_times(self.auth_id, 1) MysqlHelper().fix_user_money(balance=500000) image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 500000, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 423) self.assertEqual(withdraw_api.get_resp_message(), u'当天剩余提现额度为: 499500元,请修改后重试!')
def test_get_bank_list_success(self): """ 测试获取银行列表成功 :return: """ bank_id = [] bank_name = [] bank_list_api = BankListApi() bank_list_api.get() self.assertEqual(bank_list_api.get_resp_code(), 200) self.assertEqual(bank_list_api.get_resp_message(), u'查询成功') bank_list = bank_list_api.get_resp_result() for x in bank_list: bank_id.append(x['id']) bank_name.append(x['bankName']) db_bank_id = [] db_bank_name = [] db_bank_list = MysqlHelper().get_bank_list() for x in db_bank_list: db_bank_id.append(x['id']) db_bank_name.append(x['bank_name']) for x in bank_id: self.assertIn(x, db_bank_id) for x in bank_name: self.assertIn(x, db_bank_name)
def test_get_self_lott_success(self): """ 获取在线用户信息 :return: """ get_online = GetOnlineApi() get_online.get() self.assertEqual(get_online.get_resp_code(), 200) result = get_online.get_resp_result() id = result["user"]["id"] account_info = MysqlHelper().get_lot_account_info(user_id=id) self.assertEqual(result["account"][0]["balance"], account_info["balance"]) account_type = account_info["account_type"] self.assertEqual(result["account"][0]["accountType"], account_type) user_info = MysqlHelper().get_lot_user_info(id) self.assertEqual(result["user"]["id"], user_info["id"]) self.assertEqual(result["user"]["userName"], user_info["user_name"]) self.assertEqual(result["user"]["password"], user_info["password"]) self.assertEqual(result["user"]["email"], user_info["email"]) self.assertEqual(result["user"]["userStatus"], user_info["user_status"]) self.assertEqual(result["user"]["unionId"], user_info["union_id"]) self.assertEqual(result["user"]["nickname"], user_info["nickname"]) self.assertEqual(result["user"]["headPic"], user_info["head_pic"]) self.assertEqual(result["user"]["platformId"], user_info["platform_id"]) self.assertEqual(result["user"]["authId"], user_info["auth_id"]) createTime = float(result["user"]["createTime"] / 1000) create_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(createTime)) num = re.compile(r'\d+') createTime = num.findall(create_time) create_time = num.findall(str(user_info["create_time"])) self.assertEqual(createTime, create_time) updateTime = float(result["user"]["updateTime"] / 1000) update_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(updateTime)) num = re.compile(r'\d+') updateTime = num.findall(update_time) update_time = num.findall(str(user_info["update_time"])) self.assertEqual(updateTime, update_time)
def test_login_success(self): """ 测试登录成功 """ login_api = LoginApi() login_api.login(unionID=self.union_id) self.assertEqual(login_api.get_resp_code(), 200) self.assertEqual(login_api.get_resp_message(), u'success') user_details = MysqlHelper().get_user_details(self.union_id) result = login_api.get_resp_result() self.assertEqual(result['id'], user_details['id']) self.assertEqual(result['userName'], user_details['user_name']) self.assertEqual(result['userStatus'], user_details['user_status']) self.assertEqual(result['unionId'], self.union_id) self.assertEqual(result['nickname'], user_details['nickname']) self.assertEqual(result['headPic'], user_details['head_pic']) self.assertEqual(result['platformId'], user_details['platform_id']) self.assertEqual(result['authId'], user_details['auth_id'])
def test_login_success(self): """ 测试已实名用户登录成功 """ login_api = LoginApi() response = login_api.login() self.assertEqual(login_api.get_resp_code(), 200) self.assertEqual(login_api.get_resp_message(), 'success') result = json.loads(response.content)['result'] self.assertEqual(result['userStatus'], 1) self.assertEqual(result['unionId'], settings.TEST_UNION_ID) self.assertEqual(result['nickname'], settings.TEST_NICKNAME) self.assertEqual(result['headPic'], settings.TEST_HEAD_PIC) self.assertEqual(result['platformId'], settings.TEST_SOURCE) self.assertEqual(result['authId'], MysqlHelper().get_user_details()['auth_id']) self.assertIsNone(result['password']) self.assertIsNone(result['email'])
def test_get_sell_lottery_success(self): """ 获取在售彩种 :return: """ get_sell_lottery_api = GetSellLotteryApi() get_sell_lottery_api.get({'roomId':settings.DW_ROOM_ID}) self.assertEqual(get_sell_lottery_api.get_resp_code(),200) result = get_sell_lottery_api.get_resp_result() db_sell_lottery = MysqlHelper().get_sell_lottery(room_id=settings.DW_ROOM_ID) self.assertEqual(len(result),len(db_sell_lottery)) result_lottery_id = [i['id'] for i in result] db_sell_lottery_id = [i['lottery_id'] for i in db_sell_lottery] self.assertEqual(result_lottery_id,db_sell_lottery_id)
def test_first_login_register(self): """ 测试首次登录数据库信息 """ nickname = '我是测试001' head_pic = 'https://pic.dawang.tv/files/images/heads/2a/22/20170705213141666.jpeg' login_api = LoginApi() login_api.login(unionID=self.new_union_id, source=1, nickname=nickname, head_pic=head_pic) self.assertEqual(login_api.get_resp_code(), 200) self.assertEqual(login_api.get_resp_message(), u'success') user_details = MysqlHelper().get_user_details(self.new_union_id) result = login_api.get_resp_result() self.assertEqual(result['id'], user_details['id']) self.assertEqual(result['userName'], user_details['user_name']) self.assertEqual(result['userStatus'], user_details['user_status']) self.assertEqual(result['unionId'], self.new_union_id) self.assertEqual(result['nickname'], user_details['nickname']) self.assertEqual(result['headPic'], user_details['head_pic']) self.assertEqual(result['platformId'], user_details['platform_id']) self.assertEqual(result['authId'], user_details['auth_id'])
def setUpClass(cls): MysqlHelper().fix_user_money(balance=0)
def setUpClass(cls): MysqlHelper().delete_user(union_id=cls.new_union_id)
def tearDownClass(cls): MysqlHelper().delete_user(union_id=cls.new_union_id)
def tearDown(self): MysqlHelper().delete_bind_card( MysqlHelper().get_user_details()['auth_id']) time.sleep(1)
def tearDown(self): MysqlHelper().delete_user_withdraw_log(auth_id=self.auth_id) MysqlHelper().delete_account_details( MysqlHelper().get_user_details()['id']) Redis().fix_user_withdraw_times(self.auth_id, 0) Redis().fix_user_withdraw_money_today(self.auth_id, 0)
class TestWithDrawApplyApi(BaseCase): """ 申请提现 """ head_pic = settings.TEST_HEAD_PIC auth_id = MysqlHelper().get_user_details()['auth_id'] mobile = '13501077762' real_name = '刘祖全' card_number = '512501197203035172' def test_withdraw_apply_amount_less(self): """ 测试账户剩余提现额度不足时申请提现 :return: """ image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 500, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 422) self.assertEqual(withdraw_api.get_resp_message(), u'账户剩余提现额度不足,请查看后重试!') def test_withdraw_apply_not_cre(self): """ 测试未实名用户请求提现 :return: """ union_id = '10' + str(random.randint(1111111, 9999999)) mobile = '1311112' + str(random.randint(1111, 9999)) nickname = 'ceshi100001' image_code_api = ImageCodeApi() image_code_api.get({'mobile': mobile}) image_code = Redis().get_image_code(mobile) sms_code_api = LoginSendMessageApi(union_id, nickname=nickname, head_pic=self.head_pic, source=1) sms_code_api.get({ 'mobile': mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) self.assertEqual(sms_code_api.get_resp_code(), 200) sms_code = Redis().get_sms_code(mobile, type='tx') withdraw_api = WithdrawApplyApi(union_id, nickname=nickname, head_pic=self.head_pic, source=1) withdraw_api.get({ 'amount': 500, 'source': 1, 'mobile': mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 415) self.assertEqual(withdraw_api.get_resp_message(), u'未实名认证,请先实名认证再绑定!') def test_withdraw_mobile_error(self): """ 测试提现手机号与绑定手机号不一致时申请提现 :return: """ withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 500, 'source': 1, 'mobile': '13288888888', 'verCode': '1233', 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 414) self.assertEqual(withdraw_api.get_resp_message(), u'手机号码错误,请使用尾号: 7762的手机号进行验证!') def test_withdraw_apply_amount_success_first(self): """ 测试当天首次申请提现100元成功 :return: """ Redis().fix_user_withdraw_times(self.auth_id, 0) MysqlHelper().fix_user_money(balance=100) image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 100, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 200) self.assertEqual(withdraw_api.get_resp_message(), u'提现申请成功,请等待管理员审核!') # 提现记录 my_precent_api = MyPrecentApi() my_precent_api.get() self.assertEqual(my_precent_api.get_resp_code(), 200) self.assertEqual(my_precent_api.get_resp_message(), u'success') result = my_precent_api.get_resp_result() self.assertEqual(len(result), 1) self.assertIsNotNone(result[0]['presentRecordNo']) self.assertEqual(result[0]['authId'], self.auth_id) self.assertEqual(result[0]['amount'], 100.0) self.assertEqual(result[0]['actualAmount'], 100.0) self.assertIsNone(result[0]['amountOfCash']) self.assertEqual(result[0]['tip'], 0.0) self.assertEqual(result[0]['presentRecordStatus'], 0) self.assertIsNone(result[0]['presentRecordStatusPre']) self.assertEqual(result[0]['debitStatus'], u'1') self.assertEqual(result[0]['source'], 1) self.assertEqual(result[0]['notify'], 9) self.assertIsNone(result[0]['bak']) self.assertEqual(result[0]['realName'], u'高英龙') self.assertEqual(result[0]['mobile'], self.mobile) self.assertEqual(result[0]['bindingId'], 2) # 账户变动记录 my_ac_det_api = MyAcDetApi() my_ac_det_api.get({ 'unionId': MysqlHelper().get_user_details()['union_id'], 'source': 1 }) self.assertEqual(my_ac_det_api.get_resp_code(), 200) self.assertEqual(my_ac_det_api.get_resp_message(), u'success') result = my_ac_det_api.get_resp_result() self.assertEqual(len(result), 1) self.assertEqual(result[0]['user_id'], MysqlHelper().get_user_details()['id']) self.assertEqual(result[0]['tradeType'], 3) self.assertEqual(result[0]['amountS'], -100.0) # def test_withdraw_apply_amount_max_than_500000(self): """ 测试当天单次提现金额超过500000 :return: """ Redis().fix_user_withdraw_money_today(self.auth_id, 0) Redis().fix_user_withdraw_times(self.auth_id, 1) MysqlHelper().fix_user_money(balance=500000) image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 500000, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 421) self.assertEqual(withdraw_api.get_resp_message(), u'在线提现金额最少10元,最大5000元,请修改后重试,超过最高5000元请联系客服!') def test_withdraw_apply_amount_max_than_5000(self): """ 测试提现额度不足 :return: """ Redis().fix_user_withdraw_money_today(self.auth_id, 500) Redis().fix_user_withdraw_times(self.auth_id, 1) MysqlHelper().fix_user_money(balance=500000) image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 500000, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 423) self.assertEqual(withdraw_api.get_resp_message(), u'当天剩余提现额度为: 499500元,请修改后重试!') def tearDown(self): MysqlHelper().delete_user_withdraw_log(auth_id=self.auth_id) MysqlHelper().delete_account_details( MysqlHelper().get_user_details()['id']) Redis().fix_user_withdraw_times(self.auth_id, 0) Redis().fix_user_withdraw_money_today(self.auth_id, 0)
def test_withdraw_apply_amount_success_first(self): """ 测试当天首次申请提现100元成功 :return: """ Redis().fix_user_withdraw_times(self.auth_id, 0) MysqlHelper().fix_user_money(balance=100) image_code_api = ImageCodeApi() image_code_api.get({'mobile': self.mobile}) image_code = Redis().get_image_code(self.mobile) sms_code_api = LoginSendMessageApi() sms_code_api.get({ 'mobile': self.mobile, 'type': 'tx_sms_code', 'imgCode': image_code }) sms_code = Redis().get_sms_code(self.mobile, type='tx') withdraw_api = WithdrawApplyApi() withdraw_api.get({ 'amount': 100, 'source': 1, 'mobile': self.mobile, 'verCode': sms_code, 'type': 'tx_sms_code', 'bindingId': 2 }) self.assertEqual(withdraw_api.get_resp_code(), 200) self.assertEqual(withdraw_api.get_resp_message(), u'提现申请成功,请等待管理员审核!') # 提现记录 my_precent_api = MyPrecentApi() my_precent_api.get() self.assertEqual(my_precent_api.get_resp_code(), 200) self.assertEqual(my_precent_api.get_resp_message(), u'success') result = my_precent_api.get_resp_result() self.assertEqual(len(result), 1) self.assertIsNotNone(result[0]['presentRecordNo']) self.assertEqual(result[0]['authId'], self.auth_id) self.assertEqual(result[0]['amount'], 100.0) self.assertEqual(result[0]['actualAmount'], 100.0) self.assertIsNone(result[0]['amountOfCash']) self.assertEqual(result[0]['tip'], 0.0) self.assertEqual(result[0]['presentRecordStatus'], 0) self.assertIsNone(result[0]['presentRecordStatusPre']) self.assertEqual(result[0]['debitStatus'], u'1') self.assertEqual(result[0]['source'], 1) self.assertEqual(result[0]['notify'], 9) self.assertIsNone(result[0]['bak']) self.assertEqual(result[0]['realName'], u'高英龙') self.assertEqual(result[0]['mobile'], self.mobile) self.assertEqual(result[0]['bindingId'], 2) # 账户变动记录 my_ac_det_api = MyAcDetApi() my_ac_det_api.get({ 'unionId': MysqlHelper().get_user_details()['union_id'], 'source': 1 }) self.assertEqual(my_ac_det_api.get_resp_code(), 200) self.assertEqual(my_ac_det_api.get_resp_message(), u'success') result = my_ac_det_api.get_resp_result() self.assertEqual(len(result), 1) self.assertEqual(result[0]['user_id'], MysqlHelper().get_user_details()['id']) self.assertEqual(result[0]['tradeType'], 3) self.assertEqual(result[0]['amountS'], -100.0)
def tearDownClass(cls): MysqlHelper().fix_user_money(balance=0)
def tearDown(self): for x in [self.card_number_X, self.card_number_x, self.card_number]: MysqlHelper().delete_user_auth(x)