Exemple #1
0
def test_questions_and_answers(monkeypatch):
    monkeypatch.setenv("DBNAME", "Test")
    session = get_db_session(True, None)

    q1 = ReviewQuestion()
    q1.id = "1"
    q1.content = "Es ist eine Quelle angegeben."

    q2 = ReviewQuestion()
    q2.id = "2"
    q2.content = "Die Rechtschreibung ist korrekt."

    o1 = AnswerOption()
    o1.id = "1"
    o1.text = "Stimme zu"
    o1.value = 4

    q1.options = [o1]

    assert len(q1.options) == 1
    assert len(o1.questions) == 1

    q2.options = [o1]

    assert len(q1.options) == 1
    assert len(o1.questions) == 2

    session.add(q1)
    session.add(q2)
    session.add(o1)
    options = session.query(AnswerOption).all()
    assert len(options) == 1
Exemple #2
0
def test_questions_and_answers():
    with Session() as session:

        q1 = ReviewQuestion()
        q1.id = "1"
        q1.content = "Es ist eine Quelle angegeben."

        q2 = ReviewQuestion()
        q2.id = "2"
        q2.content = "Die Rechtschreibung ist korrekt."

        o1 = AnswerOption()
        o1.id = "1"
        o1.text = "Stimme zu"
        o1.value = 4

        q1.options = [o1]

        assert len(q1.options) == 1
        assert len(o1.questions) == 1

        q2.options = [o1]

        assert len(q1.options) == 1
        assert len(o1.questions) == 2

        session.add(q1)
        session.add(q2)
        session.add(o1)
        options = session.query(AnswerOption).all()
        assert len(options) == 1
def session(item_id, review_id, review_question_id, user_id):
    session = get_db_session(True, None)

    item = Item()
    item.id = item_id

    user = User()
    user.id = user_id

    level = Level(id=1)

    review = Review()
    review.id = review_id
    review.item_id = item.id
    review.user_id = user.id

    review_question = ReviewQuestion()
    review_question.id = review_question_id
    review_question.content = "Question content"
    review_question.info = "Question info"
    review_question.hint = "Question hint"

    o1 = AnswerOption(id="1", text="Option 1", value=0)
    o2 = AnswerOption(id="2", text="Option 2", value=1, tooltip="Tooltip 2")
    o3 = AnswerOption(id="3", text="Option 3", value=2)
    o4 = AnswerOption(id="4", text="Option 4", value=3)

    o1.questions = [review_question]
    o2.questions = [review_question]
    o4.questions = [review_question]
    o3.questions = [review_question]

    # all answers use the same review questions in order to keep the test data small
    reviewanswer1 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer2 = generate_review_answer(0, review_id, review_question_id)
    reviewanswer3 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer4 = generate_review_answer(3, review_id, review_question_id)
    reviewanswer5 = generate_review_answer(2, review_id, review_question_id)
    reviewanswer6 = generate_review_answer(1, review_id, review_question_id)
    reviewanswer7 = generate_review_answer(2, review_id, review_question_id)
    review.review_answers = [reviewanswer1, reviewanswer2, reviewanswer3,
                             reviewanswer4, reviewanswer5, reviewanswer6, reviewanswer7]

    session.add(item)
    session.add(user)
    session.add(level)
    session.add(review_question)
    # refernenced ReviewAnswers are stored as well
    session.add(review)

    session.commit()

    return session
