예제 #1
0
def test_start_test_after_reset_session(act):
    user = TelegramUser(
        tg_user_id=Utils.get_random_number(5),
        name=Utils.get_random_text(10),
        username=Utils.get_random_text(10),
        specialty="test",
    )
    question = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )

    act.add_user(user)
    assert act.has_started_test(user.tg_user_id) is False
    act.add_question(question)
    answer = Answer(
        quest_id=question.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer=Utils.get_random_text(50),
        link_to_audio_answer=Utils.get_random_text(50),
    )
    act.add_answer(answer)
    act.reset_session(user)
    assert act.get_next_test(user.tg_user_id)[0].text_question == question.text_question
    act.remove_user(user)
    act.remove_questions("test")
예제 #2
0
def test_has_started_test(act):
    user = TelegramUser(
        tg_user_id=Utils.get_random_number(5),
        name=Utils.get_random_text(10),
        username=Utils.get_random_text(10),
        specialty="test",
    )
    question = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    act.add_user(user)
    assert act.has_started_test(user.tg_user_id) is False
    act.add_question(question)
    act.get_next_test(user.tg_user_id)
    assert act.has_started_test(user.tg_user_id) is True
    answer = Answer(
        quest_id=question.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer="   ",
        link_to_audio_answer=Utils.get_random_text(50),
    )
    act.add_answer(answer)
    with pytest.raises(NoNewQuestionsException):
        act.get_next_test(user.tg_user_id)
    act.remove_user(user)
    act.remove_questions("test")
예제 #3
0
def test_no_add_answer_with_empty_text(act):
    user = TelegramUser(
        tg_user_id=Utils.get_random_number(5),
        name=Utils.get_random_text(10),
        username=Utils.get_random_text(10),
        specialty="test",
    )
    question1 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    question2 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    question3 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    act.add_user(user)
    act.add_question(question1)
    act.add_question(question2)
    act.add_question(question3)
    answer1 = Answer(
        quest_id=question1.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer="   ",
        link_to_audio_answer=Utils.get_random_text(50),
    )
    answer2 = Answer(
        quest_id=question2.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer="   ",
        link_to_audio_answer="",
    )
    assert act.add_answer(answer1) is not None
    assert act.add_answer(answer2) is None
    act.remove_user(user)
    act.remove_questions("test")
예제 #4
0
def test_get_next_test(act):
    user = TelegramUser(
        tg_user_id=Utils.get_random_number(5),
        name=Utils.get_random_text(10),
        username=Utils.get_random_text(10),
        specialty="test",
    )
    question1 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    question2 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    question3 = Question(
        question_type="test",
        question_category=Utils.get_random_text(10),
        text_question=Utils.get_random_text(10),
        text_answer=Utils.get_random_text(10),
    )
    act.add_user(user)
    act.add_question(question1)
    act.add_question(question2)
    act.add_question(question3)
    act.get_next_test(user.tg_user_id)
    session = act.get_current_session(user.tg_user_id)
    assert session is not None
    answer1 = Answer(
        quest_id=question1.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer=Utils.get_random_text(50),
        link_to_audio_answer=Utils.get_random_text(50),
        session_id=session.id,
    )
    answer2 = Answer(
        quest_id=question2.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer=Utils.get_random_text(50),
        link_to_audio_answer=Utils.get_random_text(50),
        session_id=session.id,
    )
    answer3 = Answer(
        quest_id=question1.id,
        tg_user_id=user.tg_user_id,
        answer_type=start_new_test()[1],
        text_answer=Utils.get_random_text(50),
        link_to_audio_answer=Utils.get_random_text(50),
        session_id=session.id,
    )
    act.add_answer(answer1)
    act.add_answer(answer2)
    act.add_answer(answer3)
    question = act.get_next_test(user.tg_user_id)[0]
    assert question.id == question3.id
    act.remove_user(user)
    act.remove_questions("test")
예제 #5
0
def test_start_new_test():
    assert start_new_test() == [
        AnswerTypes.VOICE.value,
        AnswerTypes.TEXT.value,
    ]