Beispiel #1
0
    def test_start_quiz_stop_last_not_set_answer(self):
        """
        测试上一局竞猜停止后未设置答案开启新的竞猜
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id': quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(), 0)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)
        self.assertEqual(
            json.loads(
                response.content)['result']['question_list'][0]['status'], 2)
        now_time_format = datetime.datetime.now().strftime("%Y-%m-%d")
        self.assertIn(
            now_time_format,
            json.loads(
                response.content)['result']['question_list'][0]['end_time'])

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 505411)
        self.assertEqual(start_quiz_api.get_response_message(), u'请先设置竞猜结果')
Beispiel #2
0
    def test_start_quiz_four(self):
        """
        测试开始竞猜时最多选择三道题目
        :return:
        """
        for x in range(4):
            set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
            set_questions_api.get({
                'room_id': self.game_room,
                'question': self.questions + str(x),
                'option_a': self.option_a,
                'option_b': self.option_b
            })
            self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 4)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 505412)
        self.assertEqual(start_quiz_api.get_response_message(), u'问题设置不能超过三个')
Beispiel #3
0
    def test_quiz_stop_last_not_set_answer(self):
        """
        测试停止竞猜未设置答案进行下注
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        question_ids = []
        for x in MysqlOperation(room_id=self.game_room).get_questions():
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        mysql_operation = MysqlOperation(user_id=self.user_id)
        mysql_operation.fix_user_account(gold_num=50000)
        RedisHold().clean_redis_user_detail(self.user_id)
        time.sleep(self.time_sleep)

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id': quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(), 0)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)

        self.assertEqual(
            json.loads(
                response.content)['result']['question_list'][0]['status'], 2)
        now_time_format = datetime.datetime.now().strftime("%Y-%m-%d")
        self.assertIn(
            now_time_format,
            json.loads(
                response.content)['result']['question_list'][0]['end_time'])

        quiz_api = QuizApi(self.user_login_name)
        quiz_api.get({
            'question_id': quiz_questions_id,
            'gold': '20000',
            'option': 'A'
        })
        self.assertEqual(quiz_api.get_code(), 505209)
        self.assertEqual(quiz_api.get_response_message(),
                         u'对不起,管理员已停止该竞猜,快去竞猜下一个题目吧')
Beispiel #4
0
    def test_start_quiz_normal_user(self):
        """
        测试普通用户开启竞猜通道
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.user_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 505404)
        self.assertEqual(start_quiz_api.get_response_message(), u'权限不足')
    def test_set_answer_not_stop_quiz(self):
        """
        测试未停止竞猜设置答案
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        set_answer_api.get({'question_id': quiz_questions_id, 'option': u'A'})
        self.assertEqual(set_answer_api.get_code(), 505210)
        self.assertEqual(set_answer_api.get_response_message(), u'请先停止竞猜再设置结果')
Beispiel #6
0
    def test_start_quiz_room_id_null(self):
        """
        测试请求接口房间ID为空
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': None,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 402000)
        self.assertEqual(start_quiz_api.get_response_message(), u'房间ID不能为空')
Beispiel #7
0
    def test_start_quiz_unfinished_last_time(self):
        """
        测试上一次精彩未结束时开始新的竞猜
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        response = start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)
        act_id = json.loads(response.content)['result']['act_id']
        self.assertEqual(act_id, 1)
        self.assertEqual(
            json.loads(response.content)['result']['room_id'], self.game_room)

        quiz_questions = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()
        self.assertEqual(len(quiz_questions), 1)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 505411)
        self.assertEqual(start_quiz_api.get_response_message(), u'请先设置竞猜结果')
Beispiel #8
0
 def test_start_quiz_questions_id_error(self):
     """
     测试请求接口问题ID不存在
     :return:
     """
     start_quiz_api = StartQuizApi(self.game_anchor_login_name)
     start_quiz_api.get({
         'room_id': self.game_room,
         'question_bank_ids': json.dumps(['999', '998'])
     })
     self.assertEqual(start_quiz_api.get_code(), 505405)
     self.assertEqual(start_quiz_api.get_response_message(), u'问题不存在')
