def setUpTestData(cls): # never modify this object in tests generate_users(user) generate_questions() generate_achievements() generate_attempts() generate_test_cases()
def setUpTestData(cls): # never modify this object in tests - read only generate_users(user) generate_questions() generate_attempts() generate_groups() generate_memberships() generate_likes()
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())
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())
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)
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())
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)
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)
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)
def setUpTestData(cls): # never modify this object in tests generate_users(user) generate_questions() generate_attempts() generate_likes()
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)
def setUpTestData(cls): generate_users(user) generate_questions() generate_achievements() generate_attempts()