Example #1
0
def test_results__none_answered_correct_first_and_second(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student
    n = len(questions)
    n_first = random.randint(1, n - 1)
    n_second = random.randint(1, n_first)

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 2,
        "rationale": "test",
        "second_answer_choice": 2,
        "chosen_rationale": None,
    } for i, question in enumerate(questions[:n_second])] +
                [{
                    "question": question,
                    "assignment": assignment,
                    "user_token": student.student.username,
                    "first_answer_choice": 2,
                    "rationale": "test",
                } for i, question in enumerate(questions[n_second:n_first])])
    correct = {
        "n_completed": n_second,
        "n_first_correct": 0,
        "n_correct": 0,
        "n": n,
        "grade": 0,
    }

    result = student_assignment.results
    assert result == correct
Example #2
0
def test_student_progress__all_first_answers_done(questions,
                                                  students_with_assignment,
                                                  student_group_assignment):
    n_correct = {
        q.pk: random.randint(0, len(students_with_assignment))
        for q in questions
    }
    add_answers([{
        "question": question,
        "assignment": student_group_assignment.assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1 + (i >= n_correct[question.pk]),
        "rationale": "test",
    } for question in questions
                 for i, student in enumerate(students_with_assignment)])

    progress = student_group_assignment.student_progress

    assert not set(map(itemgetter("question_title"), progress)) - set(
        (q.title for q in questions))
    assert not set((q.title for q in questions)) - set(
        map(itemgetter("question_title"), progress))

    for question in progress:
        question_ = next(q for q in questions
                         if q.title == question["question_title"])
        assert question["n_students"] == len(students_with_assignment)
        assert question["n_completed"] == 0
        assert question["n_first_correct"] == n_correct[question_.pk]
        assert question["n_correct"] == 0
Example #3
0
def test_completed__all_first_and_some_second_answers(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student
    n = len(questions)
    n_second = random.randint(1, n - 1)

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
        "second_answer_choice": 1,
        "chosen_rationale": None,
    } for i, question in enumerate(questions[:n_second])] +
                [{
                    "question": question,
                    "assignment": assignment,
                    "user_token": student.student.username,
                    "first_answer_choice": 1,
                    "rationale": "test",
                } for i, question in enumerate(questions[n_second:])])

    assert not student_assignment.completed
Example #4
0
def test_results__all_answered_correct(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student
    n = len(questions)

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
        "second_answer_choice": 1,
        "chosen_rationale": None,
    } for question in questions])

    correct = {
        "n_completed": n,
        "n_first_correct": n,
        "n_correct": n,
        "n": n,
        "grade": n,
    }

    result = student_assignment.results
    assert result == correct
Example #5
0
def test_send_reminder__completed(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
        "second_answer_choice": 1,
        "chosen_rationale": None,
    } for i, question in enumerate(questions)])

    assert not student_assignment.reminder_sent
    assert student_assignment.completed
    assert not StudentNotification.objects.filter(
        student=student_assignment.student,
        notification__type="assignment_about_to_expire",
    ).exists()

    student_assignment.send_reminder(last_day=False)

    assert not StudentNotification.objects.filter(
        student=student_assignment.student,
        notification__type="assignment_about_to_expire",
    ).exists()
    assert not student_assignment.reminder_sent
    assert not mail.outbox
def test_get_current_question__some_second_answers_done(student_assignment):
    student = student_assignment.student
    questions = student_assignment.group_assignment.questions
    n_second = random.randrange(1, len(questions))
    add_answers(
        [
            {
                "question": question,
                "assignment": student_assignment.group_assignment.assignment,
                "user_token": student.student.username,
                "first_answer_choice": 1,
                "rationale": "test",
            }
            for question in questions[n_second:]
        ]
    )
    add_answers(
        [
            {
                "question": question,
                "assignment": student_assignment.group_assignment.assignment,
                "user_token": student.student.username,
                "first_answer_choice": 1,
                "rationale": "test",
                "second_answer_choice": 1,
                "chosen_rationale": None,
            }
            for question in questions[:n_second]
        ]
    )

    question = student_assignment.get_current_question()
    assert question == questions[n_second]
def test_completed__multiple_same_assignment(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
        "second_answer_choice": 1,
        "chosen_rationale": None,
    } for i, question in enumerate(questions)])

    assert student_assignment.completed

    assignment_clone = Assignment.objects.create(identifier="__test__",
                                                 title=assignment.title)
    for question in questions:
        assignment_clone.questions.add(question)

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
    } for i, question in enumerate(questions)])

    assert not student_assignment.completed
Example #8
0
def test_get_current_question__all_first_answers_done(student_assignment):
    student = student_assignment.student
    questions = student_assignment.group_assignment.questions
    add_answers([{
        "question": question,
        "assignment": student_assignment.group_assignment.assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
    } for question in questions])

    question = student_assignment.get_current_question()
    assert question == questions[0]