Beispiel #9
0
 def test_start_quiz_questions_id_null(self):
     """
     测试请求接口问题ID为空
     :return:
     """
     start_quiz_api = StartQuizApi(self.game_anchor_login_name)
     start_quiz_api.get({
         'room_id': self.game_room,
         'question_bank_ids': None
     })
     self.assertEqual(start_quiz_api.get_code(), 505401)
     self.assertEqual(start_quiz_api.get_response_message(), u'问题不能为空')
    def test_set_answer_option_again(self):
        """
        测试重复设置答案
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id': quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(), 0)

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        response = set_answer_api.get({
            'question_id': quiz_questions_id,
            'option': 'A'
        })
        self.assertEqual(set_answer_api.get_code(), 0)
        question_obj = json.loads(response.content)['result']['question_obj']
        self.assertEqual(question_obj['status'], 3)
        self.assertEqual(question_obj['result'], u'A')

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        set_answer_api.get({'question_id': quiz_questions_id, 'option': 'A'})
        self.assertEqual(set_answer_api.get_code(), 505211)
        self.assertEqual(set_answer_api.get_response_message(), u'已经设置过竞猜结果了')
Beispiel #11
0
    def test_quiz_option_error(self):
        """
        测试请求下注接口竞猜选项错误
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        question_ids = []
        for x in MysqlOperation(room_id=self.game_room).get_questions():
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        mysql_operation = MysqlOperation(user_id=self.user_id)
        mysql_operation.fix_user_account(gold_num=10000)
        RedisHold().clean_redis_user_detail(self.user_id)
        time.sleep(self.time_sleep)

        quiz_api = QuizApi(self.user_login_name)
        quiz_api.get({
            'question_id': quiz_questions_id,
            'gold': 10000,
            'option': 'C'
        })
        self.assertEqual(quiz_api.get_code(), 505208)
        self.assertEqual(quiz_api.get_response_message(), u'竞猜选项不存在')
Beispiel #12
0
    def test_anchor_quiz_me(self):
        """
        测试主播无法投注自己房间得题目
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        question_ids = []
        for x in MysqlOperation(room_id=self.game_room).get_questions():
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        mysql_operation = MysqlOperation(user_id=self.game_anchor_id)
        mysql_operation.fix_user_account(gold_num=20000)
        RedisHold().clean_redis_user_detail(self.game_anchor_id)
        time.sleep(self.time_sleep)

        quiz_api = QuizApi(self.game_anchor_login_name)
        quiz_api.get({
            'question_id': quiz_questions_id,
            'gold': '20000',
            'option': 'A'
        })
        self.assertEqual(quiz_api.get_code(), 505226)
        self.assertEqual(quiz_api.get_response_message(), u'主播不能对自己直播间的问题进行投注')
    def test_set_answer_option_null(self):
        """
        测试请求接口选项为空
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id': quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(), 0)

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        set_answer_api.get({'question_id': quiz_questions_id, 'option': None})
        self.assertEqual(set_answer_api.get_code(), 505206)
        self.assertEqual(set_answer_api.get_response_message(), u'竞猜选项不能为空')
