예제 #1
0
def test_teacher_assing_work():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    math = Classroom("Math")
    teacher.add_class(math)

    assert teacher.assign_work(
        math) == "John Smith assigns work to Math class."
예제 #2
0
def test_cant_assign_work_to_someone_elses_class():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    
    # raise an error if assigning work to a class not taught by the teacher
    someone_elses_class = Classroom("Computer Studies")
    with pytest.raises(Exception):
        teacher.assign_work(someone_elses_class)
예제 #3
0
def test_teacher_getters_setters():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    assert teacher.get_first_name() == "John"

    teacher.set_OCT_PIN(5432)
    assert teacher.get_OCT_PIN() == 5432

    teacher.set_school("St. Joan")
    assert teacher.get_school() == "St. Joan"
예제 #4
0
    def setup_method(self):
        self.student = Student('Aaron Buddy', 'Form 2')
        self.teacher = Teacher('Dayo Osikoya', 'Form 2')

        # Create quiz
        subject = 'Health Education'
        self.teacher.create_quiz(subject)
        self.teacher.add_question(subject, 'How are you?', {'A': 'Good', 'B': 'Not good'}, 'B')
        self.teacher.add_question(subject, 'Are you sure?', {'A': 'Yes', 'B': 'No'}, 'B')
        self.teacher.add_question(subject, 'Cold or fever?', {'A': 'Cold', 'B': 'Fever'}, 'B')

        # Assign quiz to student
        questions = self.teacher.get_questions(subject)
        student_with_quiz = self.teacher.assign_quiz(self.student, subject, questions)
예제 #5
0
def test_teacher_cannot_have_more_than_6_classes():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)

    # OK to have 6
    for i in range(6):
        some_class = Classroom(str(i))
        teacher.add_class(some_class)
    
    # Error when trying to add a 7th class
    with pytest.raises(Exception):
        one_too_many = Classroom("Cant teach this")
        teacher.add_class(one_too_many)
    
    assert len(teacher.get_classes()) == 6
예제 #6
0
 def setup_method(self):
     self.teacher = Teacher('Dayo Osikoya', 'Form 2')
     self.student = Student('Aaron Buddy', classroom='Form 2')
