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'请先停止竞猜再设置结果')
    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'已经设置过竞猜结果了')
Exemple #3
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'竞猜选项不存在')
    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'竞猜选项不能为空')
Exemple #5
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'账户金币不足')