def handle(self, *args, **options): """Automatically called when the backdate command is given.""" print("Backdating points and achievements\n") ignore_flags = options['ignore_flags'] number = int(options['profiles']) if ignore_flags and number > 0: raise ValueError("If ignoring backdate flags you must backdate all profiles.") backdate_points_and_achievements(number, ignore_flags)
def test_backdate_points_and_achievements_achievement_earnt_no_longer_meets_requirements(self): user = User.objects.get(id=2) achievement = Achievement.objects.get(id_name='attempts-made-5') Earned.objects.create(profile=user.profile, achievement=achievement) backdate_points_and_achievements() self.assertTrue( User.objects.get(id=2).profile.earned_achievements.filter(id_name='attempts-made-5').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_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)