Beispiel #14
0
    def test_quiz_gold_low(self):
        """
        测试请求下注接口金币不足
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        question_ids = []
        for x in MysqlOperation(room_id=self.game_room).get_questions():
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        quiz_api = QuizApi(self.user_login_name)
        quiz_api.get({
            'question_id': quiz_questions_id,
            'gold': 10000,
            'option': 'A'
        })
        self.assertEqual(quiz_api.get_code(), 100032)
        self.assertEqual(quiz_api.get_response_message(), u'账户金币不足')
Beispiel #15
0
    def test_quiz_win(self):
        """
        测试竞猜消费记录和金币获取记录
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({'room_id': self.game_room, 'question': self.questions, 'option_a': self.option_a,
             'option_b': self.option_b})
        self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions),1)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({'room_id':self.game_room,'question_bank_ids':question_ids_json})
        self.assertEqual(start_quiz_api.get_code(),0)

        quiz_questions_id = MysqlOperation(room_id=self.game_room).get_quiz_questions()[0]['id']

        mysql_operation = MysqlOperation(user_id=self.user_id)
        mysql_operation.fix_user_account(gold_num=50000)
        RedisHold().clean_redis_user_detail(self.user_id)
        time.sleep(self.time_sleep)

        quiz_api = QuizApi(self.user_login_name)
        quiz_api.get({'question_id': quiz_questions_id, 'gold': '50000', 'option': 'A'})
        self.assertEqual(quiz_api.get_code(), 0)

        mysql_operation = MysqlOperation(user_id=self.user_id_two)
        mysql_operation.fix_user_account(gold_num=20000)
        RedisHold().clean_redis_user_detail(self.user_id_two)
        time.sleep(self.time_sleep)

        quiz_api = QuizApi(self.user_login_name_two)
        quiz_api.get({'question_id': quiz_questions_id, 'gold': '20000', 'option': 'B'})
        self.assertEqual(quiz_api.get_code(), 0)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)

        question_list = json.loads(response.content)['result']['question_list']
        self.assertEqual(len(question_list), 1)
        question_obj = json.loads(response.content)['result']['question_list'][0]
        self.assertEqual(int(question_obj['id']), int(quiz_questions_id))
        self.assertEqual(question_obj['room_id'], self.game_room)
        self.assertEqual(question_obj['question'], self.questions)
        self.assertEqual(question_obj['total_pool'], 70000)
        self.assertEqual(question_obj['init_pool'], u'0')
        self.assertEqual(question_obj['currency'], u'gold')
        self.assertEqual(question_obj['status'], u'1')
        self.assertEqual(question_obj['my_result'], 0)
        self.assertIsNone(question_obj['result'])

        options = question_obj['options']
        self.assertEqual(options['A']['odds'], u'1.4')
        self.assertEqual(options['A']['option_amount'], u'50000')
        self.assertEqual(options['A']['user_amount'], 0)
        self.assertEqual(options['A']['persent'], 0.025)

        self.assertEqual(options['B']['odds'], u'3.5')
        self.assertEqual(options['B']['option_amount'], u'20000')
        self.assertEqual(options['B']['user_amount'], 0)
        self.assertEqual(options['B']['persent'], 0.01)

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id':quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(),0)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)

        self.assertEqual(json.loads(response.content)['result']['question_list'][0]['status'],2)
        now_time_format = datetime.datetime.now().strftime("%Y-%m-%d")
        self.assertIn(now_time_format, json.loads(response.content)['result']['question_list'][0]['end_time'])

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        response = set_answer_api.get({'question_id': quiz_questions_id,'option':'A'})
        self.assertEqual(set_answer_api.get_code(),0)
        question_obj = json.loads(response.content)['result']['question_obj']
        self.assertEqual(question_obj['status'],3)
        self.assertEqual(question_obj['result'],u'A')
        time.sleep(2)
        consum_api = ConsumptionApi(self.user_login_name)
        response = consum_api.get()
        self.assertEqual(consum_api.get_code(),0)
        consume_list = json.loads(response.content)['result']['consume_list']
        self.assertEqual(len(consume_list),1)

        self.assertEqual(consume_list[0]['user_id'],self.user_id)
        self.assertIn(now_time_format,consume_list[0]['create_time'])
        self.assertEqual(consume_list[0]['type'],u'101')
        self.assertEqual(consume_list[0]['gold'],50000)
        self.assertEqual(consume_list[0]['corresponding_id'],quiz_questions_id)
        self.assertEqual(consume_list[0]['corresponding_name'],u'A')
        self.assertEqual(consume_list[0]['corresponding_num'],0)
        self.assertEqual(consume_list[0]['room_id'],self.game_room)
        self.assertEqual(consume_list[0]['status'],1)
        self.assertEqual(consume_list[0]['behavior_desc'],u'竞猜下注')
        self.assertEqual(consume_list[0]['consumption_type'],u'50000金币')

        identity_obj = json.loads(response.content)['result']['identity_obj']
        self.assertEqual(identity_obj['gold'],70000)
        self.assertEqual(identity_obj['diamond'],u'0')

        consum_api = ConsumptionApi(self.user_login_name_two)
        response = consum_api.get()
        self.assertEqual(consum_api.get_code(),0)
        consume_list = json.loads(response.content)['result']['consume_list']
        self.assertEqual(len(consume_list),1)

        self.assertEqual(consume_list[0]['user_id'],self.user_id_two)
        self.assertIn(now_time_format,consume_list[0]['create_time'])
        self.assertEqual(consume_list[0]['type'],u'101')
        self.assertEqual(consume_list[0]['gold'],20000)
        self.assertEqual(consume_list[0]['corresponding_id'],quiz_questions_id)
        self.assertEqual(consume_list[0]['corresponding_name'],u'B')
        self.assertEqual(consume_list[0]['corresponding_num'],0)
        self.assertEqual(consume_list[0]['room_id'],self.game_room)
        self.assertEqual(consume_list[0]['status'],1)
        self.assertEqual(consume_list[0]['behavior_desc'],u'竞猜下注')
        self.assertEqual(consume_list[0]['consumption_type'],u'20000金币')

        identity_obj = json.loads(response.content)['result']['identity_obj']
        self.assertEqual(identity_obj['gold'],0)
        self.assertEqual(identity_obj['diamond'],u'0')

        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]['user_id'],self.user_id)
        self.assertEqual(account_list[0]['type'],u'102')
        self.assertEqual(account_list[0]['gold'],70000)

        self.assertEqual(account_list[0]['corresponding_id'],quiz_questions_id)
        self.assertEqual(account_list[0]['corresponding_name'],u'A')
        self.assertEqual(account_list[0]['corresponding_num'],0)
        self.assertEqual(account_list[0]['status'],1)
        self.assertEqual(account_list[0]['money'],0)
        self.assertEqual(account_list[0]['behavior_desc'],u'竞猜奖励')
        self.assertEqual(account_list[0]['consumption_type'],u'70000金币')
        self.assertEqual(account_list[0]['room_id'],self.game_room)


        gold_account_api = GoldAccountApi(self.user_login_name_two)
        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),0)
