def test_add_student(self): s = School(name="Test") u = User(username="******") u.role = Role.get('Teacher') with self.assertRaises(ValidationError): s.add_student(u) u.role = Role.get('Student') s.add_student(u) db.session.add(s) db.session.commit() self.assertEquals([u], s.students.all())
def test_students_only_returns_students(self): s = School(name="Test") u1 = User(username="******", email='*****@*****.**') u2 = User(username="******", email='*****@*****.**') u3 = User(username="******", email='*****@*****.**') u3.role = Role.get('Teacher') u4 = User(username="******", email='*****@*****.**') u4.role = Role.get('Teacher') s.add_student(u1) s.add_student(u2) s.add_teacher(u3) s.add_teacher(u4) db.session.add(s) db.session.commit() self.assertListEqual([u1, u2], s.students.all())