예제 #7
0
class TestTeacher:
    def setup_method(self):
        self.teacher = Teacher('Dayo Osikoya', 'Form 2')
        self.student = Student('Aaron Buddy', classroom='Form 2')

    def create_quiz(self, subject):
        self.teacher.create_quiz(subject)

    def create_quiz_with_questions(self, subject):
        subject = 'Health Education'
        self.create_quiz(subject)
        self.add_question(subject, 'How are you?', {'A': 'Good', 'B': 'Not good'}, 'B')
        self.add_question(subject, 'Cold or Fever?', {'A': 'Cold', 'B': 'Fever'}, 'B')
        return self.add_question(subject, 'Are you sure?', {'A': 'Yes', 'B': 'No'}, 'B')

    def add_question(self, subject, question, options, answer):
        return self.teacher.add_question(subject, question, options, answer)

    def test_teacher_details(self):
        assert self.teacher.name == 'Dayo Osikoya'
        assert self.teacher.classroom == 'Form 2'

    def test_create_quiz(self):
        self.create_quiz('Science')
        assert self.teacher.quizzes == {
            'Science': {
                'questions': {},
                'answers': {}
            }
        }

    def test_create_another_quiz(self):
        self.create_quiz('Science')
        self.create_quiz('Health Education')
        assert self.teacher.quizzes == {
            'Science': {
                'questions': {},
                'answers': {}
            },
            'Health Education': {
                'questions': {},
                'answers': {}
            }
        }

    def test_add_question_to_first_quiz(self):
        self.create_quiz('Science')
        quiz = self.add_question('Science', 'Day or night?', {'A': 'Day', 'B': 'Night'}, 'A')
        assert quiz == {
            'answers': {'1': 'A'},
            'questions': {
                '1': {'question': 'Day or night?', 'options': {'A': 'Day', 'B': 'Night'}}
            }
            
        }

    def test_add_question_to_second_quiz(self):
        subject = 'Health Education'
        quiz = self.create_quiz_with_questions(subject)
        assert quiz == {
            'answers': {'1': 'B', '3': 'B', '2': 'B'},
            'questions': {
                '1': {
                    'question': 'How are you?',
                    'options': {'A': 'Good', 'B': 'Not good'}
                },
                '3': {
                    'question': 'Are you sure?',
                    'options': {'A': 'Yes', 'B': 'No'}
                },
                '2': {
                    'question': 'Cold or Fever?',
                    'options': {'A': 'Cold', 'B': 'Fever'}
                }
            }
        }

    def test_add_another_question_to_second_quiz(self):
        subject = 'Health Education'
        self.create_quiz_with_questions(subject)
        quiz = self.add_question(
            subject, 'Are you sure?', {'A': 'Yes', 'B': 'No'}, 'B')
        assert quiz == {
            'answers': {'1': 'B', '3': 'B', '2': 'B', '4': 'B'},
            'questions': {
                '1': {
                    'question': 'How are you?',
                    'options': {'A': 'Good', 'B': 'Not good'}
                },
                '3': {
                    'question': 'Are you sure?',
                    'options': {'A': 'Yes', 'B': 'No'}
                },
                '2': {
                    'question': 'Cold or Fever?',
                    'options': {'A': 'Cold', 'B': 'Fever'}
                },
                '4': {
                    'question': 'Are you sure?',
                    'options': {'A': 'Yes', 'B': 'No'}
                }
            }
        }

    def test_get_questions(self):
        subject = 'Health Education'
        self.create_quiz_with_questions(subject)
        assert self.teacher.get_questions('Health Education') == {
            '1': {
                'question': 'How are you?',
                'options': {'A': 'Good', 'B': 'Not good'}
            },
            '3': {
                'question': 'Are you sure?',
                'options': {'A': 'Yes', 'B': 'No'}
            },
            '2': {
                'question': 'Cold or Fever?',
                'options': {'A': 'Cold', 'B': 'Fever'}
            }
        }

    def test_assign_quiz_without_questions(self):
        subject = 'Science'
        self.create_quiz(subject)

        with pytest.raises(InvalidAction) as excinfo:
            questions = self.teacher.get_questions(subject)
            self.teacher.assign_quiz(self.student, subject, questions)
        assert 'Please add questions before assigning quiz.' in str(excinfo.value)

    def test_assign_quiz(self):
        subject = 'Health Education'
        self.create_quiz_with_questions(subject)

        questions = self.teacher.get_questions(subject)
        self.teacher.assign_quiz(self.student, subject, questions)
        assert self.student.quiz == {
            'name': 'Aaron Buddy',
            'questions': {
                '1': {
                    'question': 'How are you?',
                    'options': {'A': 'Good', 'B': 'Not good'}
                },
                '3': {
                    'question': 'Are you sure?',
                    'options': {'A': 'Yes', 'B': 'No'}
                },
                '2': {
                    'question': 'Cold or Fever?',
                    'options': {'A': 'Cold', 'B': 'Fever'}
                }
            },
            'subject': 'Health Education'
        }

    def test_grade_incomplete_quiz(self):
        # Create quiz
        subject = 'Health Education'
        self.create_quiz_with_questions(subject)

        # Assign quiz
        questions = self.teacher.get_questions(subject)
        self.teacher.assign_quiz(self.student, subject, questions)

        # Solve quiz
        self.student.solve_question(1, 'A')
        quiz = self.student.solve_question(2, 'A')

        with pytest.raises(InvalidAction) as excinfo:
            self.teacher.grade_quiz(quiz)
        assert 'You cannot grade an incomplete quiz.' in str(excinfo.value)

    def test_grade_quiz(self):
        # Create quiz
        subject = 'Health Education'
        self.create_quiz_with_questions(subject)

        # Assign quiz
        questions = self.teacher.get_questions(subject)
        self.teacher.assign_quiz(self.student, subject, questions)

        # Solve quiz
        self.student.solve_question(1, 'B')
        self.student.solve_question(2, 'A')
        quiz = self.student.solve_question(3, 'B')

        # Submit quiz
        completed_quiz = self.student.submit_quiz(quiz)

        #Grade quiz
        assert self.teacher.grade_quiz(completed_quiz) == {'Aaron Buddy': '66.67'}
