def test_teacher_compute_total(self): """Tests if a teacher can compute the total for a student""" teacher = Teacher() questions = { '1 + 1?': { '1': False, '2': True, '3': False }, 'name?': { 'my name': True, 'your name': True, 'no name': False } } teacher.add_class('math') teacher.add_class('science') teacher.create_quiz('math', 'quiz1', questions) teacher.create_quiz('science', 'quiz1', questions) student = Student('Sam') student.add_class('math') student.add_class('science') teacher.assign_quiz(student, 'math', 'quiz1') student.submit_answer('math', 'quiz1', '1 + 1?', '1') student.submit_answer('math', 'quiz1', 'name?', ['my name', 'your name']) teacher.assign_quiz(student, 'science', 'quiz1') student.submit_answer('science', 'quiz1', '1 + 1?', '1') student.submit_answer('science', 'quiz1', 'name?', ['my name', 'your name']) teacher.grade(student, student.get_quiz('math', 'quiz1')) assert teacher.total(student.get_name(), 'math') == 50
def test_student_answer_quiz(self): """Test that a student can answer a quiz""" teacher = Teacher() questions = { '1 + 1?': { '1': False, '2': True, '3': False }, 'name?': { 'my name': True, 'your name': True, 'no name': False } } teacher.add_class('math') teacher.create_quiz('math', 'quiz1', questions) student = Student() student.add_class('math') teacher.assign_quiz(student, 'math', 'quiz1') assert (student.submit_answer('math', 'quiz1', '1 + 1?', '1') and student.submit_answer('math', 'quiz1', 'name?', ['my name', 'your name']) and student.quizzes['math_quiz1']['response'] == { '1 + 1?': '1', 'name?': ['my name', 'your name'] })
def test_teacher_grade_quiz(self): """Tests if a teacher quiz can be graded""" teacher = Teacher() questions = { '1 + 1?': { '1': False, '2': True, '3': False }, 'name?': { 'my name': True, 'your name': True, 'no name': False } } teacher.add_class('math') teacher.create_quiz('math', 'quiz1', questions) student = Student() student.add_class('math') teacher.assign_quiz(student, 'math', 'quiz1') student.submit_answer('math', 'quiz1', '1 + 1?', '1') student.submit_answer('math', 'quiz1', 'name?', ['my name', 'your name']) assert teacher.grade(student, student.get_quiz('math', 'quiz1'))
def test_not_teacher_assign_quiz(self): """Tests if a teacher can't assign a uuiz to a student that is not in his class""" teacher = Teacher() questions = { '1 + 1?': { '1': False, '2': True, '3': False }, 'name?': { 'my name': True, 'your name': True, 'no name': False } } teacher.add_class('math') teacher.create_quiz('math', 'quiz1', questions) student = Student() assert not teacher.assign_quiz(student, 'math', 'quiz1')