示例#1
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)
示例#2
0
def test_student_init():
    student = Student("first", "last", datetime.datetime(2002, 1, 1), 1234)
    assert isinstance(student, Person)
    assert student._first_name == "first"
    assert student._last_name == "last"
    assert student._DOB == datetime.datetime(2002, 1, 1)
    assert student._student_number == 1234
    assert student._email == None
    assert student._email_k12 == "*****@*****.**"
示例#3
0
def test_classroom_warnings():
    assert Classroom.warnings == []

    some_class = Classroom("Math")

    # add 34 students to the class
    for i in range(34):
        some_student = Student("blah", "blah", datetime.datetime.now(), i)
        some_class.add_student(some_student)
    
    # should add a warning to the class variable 'warnings'
    warning_string = Classroom.warnings[0]
    assert warning_string == "Math has more than 33 students."
示例#4
0
from main import db, Student

db.create_all()

bob = Student("Bob", 90)
zaid= Student("Zaid", 84)
print(bob.id)
print(zaid.id)

db.session.add_all([zaid,bob])
db.session.commit()

print(zaid.id)
print(bob.id)
示例#5
0
import os

db.create_all()

# Data to initialize database with
Data = [{
    'name': 'Darren',
    'physics': 1,
    'maths': 1,
    'chemistry': 1
}, {
    'name': 'Kent',
    'physics': 1,
    'maths': 1,
    'chemistry': 1
}, {
    'name': 'Bunny',
    'physics': 1,
    'maths': 1,
    'chemistry': 1
}]

# Iterate over the PEOPLE structure and populate the database
for xData in Data:
    d = Student(name=xData['name'],
                physics=xData['physics'],
                maths=xData['maths'],
                chemistry=xData['chemistry'])
    db.session.add(d)

db.session.commit()
示例#6
0
def test_set_student_number_raises_error_with_invalid_value():
    student = Student("first", "last", datetime.datetime(2020, 1, 1), 1234)
    
    with pytest.raises(TypeError):
        student.set_student_number("abc123")
示例#7
0
def test_student_greet():
    student = Student("first", "last", datetime.datetime(2020, 1, 1), 1234)
    assert student.greet() == "Hello, my name is first last and I'm a student."

    student = Student("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    assert student.greet() == "Hello, my name is John Smith and I'm a student."
示例#8
0
def test_student_getters_setters():
    student = Student("first", "last", datetime.datetime(2020, 1, 1), 1234)
    
    student.set_first_name("John")
    assert student.get_first_name() == "John"

    student.set_last_name("Smith")
    assert student.get_last_name() == "Smith"

    student.set_student_number(4321)
    assert student.get_student_number() == 4321
示例#9
0
from main import db, Student

db.create_all()

sarita = Student('Sarita', 100)
vijaya = Student('Vijaya', 105)

print(vijaya.id)
print(sarita.id)

db.session.add_all([sarita, vijaya])

db.session.commit()

print(sarita.id)
print(vijaya.id)
示例#10
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)
示例#11
0
from main import db, Student

db.create_all()

nathan = Student('Nathan', 100)
sam = Student('Sam', 95)
tom = Student('Tom', 40)

print(sam.id)
print(nathan.id)
print(tom.id)

db.session.add_all([nathan, sam])

db.session.commit()

print(nathan.id)
print(sam.id)
print(tom.id)
示例#12
0
from main import db, Student

#CREATE
new_student = Student('John', 90)
db.session.add(new_student)
db.session.commit()

#READ
all_students = Student.query.all()
print(all_students)

first_student = Student.query.get(1)
print(first_student.name)

student_pass = Student.query.filter(Student.grade >= 85)
print(student_pass.all())

#UPDATE
first_student = Student.query.get(1)
first_student.grade = 105
db.session.add(first_student)
db.session.commit()

#DELETE
second_student = Student.query.get(2)
db.session.delete(second_student)
db.session.commit()

all_students = Student.query.all()
print(all_students)
示例#13
0
from main import Student, Facultet, Curator, db
import random

db.drop_database('my_home_db')

for i in range(10):
	Facultet.objects.create(name=f'Facultet №{i}')

for i in range(10):
	Curator.objects.create(name=f'Curator №{i}')

for i in range(100):
	Student.create_student(
			fullname=f'Sasha {i}',
			group= f'{i*10}',
			marks= [random.randint(1, 100) for i in range(10)],
			curator=Curator.objects.get(name=f'Curator №{random.randint(1, 9)}'),
			facultet=Facultet.objects.get(name=f'Facultet №{random.randint(1, 9)}')
		)
示例#14
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'}
示例#15
0
def test_generate_email():
    student = Student("first", "last", datetime.datetime(2020, 1, 1), 1234)
    assert student._email_k12 == "*****@*****.**"

    student = Student("John", "Smith", datetime.datetime(2020, 1, 1), 1234)
    assert student._email_k12 == "*****@*****.**"
示例#16
0
 def setup_method(self):
     self.teacher = Teacher('Dayo Osikoya', 'Form 2')
     self.student = Student('Aaron Buddy', classroom='Form 2')
示例#17
0
from main import db, Student

new_student = Student('Gaurav', 95)
db.session.add(new_student)
db.session.commit()

all_students = Student.query.all()
print(all_students)

first_student = Student.query.get(1)
print(first_student.name)

student_pass = Student.query.filter(Student.grade >= 85)
print(student_pass.all())

first_student = Student.query.get(1)
first_student.grade = 104
db.session.add(first_student)
db.session.commit()

second_student = Student.query.get(3)
db.session.delete(second_student)
db.session.commit()

all_students = Student.query.all()
print(all_students)