Exemple #4
0
def create_questions(session):

    item_type1 = ItemType()
    item_type1.id = "Type1"

    item_type2 = ItemType()
    item_type2.id = "Type2"

    parentquestion1 = ReviewQuestion()
    parentquestion1.id = "1"
    parentquestion1.info = "1"
    parentquestion1.max_children = 2
    parentquestion1.item_type = item_type1
    parentquestion1.warning_tag = 'PQ1 warning'
    parentquestion1.warning_tag_icon_code = 'fas fa-link'

    childquestion1a = ReviewQuestion()
    childquestion1a.id = "1a"
    childquestion1a.content = "1a"
    childquestion1a.parent_question_id = "1"
    childquestion1a.upper_bound = 4
    childquestion1a.lower_bound = 3
    childquestion1a.max_children = 0
    childquestion1a.item_type = item_type1
    childquestion1a.warning_tag = 'CQ1a warning'
    childquestion1a.warning_tag_icon_code = 'fas fa-link'

    childquestion1b = ReviewQuestion()
    childquestion1b.id = "1b"
    childquestion1b.content = "1b"
    childquestion1b.parent_question_id = "1"
    childquestion1b.upper_bound = 2
    childquestion1b.lower_bound = 1
    childquestion1b.max_children = 0
    childquestion1b.item_type = item_type1
    childquestion1b.warning_tag = 'CQ1b warning'
    childquestion1b.warning_tag_icon_code = 'fas fa-link'

    childquestion1c = ReviewQuestion()
    childquestion1c.id = "1c"
    childquestion1c.content = "1c"
    childquestion1c.parent_question_id = "1"
    childquestion1c.upper_bound = 3
    childquestion1c.lower_bound = 2
    childquestion1c.max_children = 0
    childquestion1c.item_type = item_type1
    childquestion1c.warning_tag = 'CQ1c warning'
    childquestion1c.warning_tag_icon_code = 'fas fa-link'

    parentquestion2 = ReviewQuestion()
    parentquestion2.id = "2"
    parentquestion2.info = "2"
    parentquestion2.max_children = 1
    parentquestion2.item_type = item_type1
    parentquestion2.warning_tag = 'PQ2 warning'
    parentquestion2.warning_tag_icon_code = 'fas fa-link'

    childquestion2a = ReviewQuestion()
    childquestion2a.id = "2a"
    childquestion2a.content = "2a"
    childquestion2a.parent_question_id = "2"
    childquestion2a.upper_bound = 4
    childquestion2a.lower_bound = 3
    childquestion2a.max_children = 0
    childquestion2a.item_type = item_type1
    childquestion2a.warning_tag = 'CQ2a warning'
    childquestion2a.warning_tag_icon_code = 'fas fa-link'

    childquestion2b = ReviewQuestion()
    childquestion2b.id = "2b"
    childquestion2b.content = "2b"
    childquestion2b.parent_question_id = "2"
    childquestion2b.upper_bound = 2
    childquestion2b.lower_bound = 1
    childquestion2b.max_children = 0
    childquestion2b.item_type = item_type1
    childquestion2b.warning_tag = 'CQ2b warning'
    childquestion2b.warning_tag_icon_code = 'fas fa-link'

    parentquestion3 = ReviewQuestion()
    parentquestion3.id = "3"
    parentquestion3.info = "3"
    parentquestion3.max_children = 0
    parentquestion3.item_type = item_type1
    parentquestion3.warning_tag = 'PQ3 warning'
    parentquestion3.warning_tag_icon_code = 'fas fa-link'

    parentquestion4 = ReviewQuestion()
    parentquestion4.id = "4"
    parentquestion4.info = "4"
    parentquestion4.max_children = 0
    parentquestion4.item_type = item_type1
    parentquestion4.warning_tag = 'PQ4 warning'
    parentquestion4.warning_tag_icon_code = 'fas fa-link'

    parentquestion5 = ReviewQuestion()
    parentquestion5.id = "5"
    parentquestion5.info = "5"
    parentquestion5.max_children = 0
    parentquestion5.item_type = item_type1
    parentquestion5.warning_tag = 'PQ5 warning'
    parentquestion5.warning_tag_icon_code = 'fas fa-link'

    parentquestion6 = ReviewQuestion()
    parentquestion6.id = "6"
    parentquestion6.info = "6"
    parentquestion6.max_children = 0
    parentquestion6.item_type = item_type1
    parentquestion6.warning_tag = 'PQ6 warning'
    parentquestion6.warning_tag_icon_code = 'fas fa-link'

    parentquestion7 = ReviewQuestion()
    parentquestion7.id = "7"
    parentquestion7.info = "7"
    parentquestion7.max_children = 0
    parentquestion7.item_type = item_type1
    parentquestion7.warning_tag = 'PQ7 warning'
    parentquestion7.warning_tag_icon_code = 'fas fa-link'

    parentquestion8 = ReviewQuestion()
    parentquestion8.id = "8"
    parentquestion8.info = "8"
    parentquestion8.max_children = 0
    parentquestion8.item_type = item_type1
    parentquestion8.warning_tag = 'PQ8 warning'
    parentquestion8.warning_tag_icon_code = 'fas fa-link'

    parentquestion9 = ReviewQuestion()
    parentquestion9.id = "9"
    parentquestion9.info = "9"
    parentquestion9.max_children = 0
    parentquestion9.item_type = item_type1
    parentquestion9.warning_tag = 'PQ9 warning'
    parentquestion9.warning_tag_icon_code = 'fas fa-link'

    parentquestion10 = ReviewQuestion()
    parentquestion10.id = "10"
    parentquestion10.info = "10"
    parentquestion10.max_children = 0
    parentquestion10.item_type = item_type1
    parentquestion10.warning_tag = 'PQ10 warning'
    parentquestion10.warning_tag_icon_code = 'fas fa-link'

    other_type_question = ReviewQuestion()
    other_type_question.id = "other_type"
    other_type_question.info = "other_type"
    other_type_question.max_children = 0
    other_type_question.item_type = item_type2

    session.add(item_type1)
    session.add(item_type2)
    session.add(parentquestion1)
    session.add(parentquestion2)
    session.add(parentquestion3)
    session.add(parentquestion4)
    session.add(parentquestion5)
    session.add(parentquestion6)
    session.add(parentquestion7)
    session.add(parentquestion8)
    session.add(parentquestion9)
    session.add(parentquestion10)
    session.add(childquestion1a)
    session.add(childquestion1b)
    session.add(childquestion1c)
    session.add(childquestion2a)
    session.add(childquestion2b)
    session.commit()

    return session
