Beispiel #1
0
 def setUp(self):
     super().setUp()
     self.user = self.mock_user(save=True)
     db.session.add(self.user)
     db.session.commit()
     # Add 5 courses with 3 exams each with stats
     for course_n in range(5):
         course = Course("TEST%d" % course_n, "Test Course")
         db.session.add(course)
         db.session.commit()
         for exam_n in range(3):
             exam = Exam("V%d" % exam_n, course.id)
             db.session.add(exam)
             db.session.commit()
             question = Question(exam_id=exam.id,
                                 type=Question.BOOLEAN,
                                 text="Test Question",
                                 correct=True)
             db.session.add(question)
             db.session.commit()
             for stats_n in range(2):
                 stats = Stats(self.user, question,
                               random.choice([True, False]))
                 db.session.add(stats)
     db.session.commit()
Beispiel #2
0
    def test_reset_course(self):
        course = Course.query.all()[1]

        stats_query = Stats.course(self.user, course.code).with_entities(Stats.id).subquery()
        stats_count_all = Stats.query.filter_by(reset=False).count()
        stats_count = Stats.query.filter(Stats.id.in_(stats_query)).count()
        self.assertTrue(stats_count > 0)

        response = self.client.get('/reset/{course}/'.format(course=course.code))
        self.assert_redirects(response, url_for('quiz.course', course=course.code))

        stats_count_all_after = Stats.query.filter_by(reset=False).count()
        stats_count_after = Stats.query.filter(Stats.id.in_(stats_query)).count()
        self.assertTrue(stats_count_after == 0)
        self.assertEqual(stats_count_all_after, stats_count_all - stats_count)