Example #9
0
def test_completed__all_first_and_second_answers(student_assignment):
    assignment = student_assignment.group_assignment.assignment
    questions = assignment.questions.all()
    student = student_assignment.student

    add_answers([{
        "question": question,
        "assignment": assignment,
        "user_token": student.student.username,
        "first_answer_choice": 1,
        "rationale": "test",
        "second_answer_choice": 1,
        "chosen_rationale": None,
    } for i, question in enumerate(questions)])

    assert student_assignment.completed
Example #10
0
def test_student_progress__all_answers_correct_all_second_answers_done(
    questions_all_answers_correct,
    students_with_assignment_all_answers_correct,
    student_group_assignment_all_answers_correct,
):
    n_first_correct = {
        q.pk: random.randint(0,
                             len(students_with_assignment_all_answers_correct))
        for q in questions_all_answers_correct
    }
    n_second_correct = {
        q.pk: random.randint(0,
                             len(students_with_assignment_all_answers_correct))
        for q in questions_all_answers_correct
    }
    add_answers([
        {
            "question": question,
            "assignment":
            student_group_assignment_all_answers_correct.assignment,  # noqa
            "user_token": student.student.username,
            "first_answer_choice": 1 + (i >= n_first_correct[question.pk]),
            "rationale": "test",
            "second_answer_choice": 1 + (i >= n_second_correct[question.pk]),
            "chosen_rationale": None,
        } for question in questions_all_answers_correct for i, student in
        enumerate(students_with_assignment_all_answers_correct)
    ])

    progress = student_group_assignment_all_answers_correct.student_progress

    assert not set(map(itemgetter("question_title"), progress)) - set(
        (q.title for q in questions_all_answers_correct))
    assert not set((q.title for q in questions_all_answers_correct)) - set(
        map(itemgetter("question_title"), progress))

    for question in progress:
        assert question["n_students"] == len(
            students_with_assignment_all_answers_correct)
        assert question["n_completed"] == len(
            students_with_assignment_all_answers_correct)
        assert question["n_first_correct"] == len(
            students_with_assignment_all_answers_correct)
        assert question["n_correct"] == len(
            students_with_assignment_all_answers_correct)
Example #11
0
def test_student_progress__all_answers_correct_some_second_answers_done(
    questions_all_answers_correct,
    students_with_assignment_all_answers_correct,
    student_group_assignment_all_answers_correct,
):
    times_first_answered = {
        q.pk:
        random.randrange(2, len(students_with_assignment_all_answers_correct))
        for q in questions_all_answers_correct
    }
    n_first_correct = {
        q.pk: random.randint(0, times_first_answered[q.pk])
        for q in questions_all_answers_correct
    }
    times_second_answered = {
        q.pk: random.randrange(1, times_first_answered[q.pk])
        for q in questions_all_answers_correct
    }
    n_second_correct = {
        q.pk: random.randint(0, times_second_answered[q.pk])
        for q in questions_all_answers_correct
    }
    answers = add_answers([
        {
            "question":
            question,
            "assignment":
            student_group_assignment_all_answers_correct.assignment,  # noqa
            "user_token":
            student.student.username,
            "first_answer_choice":
            1 + (i + times_second_answered[question.pk] >=
                 n_first_correct[question.pk]),
            "rationale":
            "test",
        } for question in questions_all_answers_correct
        for i, student in enumerate(
            students_with_assignment_all_answers_correct[times_second_answered[
                question.pk]:times_first_answered[question.pk]])
    ])
    answers += add_answers([
        {
            "question":
            question,
            "assignment":
            student_group_assignment_all_answers_correct.assignment,  # noqa
            "user_token":
            student.student.username,
            "first_answer_choice":
            1 + (i >= n_first_correct[question.pk]),
            "rationale":
            "test",
            "second_answer_choice":
            1 + (i >= n_second_correct[question.pk]),
            "chosen_rationale":
            random.choice([a for a in answers if a.question == question]),
        } for question in questions_all_answers_correct
        for i, student in enumerate(
            students_with_assignment_all_answers_correct[:times_second_answered[
                question.pk]])
    ])

    progress = student_group_assignment_all_answers_correct.student_progress

    assert not set(map(itemgetter("question_title"), progress)) - set(
        (q.title for q in questions_all_answers_correct))
    assert not set((q.title for q in questions_all_answers_correct)) - set(
        map(itemgetter("question_title"), progress))

    for question in progress:
        question_ = next(q for q in questions_all_answers_correct
                         if q.title == question["question_title"])
        assert question["n_students"] == len(
            students_with_assignment_all_answers_correct)
        assert question["n_completed"] == times_second_answered[question_.pk]
        assert (
            question["n_first_correct"] == times_first_answered[question_.pk])
        assert question["n_correct"] == times_second_answered[question_.pk]