Пример #1
0
 def test_signal_update_achievement(self):
     """Test for check signals"""
     client = Client()
     user_michu = create_user('passwordmichu', 'michu')
     create_user('passwordimmobile', 'immobile')
     client.login(username='******', password='******')
     coll = create_collection('Coleccion de cartas')
     ach_podium = PodiumAchievementDefinition(name='Presidente del podio', description='Consigue ser el primero',
                                              num_problems=1, position=1)
     ach_collection = NumSolvedCollectionAchievementDefinition(name='Coleccionista', description='Resuelve 50\
                                                               problemas de esta coleccion', num_problems=50,
                                                               collection=coll)
     ach_solved = NumSolvedAchievementDefinition(name='Resolvista', description='Resuelve 50 problemas',
                                                 num_problems=50)
     ach_podium.save()
     ach_solved.save()
     ach_collection.save()
     problem = create_select_problem(coll, 'Problema')
     submit_select_url = reverse('judge:submit', args=[problem.pk])
     client.post(submit_select_url, {'code': problem.solution}, follow=True)
     client.logout()
     client.login(username='******', password='******')
     client.post(submit_select_url, {'code': problem.solution}, follow=True)
     self.assertEqual(ObtainedAchievement.objects.filter(user=user_michu).count(), 0)
     ach_podium.position = 3
     ach_collection.num_problems = 1
     ach_solved.num_problems = 1
     ach_podium.save()
     ach_solved.save()
     ach_collection.save()
     self.assertEqual(ObtainedAchievement.objects.filter(user=user_michu).count(), 3)
Пример #2
0
    def test_obtained_achievements_date(self):
        """Test if the dates of the obtained achievements are correct"""
        user = create_user('passwordmichu', 'michu')
        coll = create_collection('Coleccion de cartas')
        problem_1 = create_select_problem(coll, 'Problema 1')
        problem_2 = create_select_problem(coll, 'Problema 2')
        sub_1 = Submission(code='nada', veredict_code=VeredictCode.AC,
                           user=user, problem=problem_1)
        sub_2 = Submission(code='nada', veredict_code=VeredictCode.AC,
                           user=user, problem=problem_2)
        sub_1.save()
        sub_2.save()
        Submission.objects.filter(id=sub_1.id).update(creation_date=datetime(2006, 3, 5))
        sub_1_u = Submission.objects.get(id=sub_1.id)
        Submission.objects.filter(id=sub_2.id).update(creation_date=datetime(2020, 3, 5))
        sub_2_u = Submission.objects.get(id=sub_2.id)

        # Test NumSolvedAchievementDefinition
        ach_solved = NumSolvedAchievementDefinition(name='Resolvista', description='Resuelve 2 problemas',
                                                    num_problems=2)
        ach_solved.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_2_u.creation_date)
        ach_solved.num_problems = 1
        ach_solved.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_1_u.creation_date)
        ObtainedAchievement.objects.all().delete()

        # Test NumSolvedCollectionAchievementDefinition
        ach_coll = NumSolvedCollectionAchievementDefinition(name='Coleccionista', description='Resuelve 2 \
                                                            problemas de esta coleccion', num_problems=2,
                                                            collection=coll)
        ach_coll.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_2_u.creation_date)
        ach_coll.num_problems = 1
        ach_coll.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_1_u.creation_date)
        ObtainedAchievement.objects.all().delete()

        # Test PodiumAchievementDefinition
        ach_podium = PodiumAchievementDefinition(name='Presidente del podio', description='Consigue ser el primero',
                                                 num_problems=2, position=1)
        ach_podium.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_2_u.creation_date)
        ach_podium.num_problems = 1
        ach_podium.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_1_u.creation_date)
        ObtainedAchievement.objects.all().delete()
Пример #3
0
 def test_signal_update_achievement(self):
     """Test for check signals"""
     # Create two users for test all the achievements. Two for the podium
     client = Client()
     user_michu = create_user('passwordmichu', 'michu')
     create_user('passwordimmobile', 'immobile')
     client.login(username='******', password='******')
     # Create the Collection for the achievement NumSolvedCollectionAchievementDefinition and Problem
     coll = create_collection('Coleccion de cartas')
     # Create PodiumAchievementDefinition
     ach_podium = PodiumAchievementDefinition(name='Presidente del podio', description='Consigue ser el primero',
                                              num_problems=1, position=1)
     ach_podium.save()
     # Create NumSolvedCollectionAchievementDefinition
     ach_collection = NumSolvedCollectionAchievementDefinition(name='Coleccionista', description='Resuelve 50\
                                                               problemas de esta coleccion', num_problems=50,
                                                               collection=coll)
     ach_collection.save()
     # Create NumSolvedAchievementDefinition
     ach_solved = NumSolvedAchievementDefinition(name='Resolvista', description='Resuelve 50 problemas',
                                                 num_problems=50)
     ach_solved.save()
     # Create NumSolvedTypeAchievementDefinition
     ach_type = NumSolvedTypeAchievementDefinition(name='Procedista', description='Resuelve un problema PROC',
                                                   num_problems=1, problem_type=ProblemType.PROC.name)
     ach_type.save()
     # Create NumSubmissionsProblemsAchievementDefinition
     ach_submi_pro = NumSubmissionsProblemsAchievementDefinition(name='Muchos envios',
                                                                 description='Envia muchas soluciones',
                                                                 num_submissions=80, num_problems=1)
     ach_submi_pro.save()
     # Create problem and submit correct answer with "immobile" user, for make this the first to solve the problem
     problem = create_select_problem(coll, 'Problema')
     submit_select_url = reverse('judge:submit', args=[problem.pk])
     client.post(submit_select_url, {'code': problem.solution}, follow=True)
     client.logout()
     # Login with "michu" and submit correct answer. All the checks will be with this user
     client.login(username='******', password='******')
     client.post(submit_select_url, {'code': problem.solution}, follow=True)
     # Whit this definitions our user "michu" don't have any achievement
     self.assertEqual(ObtainedAchievement.objects.filter(user=user_michu).count(), 0)
     # PodiumAchievementDefinition now only need to stay in podium
     # In this test our user "michu" stay at second position, that is why before he didn't have the achievement
     ach_podium.position = 3
     ach_podium.save()
     # NumSolvedCollectionAchievementDefinition only needs one correct submission
     # In this test our user only have one correct submission, that is why before he didn't have the achievement
     ach_collection.num_problems = 1
     ach_collection.save()
     # NumSolvedAchievementDefinition only needs one correct submission
     # In this test our user only have one correct submission, that is why before he didn't have the achievement
     ach_solved.num_problems = 1
     ach_solved.save()
     # NumSolvedTypeAchievementDefinition change to type SELECT
     # In this test our user only resolved a SELECT type problem, not PROC.
     ach_type.problem_type = ProblemType.SELECT.name
     ach_type.save()
     # NumSubmissionsProblemsAchievementDefinition only needs one submission now
     ach_submi_pro.num_submissions = 1
     ach_submi_pro.save()
     # Now our user "michu" have 5 achievements
     self.assertEqual(ObtainedAchievement.objects.filter(user=user_michu).count(), 5)