def test_diamond_get_list_can_be_add(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=7156000) 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() == 100032: 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) 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=7056000) 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': '12', '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']['guard_list'] [0]['user_guard_obj']['guard_rank'], 4) list_can_be_add_api = ListCanBeAddApi(self.user_login_name) response = list_can_be_add_api.get() self.assertEqual(list_can_be_add_api.get_code(), 0) self.assertEqual(list_can_be_add_api.get_response_message(), u'操作成功') anchor_list = json.loads( response.content)['result']['anchor_list'] self.assertEqual(len(anchor_list), 1) self.assertEqual(anchor_list[0]['room_obj']['id'], (room_id)) break self.assertLess(self.count, self.max_count)
def test_buy_currency_error(self): """ 测试请求接口货币类型不存在 :return: """ buy_guard_api = BuyGuardApi(self.login_name) buy_guard_api.get({ 'room_id': self.room_id, 'guard_id': '1', 'currency': 'abc' }) self.assertEqual(buy_guard_api.get_code(), 460004) self.assertEqual(buy_guard_api.get_response_message(), u'请选择货币类型')
def test_buy_room_id_error(self): """ 测试请求接口房间ID不存在 :return: """ buy_guard_api = BuyGuardApi(self.login_name) buy_guard_api.get({ 'room_id': '666666', 'guard_id': '1', 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 200412) self.assertEqual(buy_guard_api.get_response_message(), u'参数异常')
def test_buy_room_id_null(self): """ 测试请求接口房间ID为空 :return: """ buy_guard_api = BuyGuardApi(self.login_name) buy_guard_api.get({ 'room_id': None, 'guard_id': '1', 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 402000) self.assertEqual(buy_guard_api.get_response_message(), u'房间ID不能为空')
def test_buy_guard_id_error(self): """ 测试请求接口守护类型不存在 :return: """ buy_guard_api = BuyGuardApi(self.login_name) buy_guard_api.get({ 'room_id': self.room_id, 'guard_id': '55', 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 411148) self.assertEqual(buy_guard_api.get_response_message(), u'无此守护类型')
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 action(self,**kwargs): guard_id = kwargs['guard_id'] guard_price = None if guard_id == 1: guard_price = 588000 elif guard_id == 2: guard_price = 1176000 elif guard_id == 3: guard_price = 1764000 elif guard_id == 12: guard_price = 7056000 while self.count < self.max_count: mysql_operation = MysqlOperation(user_id=self.user_id) mysql_operation.fix_user_account(gold_num=guard_price) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) buy_guard_api = BuyGuardApi(self.login_name) response = buy_guard_api.get({'room_id':self.room_id,'guard_id':guard_id,'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) identity_obj = json.loads(response.content)['result']['identity_obj'] if guard_id == 12: self.assertEqual(identity_obj['user_guard_obj']['guard_rank'], 4) else: self.assertEqual(identity_obj['user_guard_obj']['guard_rank'],guard_id) break self.assertLess(self.count,self.max_count) while self.count < self.max_count: mysql_operation = MysqlOperation(user_id=self.user_id) mysql_operation.fix_user_account(gold_num=self.gift_gold) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) send_gift_api = SendGiftApi(self.login_name) response = send_gift_api.get({'room_id': self.room_id, 'gift_id': self.guard_gift_id, 'gift_count': 1,'currency': 'gold'}) if send_gift_api.get_code() in [100032,100503]: time.sleep(self.time_sleep) self.count+=1 else: self.assertEqual(send_gift_api.get_code(),0) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(identity_obj['gold'],0) self.assertEqual(identity_obj['diamond'],u'0') break self.assertLess(self.count,self.max_count) consumption_api = ConsumptionApi(self.login_name) response = consumption_api.get() self.assertEqual(consumption_api.get_code(),0) consume_list = json.loads(response.content)['result']['consume_list'] self.assertEqual(len(consume_list),2) self.assertEqual(consume_list[0]['user_id'],self.user_id) self.assertEqual(consume_list[0]['type'],u'1') self.assertEqual(consume_list[0]['gold'],self.gift_gold) self.assertEqual(consume_list[0]['corresponding_id'],int(self.guard_gift_id)) self.assertEqual(consume_list[0]['corresponding_name'],MysqlOperation().get_gift_details(gift_id=self.guard_gift_id)['name']) self.assertEqual(consume_list[0]['corresponding_num'],1) self.assertEqual(consume_list[0]['room_id'],self.room_id) self.assertEqual(consume_list[0]['status'],1) self.assertEqual(consume_list[0]['behavior_desc'],u'送礼') self.assertEqual(consume_list[0]['room_title'],MysqlOperation(room_id=self.room_id).get_room_details()['title']) self.assertEqual(consume_list[0]['consumption_type'],u'%s金币' % self.gift_gold)
def renew_action(self, **kwargs): guard_price = kwargs['guard_price'] first_guard_id = kwargs['first_guard_id'] second_guard_id = kwargs['second_guard_id'] following = kwargs['following'] user_rank = kwargs['user_rank'] sun_max_num = kwargs['sun_max_num'] anchor_rank = kwargs['anchor_rank'] guard_rank = kwargs['guard_rank'] expire_time_num = kwargs['expire_time_num'] mysql_operation = MysqlOperation(user_id=self.user_id) mysql_operation.fix_user_account(gold_num=guard_price) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) buy_guard_api = BuyGuardApi(self.login_name) buy_guard_api.get({ 'room_id': self.room_id, 'guard_id': first_guard_id, 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 0) time.sleep(0.5) renew_buy_guard = BuyGuardApi(self.login_name) response = renew_buy_guard.get({ 'room_id': self.room_id, 'guard_id': second_guard_id, 'currency': 'gold' }) self.assertEqual(renew_buy_guard.get_code(), 0) guard_list = json.loads(response.content)['result']['guard_list'] self.assertEqual(len(guard_list), 1) self.assertEqual(guard_list[0]['user_rank'], user_rank) self.assertEqual(guard_list[0]['user_experience_all'], guard_price) self.assertEqual(guard_list[0]['sun_resumed_time'], 180) self.assertEqual(guard_list[0]['sun_max_num'], sun_max_num) user_guard_obj = guard_list[0]['user_guard_obj'] self.assertEqual(user_guard_obj['user_id'], (self.user_id)) self.assertEqual(user_guard_obj['guard_rank'], guard_rank) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) identity_obj = json.loads(response.content)['result']['identity_obj'] self.assertEqual(identity_obj['user_rank'], user_rank) self.assertEqual(identity_obj['gold'], 0) self.assertEqual(identity_obj['diamond'], u'0') self.assertEqual(identity_obj['sun_max_num'], sun_max_num) self.assertEqual(identity_obj['has_followed'], 0) identity_user_guard_obj = identity_obj['user_guard_obj'] self.assertEqual(identity_user_guard_obj['user_id'], (self.user_id)) self.assertEqual(identity_user_guard_obj['guard_rank'], guard_rank) self.assertIn(identity_user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(identity_user_guard_obj['rest_time_str'], expire_time_num_format) anchor_obj = json.loads( response.content)['result']['room_obj']['anchor_obj'] self.assertEqual(anchor_obj['anchor_rank'], anchor_rank) self.assertEqual(anchor_obj['sun_resumed_time'], 180) self.assertEqual(anchor_obj['sun_max_num'], 50)
def action(self, **kwargs): guard_price = 0 guard_id = kwargs['guard_id'] user_rank = kwargs['user_rank'] sun_max_num = kwargs['sun_max_num'] anchor_rank = kwargs['anchor_rank'] following = kwargs['following'] expire_time_num = None guard_rank = None if guard_id == 1: guard_price = 588000 elif guard_id == 2: guard_price = 1176000 elif guard_id == 3: guard_price = 1764000 elif guard_id == 6: guard_price = 3528000 elif guard_id == 12: guard_price = 7056000 elif guard_id == 13: guard_price = 14112000 mysql_operation = MysqlOperation(user_id=self.user_id) mysql_operation.fix_user_account(gold_num=guard_price) RedisHold().clean_redis_user_detail(self.user_id) time.sleep(self.time_sleep) live_api = LiveApi(self.login_name) response = live_api.get({'room_id': self.room_id}) self.assertEqual(live_api.get_code(), 0) room_hot_num = json.loads( response.content)['result']['room_obj']['curr_hot_num'] if following: add_following_api = AddFollowingApi(self.login_name) response = add_following_api.get({'anchor_id': self.anchor_id}) self.assertEqual(add_following_api.get_code(), 0) self.assertEqual(add_following_api.get_response_message(), u'操作成功') self.assertEqual( json.loads(response.content)['result']['identity_obj'] ['has_followed'], 1) buy_guard_api = BuyGuardApi(self.login_name) response = buy_guard_api.get({ 'room_id': self.room_id, 'guard_id': guard_id, 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 0) guard_list = json.loads(response.content)['result']['guard_list'] self.assertEqual(len(guard_list), 1) self.assertEqual(guard_list[0]['user_rank'], user_rank) self.assertEqual(guard_list[0]['user_experience_all'], guard_price) self.assertEqual(guard_list[0]['sun_resumed_time'], 180) self.assertEqual(guard_list[0]['sun_max_num'], sun_max_num) user_guard_obj = guard_list[0]['user_guard_obj'] self.assertEqual(user_guard_obj['user_id'], (self.user_id)) def assert_guard_obj(obj, guard_id): if guard_id == 1: guard_rank = 1 expire_time_num = range(28, 32) self.assertEqual(user_guard_obj['guard_rank'], guard_rank) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) elif guard_id == 2: guard_rank = 2 expire_time_num = range(59, 63) self.assertEqual(user_guard_obj['guard_rank'], guard_rank) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) elif guard_id in [3, 6]: guard_rank = 3 self.assertEqual(user_guard_obj['guard_rank'], guard_rank) if guard_id == 3: expire_time_num = range(89, 94) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) elif guard_id == 6: expire_time_num = range(183, 187) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) elif guard_id in [12, 13]: guard_rank = 4 self.assertEqual(user_guard_obj['guard_rank'], guard_rank) if guard_id == 12: expire_time_num = range(369, 373) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) elif guard_id == 13: expire_time_num = range(739, 745) self.assertIn(user_guard_obj['rest_time_int'], expire_time_num) expire_time_num_format = [] for x in expire_time_num: expire_time_num_format.append(u'{0}天'.format(x)) self.assertIn(user_guard_obj['rest_time_str'], expire_time_num_format) assert_guard_obj(obj=user_guard_obj, guard_id=guard_id) intimacy_obj = guard_list[0]['intimacy_obj'] def assert_intimacy(obj, following, guard_id, identity=False): inti_dic = {} if guard_id == 1: inti_dic = { 'intimacy_experience': 113000, 'intimacy_rank': 7, 'level': 1, 'level_name': u'喜爱' } elif guard_id == 2: inti_dic = { 'intimacy_experience': 76000, 'intimacy_rank': 10, 'level': 1, 'level_name': u'喜爱' } elif guard_id == 3: inti_dic = { 'intimacy_experience': 264000, 'intimacy_rank': 11, 'level': 1, 'level_name': u'喜爱' } elif guard_id == 6: inti_dic = { 'intimacy_experience': 528000, 'intimacy_rank': 13, 'level': 1, 'level_name': u'喜爱' } elif guard_id == 12: inti_dic = { 'intimacy_experience': 56000, 'intimacy_rank': 15, 'level': 1, 'level_name': u'喜爱' } elif guard_id == 13: inti_dic = { 'intimacy_experience': 112000, 'intimacy_rank': 17, 'level': 2, 'level_name': u'真爱' } if following: self.assertEqual(obj['intimacy_experience'], inti_dic['intimacy_experience']) self.assertEqual(obj['intimacy_rank'], inti_dic['intimacy_rank']) intimacy_level_obj = obj['intimacy_level_obj'] self.assertEqual(intimacy_level_obj['level'], inti_dic['level']) self.assertEqual(intimacy_level_obj['level_name'], inti_dic['level_name']) if guard_id == 13: self.assertEqual(intimacy_level_obj['rank_start'], 16) self.assertEqual(intimacy_level_obj['rank_end'], 30) else: self.assertEqual(intimacy_level_obj['rank_start'], 1) self.assertEqual(intimacy_level_obj['rank_end'], 15) else: if identity: self.assertEqual(obj['intimacy_experience'], 0) self.assertEqual(obj['intimacy_rank'], 1) self.assertEqual(obj['intimacy_next_experience'], 10000) self.assertEqual(obj['intimacy_level_obj']['level'], 1) self.assertEqual(obj['intimacy_level_obj']['level_name'], u'喜爱') self.assertEqual(obj['intimacy_level_obj']['rank_start'], 1) self.assertEqual(obj['intimacy_level_obj']['rank_end'], 15) else: self.assertEqual(obj['intimacy_experience'], 0) self.assertEqual(obj['intimacy_rank'], 0) self.assertEqual(obj['intimacy_next_experience'], 0) self.assertIsNone(obj['intimacy_level_obj']) assert_intimacy(intimacy_obj, following, guard_id) identity_obj = json.loads(response.content)['result']['identity_obj'] identity_user_guard_obj = identity_obj['user_guard_obj'] self.assertEqual(identity_user_guard_obj['user_id'], (self.user_id)) assert_guard_obj(obj=identity_user_guard_obj, guard_id=guard_id) identity_intimacy_obj = json.loads( response.content)['result']['identity_obj']['intimacy_obj'] assert_intimacy(identity_intimacy_obj, following, guard_id, identity=True) if following: self.assertEqual(identity_obj['has_followed'], 1) else: self.assertEqual(identity_obj['has_followed'], 0) anchor_obj = json.loads( response.content)['result']['room_obj']['anchor_obj'] self.assertEqual(anchor_obj['id'], self.anchor_id) self.assertEqual(anchor_obj['anchor_rank'], anchor_rank) self.assertEqual(anchor_obj['sun_resumed_time'], 180) self.assertEqual(anchor_obj['sun_max_num'], 50) live_api = LiveApi(self.login_name) response = live_api.get({'room_id': self.room_id}) self.assertEqual(live_api.get_code(), 0) room_hot_num_after_buy = json.loads( response.content)['result']['room_obj']['curr_hot_num'] self.assertEqual(room_hot_num_after_buy - room_hot_num, guard_price) consumption_api = ConsumptionApi(self.login_name) response = consumption_api.get() self.assertEqual(consumption_api.get_code(), 0) self.assertEqual( len(json.loads(response.content)['result']['consume_list']), 1) consume_list = json.loads( response.content)['result']['consume_list'][0] self.assertEqual(consume_list['user_id'], self.user_id) self.assertEqual(consume_list['type'], u'3') self.assertEqual(consume_list['gold'], guard_price) self.assertEqual(consume_list['corresponding_id'], guard_id) self.assertEqual(consume_list['corresponding_name'], u'守护') self.assertEqual(consume_list['corresponding_num'], 1) self.assertEqual(consume_list['room_id'], self.room_id) self.assertEqual(consume_list['status'], 1) self.assertEqual(consume_list['behavior_desc'], u'购买守护') self.assertEqual( consume_list['room_title'], MysqlOperation(room_id=self.room_id).get_room_details()['title']) self.assertEqual(consume_list['consumption_type'], u'%s金币' % guard_price) my_guard_api = MyGuardApi(self.login_name) response = my_guard_api.get() self.assertEqual(my_guard_api.get_code(), 0) guard_list = json.loads(response.content)['result']['guard_list'] self.assertEqual(len(guard_list), 1) self.assertEqual(guard_list[0]['anchor_id'], self.anchor_id) if guard_id == 1: guard_rank = 1 expire_time_num = 31 elif guard_id == 2: guard_rank = 2 expire_time_num = 62 elif guard_id in [3, 6]: guard_rank = 3 if guard_id == 3: expire_time_num = 93 elif guard_id == 6: expire_time_num = 186 elif guard_id in [12, 13]: guard_rank = 4 if guard_id == 12: expire_time_num = 372 elif guard_id == 13: expire_time_num = 744 expire_time = ( datetime.datetime.now() + datetime.timedelta(days=+expire_time_num)).strftime("%Y-%m-%d") self.assertIn(expire_time, guard_list[0]['expire_time']) self.assertEqual(guard_list[0]['guard_rank'], guard_rank) room_obj = guard_list[0]['room_obj'] self.assertEqual(room_obj['id'], self.room_id) self.assertEqual(room_obj['room_type'], 1) self.assertEqual(room_obj['room_style'], 1) self.assertEqual(room_obj['room_style_extend'], 0) guard_list_anchor_obj = room_obj['anchor_obj'] self.assertEqual(guard_list_anchor_obj['id'], self.anchor_id) self.assertEqual(guard_list_anchor_obj['anchor_rank'], anchor_rank) if guard_id in [1, 2, 3, 12]: enter_room_api = EnterRoomApi(self.login_name) response = enter_room_api.get({'room_id': self.room_id}) self.assertEqual(enter_room_api.get_code(), 0) ani_obj = json.loads( response.content )['result']['enter_room_message']['msg']['obj']['ani_obj'] self.assertEqual(ani_obj['ani_type'], u'entry_guard') if guard_id == 1: self.assertEqual(ani_obj['ani_id'], 1) elif guard_id == 2: self.assertEqual(ani_obj['ani_id'], 2) elif guard_id == 3: self.assertEqual(ani_obj['ani_id'], 3) elif guard_id == 12: self.assertEqual(ani_obj['ani_id'], 4) self.assertEqual(ani_obj['ani_num'], 0) self.assertIsNone(ani_obj['category_type'])
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_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_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)
def normal_admin_add_black_action(self, **kwargs): add_super_visor = kwargs['add_super_visor'] user_id = kwargs['user_id'] type = kwargs['type'] blacker_type = kwargs['blacker_type'] is_guard = kwargs['is_guard'] guard_id = kwargs['guard_id'] is_noble = kwargs['is_noble'] noble_id = kwargs['noble_id'] user_is_anchor = kwargs['user_is_anchor'] user_login_name = MysqlOperation( user_id=user_id).get_user_details()['login_name'] price = None add_super_visor_api = AddSuperVisorApi(self.anchor_login_name) add_super_visor_api.get({ 'user_id': self.normal_admin_user_id, 'anchor_id': self.anchor_id, 'type': '40' }) self.assertEqual(add_super_visor_api.get_code(), 0) if is_guard: if guard_id == 1: price = 588000 elif guard_id == 2: price = 1176000 elif guard_id == 3: price = 1764000 elif guard_id == 12: price = 7056000 mysql_operation = MysqlOperation(user_id=user_id) mysql_operation.fix_user_account(gold_num=price) RedisHold().clean_redis_user_detail(user_id) time.sleep(self.time_sleep) buy_guard_api = BuyGuardApi(user_login_name) buy_guard_api.get({ 'room_id': self.room_id, 'guard_id': guard_id, 'currency': 'gold' }) self.assertEqual(buy_guard_api.get_code(), 0) if is_noble: if noble_id == 1: price = 24000 elif noble_id == 2: price = 40000 elif noble_id == 3: price = 80000 elif noble_id == 4: price = 400000 elif noble_id == 5: price = 800000 elif noble_id == 6: price = 2400000 elif noble_id == 7: price = 24000000 mysql_operation = MysqlOperation(user_id=user_id) mysql_operation.fix_user_account(gold_num=price) RedisHold().clean_redis_user_detail(user_id) time.sleep(self.time_sleep) buy_noble_api = BuyNobleApi(user_login_name) buy_noble_api.get({ 'noble_id': noble_id, 'num': 1, 'room_id': self.room_id, 'currency': 'gold' }) self.assertEqual(buy_noble_api.get_code(), 0) if add_super_visor: add_super_visor_api = AddSuperVisorApi(self.anchor_login_name) add_super_visor_api.get({ 'user_id': user_id, 'anchor_id': self.anchor_id, 'type': type }) self.assertEqual(add_super_visor_api.get_code(), 0) def assert_forbid_type(forbid_type): count = 1 max_count = 10 while count < max_count: black_user_detail = MysqlOperation( user_id=user_id).get_black_user_details() if black_user_detail == None: time.sleep(self.time_sleep) count += 1 else: self.assertEqual(black_user_detail['type'], (forbid_type)) break self.assertLess(count, max_count) add_black_user_api = AddBlackUserApi(self.normal_admin_user_name) add_black_user_api.get({ 'user_id': user_id, 'anchor_id': self.anchor_id, 'blacker_type': blacker_type }) if user_is_anchor: self.assertEqual(add_black_user_api.get_code(), 900012) self.assertEqual(add_black_user_api.get_response_message(), u'权限不足,设置失败') elif is_guard: if blacker_type == 'forbid_shout': self.assertEqual(add_black_user_api.get_code(), 0) self.assertEqual(add_black_user_api.get_response_message(), u'操作成功') assert_forbid_type(blacker_type) else: self.assertEqual(add_black_user_api.get_code(), 900013) self.assertEqual(add_black_user_api.get_response_message(), u'守护用户不能被限制拉黑和禁言') elif is_noble: if blacker_type == 'forbid_shout': self.assertEqual(add_black_user_api.get_code(), 411151) self.assertEqual(add_black_user_api.get_response_message(), u'权限不足,禁止喊话失败') if blacker_type == 'forbid_speak': if noble_id >= 3: self.assertEqual(add_black_user_api.get_code(), 411150) self.assertEqual(add_black_user_api.get_response_message(), u'权限不足,禁言失败') else: self.assertEqual(add_black_user_api.get_code(), 0) self.assertEqual(add_black_user_api.get_response_message(), u'操作成功') assert_forbid_type(blacker_type) if blacker_type == 'forbid_visit': if noble_id >= 2: self.assertEqual(add_black_user_api.get_code(), 411152) self.assertEqual(add_black_user_api.get_response_message(), u'权限不足,踢出房间失败') else: self.assertEqual(add_black_user_api.get_code(), 0) self.assertEqual(add_black_user_api.get_response_message(), u'操作成功') enter_room_api = EnterRoomApi(user_login_name) enter_room_api.get({'room_id': self.room_id}) self.assertEqual(enter_room_api.get_code(), 402002) self.assertEqual(enter_room_api.get_response_message(), u'说明是禁止访问') elif type in ['60', '40']: self.assertEqual(add_black_user_api.get_code(), 900014) self.assertEqual(add_black_user_api.get_response_message(), u'权限不足,设置失败') else: self.assertEqual(add_black_user_api.get_code(), 0) self.assertEqual(add_black_user_api.get_response_message(), u'操作成功') if blacker_type == 'forbid_visit': enter_room_api = EnterRoomApi(user_login_name) enter_room_api.get({'room_id': self.room_id}) self.assertEqual(enter_room_api.get_code(), 402002) self.assertEqual(enter_room_api.get_response_message(), u'说明是禁止访问') else: assert_forbid_type(blacker_type)