Exemple #5
0
def child_question1(question_id_1, type_id_1) -> ReviewQuestion:
    cq1 = ReviewQuestion()
    cq1.id = str(uuid4())
    cq1.parent_question_id = question_id_1
    cq1.item_type_id = type_id_1
    return cq1
Exemple #6
0
def create_questions(session):

    item_type1 = ItemType()
    item_type1.id = "Type1"

    item_type2 = ItemType()
    item_type2.id = "Type2"

    parentquestion1 = ReviewQuestion()
    parentquestion1.id = "1"
    parentquestion1.info = "1"
    parentquestion1.max_children = 2
    parentquestion1.item_type = item_type1

    childquestion1a = ReviewQuestion()
    childquestion1a.id = "1a"
    childquestion1a.content = "1a"
    childquestion1a.parent_question_id = "1"
    childquestion1a.upper_bound = 4
    childquestion1a.lower_bound = 3
    childquestion1a.max_children = 0
    childquestion1a.item_type = item_type1

    childquestion1b = ReviewQuestion()
    childquestion1b.id = "1b"
    childquestion1b.content = "1b"
    childquestion1b.parent_question_id = "1"
    childquestion1b.upper_bound = 2
    childquestion1b.lower_bound = 1
    childquestion1b.max_children = 0
    childquestion1b.item_type = item_type1

    childquestion1c = ReviewQuestion()
    childquestion1c.id = "1c"
    childquestion1c.content = "1c"
    childquestion1c.parent_question_id = "1"
    childquestion1c.upper_bound = 3
    childquestion1c.lower_bound = 2
    childquestion1c.max_children = 0
    childquestion1c.item_type = item_type1

    parentquestion2 = ReviewQuestion()
    parentquestion2.id = "2"
    parentquestion2.info = "2"
    parentquestion2.max_children = 1
    parentquestion2.item_type = item_type1

    childquestion2a = ReviewQuestion()
    childquestion2a.id = "2a"
    childquestion2a.content = "2a"
    childquestion2a.parent_question_id = "2"
    childquestion2a.upper_bound = 4
    childquestion2a.lower_bound = 3
    childquestion2a.max_children = 0
    childquestion2a.item_type = item_type1

    childquestion2b = ReviewQuestion()
    childquestion2b.id = "2b"
    childquestion2b.content = "2b"
    childquestion2b.parent_question_id = "2"
    childquestion2b.upper_bound = 2
    childquestion2b.lower_bound = 1
    childquestion2b.max_children = 0
    childquestion2b.item_type = item_type1

    parentquestion3 = ReviewQuestion()
    parentquestion3.id = "3"
    parentquestion3.info = "3"
    parentquestion3.max_children = 0
    parentquestion3.item_type = item_type1

    parentquestion4 = ReviewQuestion()
    parentquestion4.id = "4"
    parentquestion4.info = "4"
    parentquestion4.max_children = 0
    parentquestion4.item_type = item_type1

    parentquestion5 = ReviewQuestion()
    parentquestion5.id = "5"
    parentquestion5.info = "5"
    parentquestion5.max_children = 0
    parentquestion5.item_type = item_type1

    parentquestion6 = ReviewQuestion()
    parentquestion6.id = "6"
    parentquestion6.info = "6"
    parentquestion6.max_children = 0
    parentquestion6.item_type = item_type1

    parentquestion7 = ReviewQuestion()
    parentquestion7.id = "7"
    parentquestion7.info = "7"
    parentquestion7.max_children = 0
    parentquestion7.item_type = item_type1

    parentquestion8 = ReviewQuestion()
    parentquestion8.id = "8"
    parentquestion8.info = "8"
    parentquestion8.max_children = 0
    parentquestion8.item_type = item_type1

    parentquestion9 = ReviewQuestion()
    parentquestion9.id = "9"
    parentquestion9.info = "9"
    parentquestion9.max_children = 0
    parentquestion9.item_type = item_type1

    parentquestion10 = ReviewQuestion()
    parentquestion10.id = "10"
    parentquestion10.info = "10"
    parentquestion10.max_children = 0
    parentquestion10.item_type = item_type1

    other_type_question = ReviewQuestion()
    other_type_question.id = "other_type"
    other_type_question.info = "other_type"
    other_type_question.max_children = 0
    other_type_question.item_type = item_type2

    session.add(item_type1)
    session.add(item_type2)
    session.add(parentquestion1)
    session.add(parentquestion2)
    session.add(parentquestion3)
    session.add(parentquestion4)
    session.add(parentquestion5)
    session.add(parentquestion6)
    session.add(parentquestion7)
    session.add(parentquestion8)
    session.add(parentquestion9)
    session.add(parentquestion10)
    session.add(childquestion1a)
    session.add(childquestion1b)
    session.add(childquestion1c)
    session.add(childquestion2a)
    session.add(childquestion2b)
    session.commit()

    return session
