Esempio n. 1
0
 def setUpTestData(cls):
     # never modify this object in tests
     generate_users(user)
     generate_questions()
     generate_achievements()
     generate_attempts()
     generate_test_cases()
Esempio n. 2
0
 def setUpTestData(cls):
     # never modify this object in tests - read only
     generate_users(user)
     generate_questions()
     generate_attempts()
     generate_groups()
     generate_memberships()
     generate_likes()
Esempio n. 3
0
 def test_check_achievement_conditions(self):
     generate_attempts()
     user = User.objects.get(id=1)
     self.assertEqual(user.profile.earned_achievements.count(), 0)
     check_achievement_conditions(user.profile)
     earned_achievements = user.profile.earned_achievements
     self.assertTrue(earned_achievements.filter(id_name='create-account').exists())
     self.assertTrue(earned_achievements.filter(id_name='attempts-made-1').exists())
     self.assertTrue(earned_achievements.filter(id_name='attempts-made-5').exists())
     self.assertTrue(earned_achievements.filter(id_name='questions-solved-1').exists())
     self.assertTrue(earned_achievements.filter(id_name='consecutive-days-2').exists())
Esempio n. 4
0
 def test_check_achievement_conditions_questions_solved_does_not_exist(self):
     Achievement.objects.filter(id_name__contains="questions-solved").delete()
     generate_attempts()
     user = User.objects.get(id=1)
     check_achievement_conditions(user.profile)
     earned_achievements = user.profile.earned_achievements
     self.assertTrue(earned_achievements.filter(id_name='create-account').exists())
     self.assertTrue(earned_achievements.filter(id_name='attempts-made-1').exists())
     self.assertTrue(earned_achievements.filter(id_name='attempts-made-5').exists())
     self.assertTrue(earned_achievements.filter(id_name='consecutive-days-2').exists())
     # All questions-solved badges have been deleted and should not exist
     self.assertFalse(earned_achievements.filter(id_name='questions-solved-1').exists())
Esempio n. 5
0
 def test_backdate_points_and_achievements_run_twice(self):
     generate_attempts()
     user = User.objects.get(id=1)
     user.profile.points = 1000
     backdate_points_and_achievements()
     backdate_points_and_achievements()
     self.assertEqual(User.objects.get(id=1).profile.points, 60)
     earned_achievements = User.objects.get(id=1).profile.earned_achievements
     self.assertEqual(len(earned_achievements.filter(id_name='create-account')), 1)
     self.assertEqual(len(earned_achievements.filter(id_name='attempts-made-1')), 1)
     self.assertEqual(len(earned_achievements.filter(id_name='attempts-made-5')), 1)
     self.assertEqual(len(earned_achievements.filter(id_name='questions-solved-1')), 1)
     self.assertEqual(len(earned_achievements.filter(id_name='consecutive-days-2')), 1)
Esempio n. 6
0
    def test_check_achievement_conditions_question_already_solved(self):
        generate_attempts()
        user = User.objects.get(id=1)
        self.assertEqual(user.profile.earned_achievements.count(), 0)
        check_achievement_conditions(user.profile)
        self.assertEqual(user.profile.earned_achievements.count(), 5)
        question = Question.objects.get(slug='program-question-1')

        # generate two more correct attempts for the SAME question
        # this would put the total number of correct submissions at 5
        # but since it's for the SAME question, it does not contribute to the questions solved achievement
        Attempt.objects.create(profile=user.profile, question=question, passed_tests=True)
        Attempt.objects.create(profile=user.profile, question=question, passed_tests=True)
        check_achievement_conditions(user.profile)
        earned_achievements = user.profile.earned_achievements
        self.assertFalse(earned_achievements.filter(id_name='questions-solved-5').exists())
Esempio n. 7
0
 def test_backdate_points_and_achievements_too_many_points(self):
     generate_attempts()
     user = User.objects.get(id=1)
     user.profile.points = 1000
     backdate_points_and_achievements()
     self.assertEqual(User.objects.get(id=1).profile.points, 60)
Esempio n. 8
0
 def test_get_questions_answered_in_past_month(self):
     generate_attempts()
     user = User.objects.get(id=1)
     num_solved = get_questions_answered_in_past_month(user.profile)
     self.assertEqual(num_solved, 1)
Esempio n. 9
0
 def test_get_days_consecutively_answered(self):
     generate_attempts()
     user = User.objects.get(id=1)
     streak = get_days_consecutively_answered(user.profile)
     self.assertEqual(streak, 2)
Esempio n. 10
0
 def setUpTestData(cls):
     # never modify this object in tests
     generate_users(user)
     generate_questions()
     generate_attempts()
     generate_likes()
Esempio n. 11
0
 def test_attempted_questions(self):
     user = User.objects.get(id=1)
     generate_attempts()
     attempted_questions = Attempt.objects.filter(profile=user.profile)
     # generate_attempts in codewof_utils will generate 5 attempts for user 1
     self.assertEqual(len(attempted_questions), 5)
Esempio n. 12
0
 def setUpTestData(cls):
     generate_users(user)
     generate_questions()
     generate_achievements()
     generate_attempts()