Exemple #1
0
def create_an_achievement_of_each(coll):
    """Create an achievement of each type: NumSolvedAchievementDefinition, PodiumAchievementDefinition and
    NumSolvedCollectionAchievementDefinition"""
    ach_podium = PodiumAchievementDefinition(
        name={"es": 'Presidente del podio'},
        description={"es": 'Consigue entrar al podio'},
        num_problems=1,
        position=3)
    ach_collection = NumSolvedCollectionAchievementDefinition(
        name={"es": 'Coleccionista'},
        description={"es": 'Resuelve 1 problema de esta coleccion'},
        num_problems=1,
        collection=coll)
    ach_solved = NumSolvedAchievementDefinition(
        name={"es": 'Resolvista'},
        description={"es": 'Resuelve 1 problema'},
        num_problems=1)
    ach_type = NumSolvedTypeAchievementDefinition(
        name={"es": 'Tipos'},
        description={"es": 'Resuelve un problema SELECT'},
        num_problems=1,
        problem_type=ProblemType.SELECT.name)
    ach_submi_pro = NumSubmissionsProblemsAchievementDefinition(
        name={"es": 'Primer envio'},
        description={"es": 'Realiza un envio a cualquier problema'},
        num_submissions=1,
        num_problems=1)
    ach_type.save()
    ach_submi_pro.save()
    ach_podium.save()
    ach_collection.save()
    ach_solved.save()
Exemple #2
0
 def test_incorrect_submit_get_achievement(self):
     """Test if an incorrect submission get an achievement"""
     client = Client()
     user = create_user('passwordmazepin', 'mazepin')
     coll = create_collection('Coleccion de cartas')
     problem = create_select_problem(coll, 'Problema')
     ach_submissions = NumSubmissionsProblemsAchievementDefinition(name='Un envio',
                                                                   description='Envia una solucion para un problema',
                                                                   num_problems=1, num_submissions=1)
     ach_submissions.save()
     client.login(username='******', password='******')
     submit_select_url = reverse('judge:submit', args=[problem.pk])
     client.post(submit_select_url, {'code': 'MAL'}, follow=True)  # Validation Error, too short
     self.assertEqual(ObtainedAchievement.objects.filter(user=user).count(), 1)
Exemple #3
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 1 updated
        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()

        # Test NumSolvedTypeAchievementDefinition
        ach_type = NumSolvedTypeAchievementDefinition(name='Tipos', description='Resuelve un problema SELECT',
                                                      num_problems=2, problem_type=ProblemType.SELECT.name)
        ach_type.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_2_u.creation_date)
        ach_type.num_problems = 1
        ach_type.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 NumSubmissionsProblemsAchievementDefinition
        ach_submissions = NumSubmissionsProblemsAchievementDefinition(name='Ya van dos problemas',
                                                                      description='Realiza un envio en dos problemas',
                                                                      num_problems=2, num_submissions=2)
        ach_submissions.save()
        date = ObtainedAchievement.objects.filter(user=user).values_list('obtained_date', flat=True)
        self.assertEqual(date[0], sub_2_u.creation_date)
        ach_submissions.num_problems = 1
        ach_submissions.num_submissions = 1
        ach_submissions.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()
Exemple #4
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)
Exemple #5
0
    def test_achievements_submit(self):
        """Test to show correct message when obtain an achievement"""
        client = Client()
        collection = create_collection('Colleccion de prueba XYZ')
        select_problem = create_select_problem(collection,
                                               'SelectProblem ABC DEF')
        user = create_user('5555', 'tamara')
        ach_submission = NumSubmissionsProblemsAchievementDefinition(
            name={"es": 'Un envio'},
            description={"es": 'Envia una solucion para un problema'},
            num_problems=1,
            num_submissions=1)
        ach_submission.save()
        ach_submissions = NumSubmissionsProblemsAchievementDefinition(
            name={"es": 'Tres envios'},
            description={"es": 'Envia tres soluciones de un problema'},
            num_problems=1,
            num_submissions=3)
        ach_submissions.save()
        ach_type = NumSolvedTypeAchievementDefinition(
            name={"es": 'Es select'},
            description={"es": 'Resuelve un problema SELECT'},
            num_problems=1,
            problem_type=ProblemType.SELECT.name)
        client.login(username='******', password='******')
        submit_select_url = reverse('judge:submit', args=[select_problem.pk])

        # The user submits one solution and obtains the first achievement
        response = client.post(submit_select_url, {'code': 'MAL'},
                               follow=True)  # Validation Error, too short
        obtained_achieve = ObtainedAchievement.objects.filter(user=user)
        self.assertIn(obtained_achieve[0].achievement_definition.name['es'],
                      response.json()['achievements'])

        # The user submits a new solution and does not receive any achievement
        response = client.post(submit_select_url, {'code': 'MAL'},
                               follow=True)  # Validation Error, too short
        self.assertNotIn('achievements', response.json())

        # The user makes another submission and obtain two achievements
        ach_type.save()
        curr_path = os.path.dirname(__file__)
        zip_select_path = os.path.join(curr_path, ParseTest.ZIP_FOLDER,
                                       ParseTest.SELECT_OK)
        collection = create_collection('Coleccion 1')
        select = SelectProblem(zipfile=zip_select_path, collection=collection)
        select.clean()
        select.save()
        submit_url = reverse('judge:submit', args=[select.pk])
        response = client.post(submit_url, {'code': select.solution},
                               follow=True)
        obtained_achieve = ObtainedAchievement.objects.filter(user=user)
        self.assertIn(obtained_achieve[1].achievement_definition.name['es'],
                      response.json()['achievements'])
        self.assertIn(obtained_achieve[2].achievement_definition.name['es'],
                      response.json()['achievements'])

        # The user submits a new solution and does not receive any achievement
        response = client.post(submit_select_url, {'code': 'MAL'},
                               follow=True)  # Validation Error, too short
        self.assertNotIn('achievements', response.json())