Beispiel #16
0
    def test_start_quiz_two_success(self):
        """
        测试选择两道题目开始竞猜成功
        :return:
        """
        for x in range(2):
            set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
            set_questions_api.get({
                'room_id': self.game_room,
                'question': self.questions + str(x),
                'option_a': self.option_a,
                'option_b': self.option_b
            })
            self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 2)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        response = start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)
        act_id = json.loads(response.content)['result']['act_id']
        self.assertEqual(act_id, 1)
        self.assertEqual(
            json.loads(response.content)['result']['room_id'], self.game_room)

        quiz_questions = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()
        self.assertEqual(len(quiz_questions), 2)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)
        question_list = json.loads(response.content)['result']['question_list']
        self.assertEqual(len(question_list), 2)

        for x in question_list:
            self.assertEqual(int(x['act_id']), int(act_id))
            self.assertEqual(x['room_id'], self.game_room)
            self.assertIn(self.questions, x['question'])
            self.assertEqual(x['total_pool'], u'0')
            self.assertEqual(x['init_pool'], u'0')
            self.assertEqual(x['currency'], u'gold')
            self.assertEqual(x['status'], u'1')
            self.assertIsNone(x['result'])
            self.assertEqual(x['my_result'], 0)
            self.assertIsNone(x['end_time'])
            now_time_format = datetime.datetime.now().strftime("%Y-%m-%d")
            self.assertIn(now_time_format, x['start_time'])

            options = x['options']
            self.assertEqual(len(options), 2)
            self.assertEqual(options['A']['content'], self.option_a)
            self.assertEqual(options['A']['answer'], self.option_a)
            self.assertEqual(options['A']['odds'], u'1.0')
            self.assertEqual(options['A']['option_amount'], 0)
            self.assertEqual(options['A']['user_amount'], 0)
            self.assertEqual(options['A']['persent'], 0)
            self.assertEqual(options['B']['content'], self.option_b)
            self.assertEqual(options['B']['answer'], self.option_b)
            self.assertEqual(options['B']['odds'], u'1.0')
            self.assertEqual(options['B']['option_amount'], 0)
            self.assertEqual(options['B']['user_amount'], 0)
            self.assertEqual(options['B']['persent'], 0)