예제 #8
0
def test_teacher_greet():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    assert teacher.greet() == "Hello, my name is John Smith and I'm a teacher."
예제 #9
0
def test_teacher_add_remove_class():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    some_class = Classroom("Math")
    teacher.add_class(some_class)

    assert some_class in teacher.get_classes()

    teacher.remove_class(some_class)
    assert teacher.get_classes() == []

    # ensure you cannot teach the same class twice
    teacher.add_class(some_class)
    with pytest.raises(Exception):
        teacher.add_class(some_class)
예제 #10
0
def test_teacher_init():
    teacher = Teacher("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    assert isinstance(teacher, Person)
    assert teacher._OCT_PIN == 1234
    assert teacher._email_k12 == "*****@*****.**"
    assert teacher._classes == []
예제 #11
0
class TestStudent:
    def setup_method(self):
        self.student = Student('Aaron Buddy', 'Form 2')
        self.teacher = Teacher('Dayo Osikoya', 'Form 2')

        # Create quiz
        subject = 'Health Education'
        self.teacher.create_quiz(subject)
        self.teacher.add_question(subject, 'How are you?', {'A': 'Good', 'B': 'Not good'}, 'B')
        self.teacher.add_question(subject, 'Are you sure?', {'A': 'Yes', 'B': 'No'}, 'B')
        self.teacher.add_question(subject, 'Cold or fever?', {'A': 'Cold', 'B': 'Fever'}, 'B')

        # Assign quiz to student
        questions = self.teacher.get_questions(subject)
        student_with_quiz = self.teacher.assign_quiz(self.student, subject, questions)

    def test_student_details(self):
        assert self.student.name == 'Aaron Buddy'
        assert self.student.classroom == 'Form 2'

    def test_solve_question_answer_does_not_exist(self):
        with pytest.raises(InvalidAction) as excinfo:
            quiz = self.student.solve_question(1, 'C')
        assert 'Answer provided is not in options.' in str(excinfo.value)

    def test_solve_question(self):
        quiz = self.student.solve_question(1, 'A')
        assert quiz == {
            'name': 'Aaron Buddy',
            'answers': {'1': 'A'},
            'questions': {
                '1': {
                    'question': 'How are you?',
                    'options': {'A': 'Good', 'B': 'Not good'}
                },
                '3': {
                    'question': 'Cold or fever?',
                    'options': {'A': 'Cold', 'B': 'Fever'}
                },
                '2': {
                    'question': 'Are you sure?',
                    'options': {'A': 'Yes', 'B': 'No'}
                }
            },
            'subject': 'Health Education'
        }

    def test_submit_quiz(self):
        self.student.solve_question(1, 'A')
        self.student.solve_question(2, 'A')
        quiz = self.student.solve_question(3, 'A')

        completed_quiz = self.student.submit_quiz(quiz)
        assert completed_quiz == {
            'answers': {'1': 'A', '3': 'A', '2': 'A'},
            'completed': True,
            'name': 'Aaron Buddy',
            'questions': {
                '1': {
                    'question': 'How are you?', 'options': {'A': 'Good', 'B': 'Not good'}
                },
                '3': {
                    'question': 'Cold or fever?', 'options': {'A': 'Cold', 'B': 'Fever'}
                },
                '2': {
                    'question': 'Are you sure?', 'options': {'A': 'Yes', 'B': 'No'}
                }
            },
            'subject': 'Health Education'
        }

    def test_submit_incomplete_quiz(self):
        quiz = self.student.solve_question(1, 'A')
        with pytest.raises(InvalidAction) as excinfo:
            self.student.submit_quiz(quiz)
        assert 'You can only submit quiz after answering all questions.' in str(excinfo.value)