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() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') student = Student(user, 'U1722') db.session.add(student) # adding quizzes qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22') db.session.add(qz) # adding quizattempts qa = initializeQuizAttempt(2, 1, 100) db.session.add(qa) db.session.commit()
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() # adding users user_1 = User('*****@*****.**', encrypt('password'), 'student_1') student_1 = Student(user_1, 'U00000000A') db.session.add(student_1) user_2 = User('*****@*****.**', encrypt('password'), 'student_2') student_2 = Student(user_2, 'U00000000B') db.session.add(student_2) user_3 = User('*****@*****.**', encrypt('password'), 'teacher_1') staff_1 = Staff(user_3) db.session.add(staff_1) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(1, 1, 'lesson_1', 'content') db.session.add(lesson) # adding quizzes quiz = Quiz(3, 'quiz_1', True, '2020-03-30', '2020-03-31') db.session.add(quiz) db.session.commit()
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() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) # adding courses course = Course(index='cz3003') db.session.add(course) # adding quizzes quiz = Quiz( staff_id=1, name="Quiz Test", is_fast=True, date_start='2020-03-01', date_end='2020-03-31', ) db.session.add(quiz) db.session.commit()
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() # adding courses course = Course(index='cz3003') db.session.add(course) # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding quizzes qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22') db.session.add(qz) # adding RsQuizCourseAssign rs = initializeRsQuizCourseAssign(1, 'cz3003') db.session.add(rs) db.session.commit()
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() # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id=1, id=1, name='se', content='test') db.session.add(lesson) # adding users user = User('*****@*****.**', encrypt('password'), 'staff_name') staff = Staff(user) db.session.add(staff) # adding quizzes quiz = Quiz(1, 'quiz_name', True, '2020-03-21', '2020-03-22') db.session.add(quiz) db.session.commit()
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() # adding courses course = Course(index='cz3003') db.session.add(course) # adding users user = User( email='*****@*****.**', encrypted_password=encrypt('password'), name='std' ) std = Student(user,"U1722") db.session.add(std) # adding RsStudentCourseEnrol rs = initializeRsStudentCourseEnrol(1,'cz3003') db.session.add(rs) db.session.commit()
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() # adding users user = User( email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe' ) student = Student(user, 'U1722') db.session.add(student) # adding topics topic = Topic(name='seng') db.session.add(topic) # add lessons lesson = Lesson(topic_id='1', id='3', name='se', content='test') db.session.add(lesson) # add questions qn = Question('1', '3', 'easy') db.session.add(qn) # add questionChoice qc = initializeQuestionChoice(1,'A',False) db.session.add(qc) db.session.commit()
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() # adding users user = User( email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe' ) student = Student(user, 'U1722') db.session.add(student) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id=1, id=1, name='se', content='test') db.session.add(lesson) # adding questions qn_1 = Question(1, 1,'easy') db.session.add(qn_1) qn_2 = Question(1, 1,'medium') db.session.add(qn_2) db.session.commit()
def test_encryption(self): # check that authenticate function works, with encrypted string print( '--- check that authenticate function works, with encrypted string' ) plaintext_password = '******' encrypted_password = encrypt(plaintext_password) self.assertTrue(authenticate(plaintext_password, encrypted_password))
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() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') student = Student(user, 'U1722') db.session.add(student) user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id='1', id='3', name='se', content='test') db.session.add(lesson) # adding questions qn = Question('1', '3', 'easy') db.session.add(qn) # adding quizzes qz = Quiz(2, 'quiz', True, '2020-03-21', '2020-03-22' ) # staff id is 2 here, as it uses the fk of users table db.session.add(qz) # adding courses course = Course(index='cz3003') db.session.add(course) db.session.commit()
def test_userUpdate(self): # create a new User object and add it to the database user = User( email = '*****@*****.**', encrypted_password=encrypt('password'), name = 'john_doe' ) db.session.add(user) db.session.commit() # update value of User object password_original = user.encrypted_password user.encrypted_password = encrypt('password_new') userUpdate() # fetch updated User object from the database user = User.query.filter_by(email='*****@*****.**').first() # check if value of User object has been updated print('--- check if value of User object has been updated') self.assertTrue(authenticate('password_new', user.encrypted_password))
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() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) db.session.commit()
def test_userRead(self): # create a new User object and add it to the database user = User( email = '*****@*****.**', encrypted_password=encrypt('password'), name = 'john_doe' ) db.session.add(user) db.session.commit() # check that the record retrieved is correct (using col='email') print('--- check that the record retrieved is correct (using col=\'email\')') self.assertTrue(userRead(col='email', value='*****@*****.**')) # check that the record retrieved is correct (using col='id') print('--- check that the record retrieved is correct (using col=\'id\')') self.assertTrue(userRead(col='id', value=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() # addingusers user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) # adding courses course = Course(index='cz3003') db.session.add(course) # adding quizzes quiz = Quiz( staff_id=1, name="Quiz Test", is_fast=True, date_start='2020-03-01', date_end='2020-03-31', ) db.session.add(quiz) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id='1', id='3', name='se', content='test') db.session.add(lesson) # adding questions qn = Question('1', '3', 'easy') db.session.add(qn) db.session.commit()
def test_staffUpdate(self): # create a new Staff object and add it to the database user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') stf = Staff(user=user) db.session.add(stf) db.session.commit() # update value of Staff object stf.name = 'Justin' staffUpdate() # fetch updated Staff object from the database stf = Staff.query.filter_by(email='*****@*****.**').first() # check if value of Staff object has been updated print('--- check if value of Staff object has been updated') self.assertEqual('Justin', stf.name)
def test_staffRead(self): # create a new Staff object and add it to the database user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') stf = Staff(user=user) db.session.add(stf) db.session.commit() # check that the record retrieved is correct (using col='email') print( '--- check that the record retrieved is correct (using col=\'email\')' ) self.assertTrue(staffRead('email', '*****@*****.**')) # check that the record retrieved is correct (using col='id') print( '--- check that the record retrieved is correct (using col=\'id\')' ) self.assertTrue(staffRead('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() # adding courses course = Course(index='cz3003') db.session.add(course) # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding quizzes qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22') db.session.add(qz) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id=1, id=1, name='se', content='test') db.session.add(lesson) # adding questions qn = Question(1, 1, 'easy') db.session.add(qn) # adding RsQuizQuestionContain rs = initializeRsQuizQuestionContain(1, 1) db.session.add(rs) db.session.commit()
def test_userCreate(self): # create a new User object user = User( email = '*****@*****.**', encrypted_password=encrypt('password'), name = 'john_doe' ) # add User object to the database userCreate(user) # retrieve all records from the table 'users' user_list = User.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(user_list)) # check that the value(s) of the User object added is correct print('--- check that the value(s) of the User object added is correct') self.assertEqual(user_list[0].email, '*****@*****.**')
def test_staffCreate(self): # create a new Staff object user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') stf = Staff(user=user) # add Staff object to the database staffCreate(stf) # retrieve all records from the table 'staffs' stf_list = Staff.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(stf_list)) # check that the value(s) of the Staff object added is correct print( '--- check that the value(s) of the Staff object added is correct') self.assertEqual(stf_list[0].email, '*****@*****.**')
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() # adding courses course = Course(index='cz3003') db.session.add(course) # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding RsStaffCourseTeach rs = initializeRsStaffCourseTeach(1, 'cz3003') db.session.add(rs) db.session.commit()
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()