def test_quizAttemptListRead(self): # create a new QuizAttempt object and add it to the database qzAttempt = QuizAttempt(student_id=1, quiz_id=1, score=100) db.session.add(qzAttempt) db.session.commit() # check that the number of record retrieved is correct print('--- check that the number of record retrieved is correct') self.assertEqual(1, len(quizAttemptListRead(student_id='1', quiz_id='1'))) # check that the record retrieved is correct print('--- check that the record retrieved is correct') self.assertEqual( quizAttemptListRead(student_id='1', quiz_id='1')[0].quiz_id, 1)
def test_quizAttemptCreate(self): # create a new QuizAttempt object qzAttempt = QuizAttempt(student_id=1, quiz_id=1, score=100) # add QuizAttempt object to the database quizAttemptCreate(qzAttempt) # retrieve all records from the table 'quizattempts' qzAttempt_list = QuizAttempt.query.all() # check that the number of record added is correct print('--- check that the number of record added is correct') self.assertEqual(1, len(qzAttempt_list)) # check that the value(s) of the QuizAttempt object added is correct print( '--- check that the value(s) of the QuizAttempt object added is correct' ) self.assertEqual(qzAttempt_list[0].student_id, 1)
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() self.maxDiff = None # adding students user_1 = User('*****@*****.**', encrypt('password'), 'student_1') student_1 = Student(user_1, 'U00000000A') db.session.add(student_1) user_2 = User('student_2gmail.com', encrypt('password'), 'student_2') student_2 = Student(user_2, 'U00000000B') db.session.add(student_2) # adding staff user_3 = User('*****@*****.**', encrypt('password'), 'staff_1') staff_1 = Staff(user_3) db.session.add(staff_1) # adding topics topic_1 = Topic(name='topic_1') db.session.add(topic_1) topic_2 = Topic(name='topic_2') db.session.add(topic_2) # adding lessons lesson_1 = Lesson(topic_id=1, id=1, name='lesson_1', content='content') db.session.add(lesson_1) lesson_2 = Lesson(topic_id=1, id=2, name='lesson_2', content='content') db.session.add(lesson_2) lesson_3 = Lesson(topic_id=1, id=3, name='lesson_3', content='content') db.session.add(lesson_3) lesson_4 = Lesson(topic_id=2, id=1, name='lesson_4', content='content') db.session.add(lesson_4) # adding quizzes quiz_1 = Quiz(3, 'quiz_1', True, '2020-03-30', '2020-03-31') db.session.add(quiz_1) quiz_2 = Quiz(3, 'quiz_2', True, '2020-03-30', '2020-03-31') db.session.add(quiz_2) quiz_3 = Quiz(3, 'quiz_3', True, '2020-03-30', '2020-03-31') db.session.add(quiz_3) # adding questions question_1 = Question(1, 1, 'description') db.session.add(question_1) question_2 = Question(1, 1, 'description') db.session.add(question_2) question_3 = Question(1, 3, 'description') db.session.add(question_3) question_4 = Question(1, 3, 'description') db.session.add(question_4) question_5 = Question(1, 3, 'description') db.session.add(question_5) # assign questions to quiz rs_1 = Rs_quiz_question_contain(1, 1) db.session.add(rs_1) rs_2 = Rs_quiz_question_contain(3, 3) db.session.add(rs_2) rs_3 = Rs_quiz_question_contain(3, 4) db.session.add(rs_3) rs_4 = Rs_quiz_question_contain(3, 5) db.session.add(rs_4) # adding quiz attempts quiz_attempt_1 = QuizAttempt(1, 1, 0) db.session.add(quiz_attempt_1) quiz_attempt_2 = QuizAttempt(2, 3, 2) db.session.add(quiz_attempt_2) quiz_attempt_3 = QuizAttempt(1, 3, 3) db.session.add(quiz_attempt_3) # adding quizzes to lessons rs_lesson_quiz_contain_1 = Rs_lesson_quiz_contain(1, 1, 1) db.session.add(rs_lesson_quiz_contain_1) rs_lesson_quiz_contain_2 = Rs_lesson_quiz_contain(1, 1, 2) db.session.add(rs_lesson_quiz_contain_2) rs_lesson_quiz_contain_3 = Rs_lesson_quiz_contain(1, 3, 3) db.session.add(rs_lesson_quiz_contain_3) # adding courses course = Course('cz1005') db.session.add(course) # enrol students into courses enrol_1 = Rs_student_course_enrol(1, 'cz1005') db.session.add(enrol_1) enrol_2 = Rs_student_course_enrol(2, 'cz1005') db.session.add(enrol_2) # adding quizzes to courses Rs_quiz_course_assign_1 = Rs_quiz_course_assign(1, 'cz1005') db.session.add(Rs_quiz_course_assign_1) Rs_quiz_course_assign_2 = Rs_quiz_course_assign(2, 'cz1005') db.session.add(Rs_quiz_course_assign_2) Rs_quiz_course_assign_3 = Rs_quiz_course_assign(3, 'cz1005') db.session.add(Rs_quiz_course_assign_3) db.session.commit()
def initializeQuizAttempt(student_id, quiz_id, score): return QuizAttempt( student_id = student_id, quiz_id = quiz_id, score = int(score) )