def test_get_review(item_id, review_id, review_question_id, user_id, tag_id,
                    item_tag_id, monkeypatch):
    """
    Gets a simple Review
    """
    monkeypatch.setenv("CORS_ALLOW_ORIGIN", "http://localhost:4200")

    with Session() as session:

        item = Item()
        item.id = item_id

        user = User()
        user.id = user_id

        level = Level(id=1)

        review = Review()
        review.id = review_id
        review.item_id = item.id
        review.user_id = user.id
        review.status = 'in_progress'

        tag = Tag(tag='test', id=tag_id)
        item_tag = ItemTag(id=item_tag_id,
                           item_id=item_id,
                           tag_id=tag_id,
                           review_id=review_id)

        comment = Comment(id='comment_id',
                          comment='testcomment',
                          review_id=review_id,
                          is_review_comment=True)

        review_question = ReviewQuestion()
        review_question.id = review_question_id
        review_question.content = "Question content"
        review_question.info = "Question info"
        review_question.hint = "Question hint"

        o1 = AnswerOption(id="1", text="Option 1", value=0)
        o2 = AnswerOption(id="2",
                          text="Option 2",
                          value=1,
                          tooltip="Tooltip 2")
        o3 = AnswerOption(id="3", text="Option 3", value=2)
        o4 = AnswerOption(id="4", text="Option 4", value=3)

        o1.questions = [review_question]
        o2.questions = [review_question]
        o4.questions = [review_question]
        o3.questions = [review_question]

        # all answers use the same review questions in order to keep the test data small
        reviewanswer1 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer2 = generate_review_answer(0, review_id,
                                               review_question_id)
        reviewanswer3 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer4 = generate_review_answer(3, review_id,
                                               review_question_id)
        reviewanswer5 = generate_review_answer(2, review_id,
                                               review_question_id)
        reviewanswer6 = generate_review_answer(1, review_id,
                                               review_question_id)
        reviewanswer7 = generate_review_answer(2, review_id,
                                               review_question_id)
        review.review_answers = [
            reviewanswer1, reviewanswer2, reviewanswer3, reviewanswer4,
            reviewanswer5, reviewanswer6, reviewanswer7
        ]

        session.add(item)
        session.add(user)
        session.add(level)
        session.add(review_question)
        session.add_all([tag, item_tag, comment])
        # referenced ReviewAnswers are stored as well
        session.add(review)

        session.commit()

        event = event_creator.get_get_review_event(user_id, review_id)

        resp = get_review(event, None)

        status = resp["statusCode"]
        assert status == 200

        body = json.loads(resp["body"])
        assert body["id"] == review_id

        assert len(body["questions"]) == 7
        assert body["questions"][0]["answer_id"] != None
        assert body["questions"][0]["question_id"] != None
        assert body["questions"][0]["parent_question_id"] == None
        assert body["questions"][0]["max_children"] == None
        assert body["questions"][0]["content"] != None
        assert body["questions"][0]["info"] != None
        assert body["questions"][0]["hint"] != None
        assert body["questions"][0]["answer_value"] == 1
        assert len(body["questions"][0]["options"]) == 4
        assert body["questions"][0]["options"][0]["text"] != None
        assert body["questions"][0]["options"][0]["value"] == 0
        assert body["questions"][0]["options"][1]["tooltip"] != None

        assert 'tags' in body
        assert len(body['tags']) == 1
        assert body['tags'][0] == 'test'

        assert 'comment' in body
        assert body['comment'] == 'testcomment'