Ejemplo n.º 1
0
 def test_answers_clue_properly(self):
     answers = [
         Answer(pattern=r'\w+\s+(?P<second_word>\w+)', next_clue='TWOWORDS'),
         Answer(pattern=r'steve', next_clue="STEVE"),
         Answer(pattern=r'.*', next_clue='CATCHALL'),
     ]
     message = Message(text='test answer')
     next_clue, answer_data = get_next_clue(message, answers)
     self.assertEqual('TWOWORDS', next_clue)
     self.assertEqual({'second_word': 'answer'}, answer_data)
Ejemplo n.º 2
0
 def test_requires_matching_receiver(self):
     answers = [
         Answer(pattern=r'.*', next_clue='STORY:FIRSTCLUE', receiver=SECONDARY_SERVER_PHONE),
         Answer(pattern=r'.*', next_clue='STORY:SECONDCLUE')
     ]
     user = MagicMock()
     message = Message(text='correct answer')
     group_mock = Mock(clue=Mock(is_endpoint=False, hint='My Hint', answers=answers))
     result = answer(message, user, group_mock)
     self.assertEqual(CLUE, result.response_type)
     self.assertEqual('STORY:SECONDCLUE', result.group.clue_uid)
Ejemplo n.º 3
0
    def test_requires_media(self):
        answers = [
            Answer(pattern=r'.*', next_clue='STORY:FIRSTCLUE', require_media=True),
            Answer(pattern=r'.*', next_clue='STORY:SECONDCLUE')
        ]
        user = MagicMock()
        message_without_media = Message(text='correct answer')
        group_mock = Mock(clue=Mock(is_endpoint=False, hint='My Hint', answers=answers))

        result_without_media = answer(message_without_media, user, group_mock)

        self.assertEqual('STORY:SECONDCLUE', result_without_media.group.clue_uid)
Ejemplo n.º 4
0
    def test_matches_if_media_given(self):
        answers = [
            Answer(pattern=r'.*', next_clue='STORY:FIRSTCLUE', require_media=True),
            Answer(pattern=r'.*', next_clue='STORY:SECONDCLUE')
        ]
        user = MagicMock()
        message_with_media = Message(text='correct answer', media_url='www.example.com/caturday.png')
        group_mock = Mock(clue=Mock(is_endpoint=False, hint='My Hint', answers=answers))

        result_with_media = answer(message_with_media, user, group_mock)

        self.assertEqual('STORY:FIRSTCLUE', result_with_media.group.clue_uid)
Ejemplo n.º 5
0
 def test_gives_hints_if_incorrect(self):
     answers = [Answer(pattern=r'tough answer', next_clue='SOME:NEXTCLUE')]
     user = MagicMock()
     message = Message(text='this is not the correct answer')
     group_mock = Mock(clue=Mock(is_endpoint=False, hint='My Hint', answers=answers))
     result = answer(message, user, group_mock)
     self.assertEqual(['My Hint'], [r.text for r in result.messages])
Ejemplo n.º 6
0
def create_answer(qid):
    question = Question.query.get_or_404(qid)
    form = AnswerForm().validate_for_api()
    with db.auto_commit():
        answer = Answer(
            content=form.content.data,
            author_gid=g.user['gid'],
            # author_gid=g.user['gid']
        )
        if g.user['scope'] == 'TeacherScope':
            if not question.teacher_aid:
                question.teacher_answer = answer
                # todo: history
                # history = History.create_from_teacher_answer(answer, create_answer=True)
            else:
                return Duplicate()
        else:
            if not question.student_aid:
                question.student_answer = answer
                # todo: history
                # history = History.create_from_student_answer(answer, create_answer=True)
            else:
                return Duplicate()
        db.session.add(answer)
    return Success()
Ejemplo n.º 7
0
    def test_sets_next_clue_on_group(self):
        user = MagicMock()
        answers = [
            Answer(
                pattern=r'\w+\s+(?P<group_word>\w+)',
                next_clue=r'STORY:TWO-WORDS',
            ),
            Answer(
                pattern=r'.*',
                next_clue=r'STORY:GENERIC'
            )
        ]
        message = Message(text='test answer')

        group_mock = Mock(data={}, clue=Mock(is_endpoint=False, answers=answers))
        result = answer(message, user, group_mock)
        self.assertEqual("STORY:TWO-WORDS", result.group.clue_uid)
        self.assertEqual({'group_word': 'answer'}, result.group.data)
Ejemplo n.º 8
0
def create_and_save_question(title, text, is_mcq, answers, room):
    '''
    Helper to create a question and save it to the graph
    :param name: the name of the question
    :param active: whether or not this question will be active by default
    :param admin_id: the user id representing the admin
    :param course_id: the course code / id representing the course that this question studies
    :return ValueError: raised if either the course or user cannot be found in the graph
    '''

    new_question = Question(title=title, text=text, is_multiple_choice=is_mcq)
    new_question.save()

    new_question.room.connect(room)

    for a in answers:
        temp_answ = Answer(text=a.get('text'), correct=a.get('correct'))
        temp_answ.save()
        temp_answ.question.connect(new_question)

    return new_question