def test_anchor_group_withdraw_failed(self): """ 测试主播团金库数量小于100000不可转出 :return: """ user_id = self.user_id mysql_operation = MysqlOperation(user_id=user_id,anchor_id=anchor_id) mysql_operation.fix_user_rank_and_experience(user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=51326000) RedisHold().clean_redis_user_detail(self.user_id) # 开通主播团 open_anchor_group_api = OpenAnchorGroupApi(self.user_login_name) open_anchor_group_api.get() self.assertEqual(open_anchor_group_api.get_code(), 0) # 购买守护 buy_guard_api = BuyGuardApi(self.user_login_name) guard_response = buy_guard_api.get({'room_id': room_id, 'guard_id': '2','currency':'gold'}) self.assertEqual(buy_guard_api.get_code(), 0) self.assertEqual(json.loads(guard_response.content)['result']['identity_obj']['user_guard_obj']['guard_rank'], 2) time.sleep(1) # 将主播纳入主播团 add_anchor_to_group_api = AddAnchorToGroupApi(self.user_login_name) response = add_anchor_to_group_api.get({'anchor_id': anchor_id, 'position': 1,'grab_flag': 0,'change_flag': 0}) self.assertEqual(add_anchor_to_group_api.get_code(), 0) self.assertEqual(add_anchor_to_group_api.get_response_message(), u'操作成功') anchor_group_anchor_obj = json.loads(response.content)['result']['anchor_group_list'][0]['anchor_group_anchor_obj'] self.assertEqual(anchor_group_anchor_obj['anchor_id'], int(anchor_id)) self.assertEqual(anchor_group_anchor_obj['position'], 1) self.assertEqual(anchor_group_anchor_obj['income_gold'], 0) self.assertLessEqual(anchor_group_anchor_obj['left_time'], 604800) time.sleep(1) # 给主播团内主播送礼物 send_gift_api = SendGiftApi(self.user_login_name) send_gift_api.get({'room_id': room_id, 'gift_id': 2, 'gift_count': 1,'currency':'gold'}) self.assertEqual(send_gift_api.get_code(), 0) time.sleep(3) # 查询主播团金库金币 my_anchor_group_api = MyAnchorGroupApi(self.user_login_name) my_anchor_group_response = my_anchor_group_api.get() response_gold = json.loads(my_anchor_group_response.content)['result']['anchor_group_obj']['gold'] self.assertEqual(my_anchor_group_api.get_code(),0) expect_gold_num = (int(mysql_operation.get_gift_details(gift_id=2)['gold']) * 1) * 0.05 self.assertEqual(response_gold,expect_gold_num) # 提取主播团金库金币 anchor_group_withdraw_api = AnchorGroupWithdrawApi(self.user_login_name) anchor_group_withdraw_api.get() self.assertEqual(anchor_group_withdraw_api.get_code(),200510) self.assertEqual(anchor_group_withdraw_api.get_response_message(),u'金库余额大于等于100000金币才可转出')
def test_anchor_group_withdraw(self): """ 测试主播团金库金币收入和提出 :return: """ user_id = self.user_id mysql_operation = MysqlOperation(user_id=user_id,anchor_id=anchor_id) expect_gold_num = (int(mysql_operation.get_gift_details(gift_id=67)['gold']) * 2000) * 0.05 mysql_operation.fix_user_rank_and_experience(user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=2738000) RedisHold().clean_redis_user_detail(self.user_id) # 开通主播团 open_anchor_group_api = OpenAnchorGroupApi(self.user_login_name) response = open_anchor_group_api.get() self.assertEqual(open_anchor_group_api.get_code(), 0) self.assertEqual(json.loads(response.content)['result']['identity_obj']['gold'],2638000) # 购买守护 buy_guard_api = BuyGuardApi(self.user_login_name) guard_response = buy_guard_api.get({'room_id': room_id, 'guard_id': '1','currency':'gold'}) self.assertEqual(buy_guard_api.get_code(), 0) self.assertEqual(json.loads(guard_response.content)['result']['identity_obj']['user_guard_obj']['guard_rank'], 1) self.assertEqual(json.loads(guard_response.content)['result']['identity_obj']['gold'],2050000) time.sleep(1) # 将主播纳入主播团 add_anchor_to_group_api = AddAnchorToGroupApi(self.user_login_name) response = add_anchor_to_group_api.get({'anchor_id': anchor_id, 'position': 1,'grab_flag': 0,'change_flag': 0}) self.assertEqual(add_anchor_to_group_api.get_code(), 0) self.assertEqual(add_anchor_to_group_api.get_response_message(), u'操作成功') anchor_group_anchor_obj = json.loads(response.content)['result']['anchor_group_list'][0]['anchor_group_anchor_obj'] self.assertEqual(anchor_group_anchor_obj['anchor_id'], int(anchor_id)) self.assertEqual(anchor_group_anchor_obj['position'], 1) self.assertEqual(anchor_group_anchor_obj['income_gold'], 0) self.assertLessEqual(anchor_group_anchor_obj['left_time'], 604800) self.assertEqual(json.loads(response.content)['result']['identity_obj']['gold'],2000000) time.sleep(1) # 给主播团内主播送礼物 send_gift_api = SendGiftApi(self.user_login_name) send_gift_response = send_gift_api.get({'room_id': room_id, 'gift_id': 67, 'gift_count': 2000,'currency':'gold'}) self.assertEqual(send_gift_api.get_code(), 0) self.assertEqual(json.loads(send_gift_response.content)['result']['identity_obj']['gold'],0) time.sleep(1) # 查询主播团金库金币 my_anchor_group_api = MyAnchorGroupApi(self.user_login_name) my_anchor_group_response = my_anchor_group_api.get() self.assertEqual(my_anchor_group_api.get_code(),0) anchor_group_gold = json.loads(my_anchor_group_response.content)['result']['anchor_group_obj']['gold'] self.assertEqual(anchor_group_gold,expect_gold_num) # 提取主播团金库金币 anchor_group_withdraw_api = AnchorGroupWithdrawApi(self.user_login_name) withdraw_response = anchor_group_withdraw_api.get() self.assertEqual(anchor_group_withdraw_api.get_code(),0) anchor_group_obj = json.loads(withdraw_response.content)['result']['anchor_group_obj'] self.assertEqual(anchor_group_obj['gold'],0) time.sleep(3) db_user_gold = mysql_operation.get_user_account_details()['gold'] self.assertEqual(int(db_user_gold),int(expect_gold_num * 0.9)) time.sleep(3) # 查询主播团日志 my_anchor_group_logs_api = MyAnchorGroupLogsApi(self.user_login_name) logs_response = my_anchor_group_logs_api.get() anchor_group_log_list = json.loads(logs_response.content)['result']['anchor_group_log_list'] self.assertEqual(my_anchor_group_logs_api.get_code(),0) self.assertEqual(len(anchor_group_log_list),3) self.assertIn(u'金库资金被转出',anchor_group_log_list[0]['content']) self.assertIn(u'为金库贡献了',anchor_group_log_list[1]['content']) self.assertIn(u'被纳入主播团',anchor_group_log_list[2]['content']) # 金币获取记录 gold_account_api = GoldAccountApi(self.user_login_name) response = gold_account_api.get() self.assertEqual(gold_account_api.get_code(), 0) account_list = json.loads(response.content)['result']['account_list'] self.assertEqual(len(account_list),1) self.assertEqual(account_list[0]['gold'], int(expect_gold_num) * 0.9) self.assertEqual(account_list[0]['consumption_type'], u'%s金币' % (int(int(expect_gold_num) * 0.9))) self.assertEqual(account_list[0]['behavior_desc'], u'主播团提现')
def test_anchor_group_rob(self): """ 测试将其他主播团中主播纳入到自己的主播团 :return: """ for login_name in [self.user_login_name, self.rob_user_login_name]: mysql_operation = MysqlOperation(mobile=login_name) user_id = str(mysql_operation.get_user_id()) mysql_operation = MysqlOperation(user_id=user_id) mysql_operation.fix_user_rank_and_experience(user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=51326000) RedisHold().clean_redis_user_detail(user_id) # 依次给用户开通主播团 open_anchor_group_api = OpenAnchorGroupApi(login_name) open_anchor_group_api.get() self.assertEqual(open_anchor_group_api.get_code(), 0) # 用户依次购买守护 buy_guard_api = BuyGuardApi(login_name) buy_guard_api.get({'room_id': room_id, 'guard_id': '2','currency':'gold'}) self.assertEqual(buy_guard_api.get_code(), 0) time.sleep(self.time_sleep * 2) # 用户将主播纳入主播团 add_anchor_to_group_api = AddAnchorToGroupApi(self.user_login_name) add_anchor_to_group_api.get({'anchor_id': anchor_id, 'position': 1,'grab_flag': 0,'change_flag': 0}) self.assertEqual(add_anchor_to_group_api.get_code(), 0) time.sleep(0.5) # 查询主播团信息 my_anchor_group_list_api = MyAnchorGroupListApi(self.user_login_name) list_response = my_anchor_group_list_api.get() self.assertEqual(my_anchor_group_list_api.get_code(), 0) anchor_group_opening_info = json.loads(list_response.content)['result']['anchor_group_opening_info'] self.assertEqual(anchor_group_opening_info['gold_needed'],100000) self.assertEqual(anchor_group_opening_info['is_opened'],1) anchor_group_obj = json.loads(list_response.content)['result']['anchor_group_obj'] self.assertEqual(anchor_group_obj['owend_anchor_count'],1) # 用户将主播抢到自己的主播团 add_anchor_to_group_api = AddAnchorToGroupApi(self.rob_user_login_name) add_anchor_to_group_api.get({'anchor_id': anchor_id, 'position': 1,'grab_flag': 1,'change_flag': 0}) self.assertEqual(add_anchor_to_group_api.get_code(), 0) time.sleep(0.5) # 查询15020170001主播团信息 my_anchor_group_list_api = MyAnchorGroupListApi(self.rob_user_login_name) list_response = my_anchor_group_list_api.get() self.assertEqual(my_anchor_group_list_api.get_code(), 0) anchor_group_opening_info = json.loads(list_response.content)['result']['anchor_group_opening_info'] self.assertEqual(anchor_group_opening_info['gold_needed'],100000) self.assertEqual(anchor_group_opening_info['is_opened'],1) anchor_group_obj = json.loads(list_response.content)['result']['anchor_group_obj'] self.assertEqual(anchor_group_obj['owend_anchor_count'],1) # 查询13501077762主播团信息 my_anchor_group_list_api = MyAnchorGroupListApi(self.user_login_name) list_response = my_anchor_group_list_api.get() self.assertEqual(my_anchor_group_list_api.get_code(), 0) anchor_group_obj = json.loads(list_response.content)['result']['anchor_group_obj'] self.assertEqual(anchor_group_obj['owend_anchor_count'],0) time.sleep(2) # 查询13501077762主播团日志 my_anchor_group_logs_api = MyAnchorGroupLogsApi(self.user_login_name) logs_response = my_anchor_group_logs_api.get() anchor_group_log_list = json.loads(logs_response.content)['result']['anchor_group_log_list'] self.assertEqual(my_anchor_group_logs_api.get_code(), 0) self.assertEqual(len(anchor_group_log_list), 2) self.assertIn(u'抢走', anchor_group_log_list[0]['content']) self.assertIn(u'被纳入主播团', anchor_group_log_list[1]['content']) # 查询15020170001主播团日志 my_anchor_group_logs_api = MyAnchorGroupLogsApi(self.rob_user_login_name) logs_response = my_anchor_group_logs_api.get() anchor_group_log_list = json.loads(logs_response.content)['result']['anchor_group_log_list'] self.assertEqual(my_anchor_group_logs_api.get_code(), 0) self.assertEqual(len(anchor_group_log_list), 1) self.assertIn(u'被纳入主播团', anchor_group_log_list[0]['content'])
def test_add_anchor_to_group_consumption(self): """ 测试主播团日志 :return: """ user_id = self.user_id while self.count < self.max_count: mysql_operation = MysqlOperation(user_id=user_id) mysql_operation.fix_user_rank_and_experience( user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=100000) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) open_anchor_group_api = OpenAnchorGroupApi(self.user_login_name) open_anchor_group_api.get() if open_anchor_group_api.get_code() == 200502: time.sleep(self.time_sleep) self.count += 1 else: self.assertEqual(open_anchor_group_api.get_code(), 0) break self.assertLess(self.count, self.max_count) consumption_api = ConsumptionApi(self.user_login_name) response = consumption_api.get() consume_list = json.loads(response.content)['result']['consume_list'] self.assertEqual(consumption_api.get_code(), 0) self.assertEqual(len(consume_list), 1) self.assertEqual(consume_list[0]['type'], u'7') self.assertEqual(consume_list[0]['gold'], 100000) self.assertEqual(consume_list[0]['corresponding_name'], u'主播团') self.assertEqual(consume_list[0]['consumption_type'], u'100000金币') self.assertEqual(consume_list[0]['behavior_desc'], u'开通主播团') while self.count < self.max_count: mysql_operation = MysqlOperation(user_id=user_id) mysql_operation.fix_user_rank_and_experience( user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=638000) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) buy_guard_api = BuyGuardApi(self.user_login_name) guard_response = buy_guard_api.get({ 'room_id': room_id, 'guard_id': '1', 'currency': 'gold' }) if buy_guard_api.get_code() == 100032: time.sleep(self.time_sleep) self.count += 1 else: self.assertEqual(buy_guard_api.get_code(), 0) self.assertEqual( json.loads(guard_response.content)['result'] ['identity_obj']['user_guard_obj']['guard_rank'], 1) break self.assertLess(self.count, self.max_count) add_anchor_to_group_api = AddAnchorToGroupApi(self.user_login_name) response = add_anchor_to_group_api.get({ 'anchor_id': anchor_id, 'position': 1, 'grab_flag': 0, 'change_flag': 0 }) self.assertEqual(add_anchor_to_group_api.get_code(), 0) self.assertEqual(add_anchor_to_group_api.get_response_message(), u'操作成功') anchor_group_anchor_obj = json.loads( response.content )['result']['anchor_group_list'][0]['anchor_group_anchor_obj'] self.assertEqual(anchor_group_anchor_obj['anchor_id'], int(anchor_id)) self.assertEqual(anchor_group_anchor_obj['position'], 1) self.assertEqual(anchor_group_anchor_obj['income_gold'], 0) self.assertLessEqual(anchor_group_anchor_obj['left_time'], 604800) # 消费记录 consumption_api = ConsumptionApi(self.user_login_name) response = consumption_api.get() consume_list = json.loads(response.content)['result']['consume_list'] self.assertEqual(consumption_api.get_code(), 0) self.assertEqual(consume_list[0]['gold'], 50000) self.assertEqual(consume_list[0]['corresponding_name'], u'纳入主播团') self.assertEqual(consume_list[0]['consumption_type'], u'50000金币') self.assertEqual(consume_list[0]['behavior_desc'], u'纳入主播团') self.assertEqual(consume_list[0]['user_id'], self.user_id) self.assertEqual( consume_list[0]['room_title'], MysqlOperation(room_id=room_id).get_room_details()['title'])
def test_bronze_add_anchor_to_group(self): """ 测试将青铜守护纳入主播团 :return: """ while self.count < self.max_count: mysql_operation = MysqlOperation(self.user_id) mysql_operation.fix_user_rank_and_experience( user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=100000) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) open_anchor_group_api = OpenAnchorGroupApi(self.user_login_name) response = open_anchor_group_api.get() if open_anchor_group_api.get_code() == 100032: time.sleep(self.time_sleep) self.count += 1 else: self.assertEqual(open_anchor_group_api.get_code(), 0) anchor_group_obj = json.loads( response.content)['result']['anchor_group_obj'] self.assertEqual(anchor_group_obj['user_id'], int(self.user_id)) self.assertEqual(anchor_group_obj['gold'], 0) self.assertEqual(anchor_group_obj['max_num'], 2) self.assertEqual(anchor_group_obj['next_level'], 18) self.assertEqual(anchor_group_obj['next_level_name'], u'1级上校') self.assertEqual(anchor_group_obj['owend_anchor_count'], 0) while self.count < self.max_count: mysql_operation = MysqlOperation(self.user_id) mysql_operation.fix_user_rank_and_experience( user_rank=self.user_rank, experience_all=self.user_experience_all) mysql_operation.fix_user_account(gold_num=638000) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) buy_guard_api = BuyGuardApi(self.user_login_name) guard_response = buy_guard_api.get({ 'room_id': room_id, 'guard_id': '1', 'currency': 'gold' }) if buy_guard_api.get_code() == 100032: time.sleep(self.time_sleep) self.count += 1 else: self.assertEqual(buy_guard_api.get_code(), 0) self.assertEqual( json.loads(guard_response.content)['result'] ['identity_obj']['user_guard_obj']['guard_rank'], 1) add_anchor_to_group_api = AddAnchorToGroupApi( self.user_login_name) response = add_anchor_to_group_api.get({ 'anchor_id': anchor_id, 'position': 1, 'grab_flag': 0, 'change_flag': 0 }) self.assertEqual(add_anchor_to_group_api.get_code(), 0) self.assertEqual( add_anchor_to_group_api.get_response_message(), u'操作成功') anchor_group_anchor_obj = json.loads( response.content)['result']['anchor_group_list'][ 0]['anchor_group_anchor_obj'] self.assertEqual(anchor_group_anchor_obj['anchor_id'], int(anchor_id)) self.assertEqual(anchor_group_anchor_obj['position'], 1) self.assertEqual( anchor_group_anchor_obj['income_gold'], 0) self.assertLessEqual( anchor_group_anchor_obj['left_time'], 604800) anchor_obj = json.loads( response.content )['result']['anchor_group_list'][0]['anchor_obj'] self.assertEqual(anchor_obj['id'], anchor_id) self.assertEqual(anchor_obj['anchor_rank'], 4) self.assertEqual(anchor_obj['anchor_experience_all'], 588000) break self.assertLess(self.count, self.max_count) break self.assertLess(self.count, self.max_count)