Beispiel #17
0
    def test_start_quiz_two_questions_onr_not_set_answer(self):
        """
        测试选择两道题目其中一道未设置答案时开启竞猜失败
        :return:
        """
        for x in range(2):
            set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
            set_questions_api.get({
                'room_id': self.game_room,
                'question': self.questions + str(x),
                'option_a': self.option_a,
                'option_b': self.option_b
            })
            self.assertEqual(set_questions_api.get_code(), 0)

        db_questions = MysqlOperation(room_id=self.game_room).get_questions()
        self.assertEqual(len(db_questions), 2)
        question_ids = []
        for x in db_questions:
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_ids = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()
        self.assertEqual(len(quiz_questions_ids), 2)
        quiz_questions_id = quiz_questions_ids[0]['id']

        stop_quiz_api = StopQuizApi(self.game_anchor_login_name)
        stop_quiz_api.get({'question_id': quiz_questions_id})
        self.assertEqual(stop_quiz_api.get_code(), 0)

        get_questions_api = GetQuestionsApi(self.game_anchor_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)

        self.assertEqual(
            json.loads(
                response.content)['result']['question_list'][0]['status'], 2)
        now_time_format = datetime.datetime.now().strftime("%Y-%m-%d")
        self.assertIn(
            now_time_format,
            json.loads(
                response.content)['result']['question_list'][0]['end_time'])

        set_answer_api = SetAnswerApi(self.game_anchor_login_name)
        response = set_answer_api.get({
            'question_id': quiz_questions_id,
            'option': 'A'
        })
        self.assertEqual(set_answer_api.get_code(), 0)
        question_obj = json.loads(response.content)['result']['question_obj']
        self.assertEqual(question_obj['status'], 3)
        self.assertEqual(question_obj['result'], u'A')

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 505411)
        self.assertEqual(start_quiz_api.get_response_message(), u'请先设置竞猜结果')
Beispiel #18
0
    def test_anchor_quiz_other_room(self):
        """
        测试主播投注其他房间得题目
        :return:
        """
        set_questions_api = SetQuestionsApi(self.game_anchor_login_name)
        set_questions_api.get({
            'room_id': self.game_room,
            'question': self.questions,
            'option_a': self.option_a,
            'option_b': self.option_b
        })
        self.assertEqual(set_questions_api.get_code(), 0)

        question_ids = []
        for x in MysqlOperation(room_id=self.game_room).get_questions():
            question_ids.append(x['id'])
        question_ids_json = json.dumps(question_ids)

        start_quiz_api = StartQuizApi(self.game_anchor_login_name)
        start_quiz_api.get({
            'room_id': self.game_room,
            'question_bank_ids': question_ids_json
        })
        self.assertEqual(start_quiz_api.get_code(), 0)

        quiz_questions_id = MysqlOperation(
            room_id=self.game_room).get_quiz_questions()[0]['id']

        mysql_operation = MysqlOperation(user_id=self.other_anchor_id)
        mysql_operation.fix_user_account(gold_num=20000)
        RedisHold().clean_redis_user_detail(self.other_anchor_id)
        time.sleep(self.time_sleep)

        quiz_api = QuizApi(self.other_anchor_login_name)
        quiz_api.get({
            'question_id': quiz_questions_id,
            'gold': '20000',
            'option': 'A'
        })
        self.assertEqual(quiz_api.get_code(), 0)

        get_questions_api = GetQuestionsApi(self.user_login_name)
        response = get_questions_api.get({'room_id': self.game_room})
        self.assertEqual(get_questions_api.get_code(), 0)
        question_list = json.loads(response.content)['result']['question_list']
        self.assertEqual(len(question_list), 1)
        question_obj = json.loads(
            response.content)['result']['question_list'][0]
        self.assertEqual(int(question_obj['id']), int(quiz_questions_id))
        self.assertEqual(question_obj['room_id'], self.game_room)
        self.assertEqual(question_obj['question'], self.questions)
        self.assertEqual(question_obj['total_pool'], 20000)
        self.assertEqual(question_obj['init_pool'], u'0')
        self.assertEqual(question_obj['currency'], u'gold')
        self.assertEqual(question_obj['status'], u'1')
        self.assertEqual(question_obj['my_result'], 0)
        self.assertIsNone(question_obj['result'])

        options = question_obj['options']
        self.assertEqual(options['A']['odds'], u'1.0')
        self.assertEqual(options['A']['option_amount'], u'20000')
        self.assertEqual(options['A']['user_amount'], 0)
        self.assertEqual(options['A']['persent'], 0.01)

        self.assertEqual(options['B']['odds'], u'1.0')
        self.assertEqual(options['B']['option_amount'], u'0')
        self.assertEqual(options['B']['user_amount'], 0)
        self.assertEqual(options['B']['persent'], 0)