Esempio n. 1
0
    def test_solved_n_position(self):
        """ Test that solved_n_position does not count staff or inactive users """
        staff_user = get_user_model().objects.create_user('teacher',
                                                          password='******',
                                                          is_staff=True,
                                                          is_active=True)
        inactive_user = get_user_model().objects.create_user('inactive',
                                                             password='******',
                                                             is_staff=False,
                                                             is_active=False)
        user = get_user_model().objects.create_user('normal',
                                                    password='******',
                                                    is_staff=False,
                                                    is_active=True)

        collection = Collection(name_md='ABC', description_md='blablabla')
        collection.clean()
        collection.save()

        create = 'CREATE TABLE tabla (xx NUMBER);'
        solution = 'SELECT * FROM tabla'
        problem = SelectProblem(title_md='Example',
                                text_md='Enunciado',
                                create_sql=create,
                                insert_sql="",
                                collection=collection,
                                solution=solution)
        problem.clean()
        problem.save()

        sub1 = Submission(code='nada',
                          verdict_code=VerdictCode.AC,
                          user=staff_user,
                          problem=problem)
        sub2 = Submission(code='nada',
                          verdict_code=VerdictCode.AC,
                          user=inactive_user,
                          problem=problem)
        sub3 = Submission(code='nada',
                          verdict_code=VerdictCode.AC,
                          user=user,
                          problem=problem)
        for sub in (sub1, sub2, sub3):
            sub.clean()
            sub.save()

        # First non-staff active user to solve the problem is 'user'
        self.assertEqual(problem.solved_first(), user)
        self.assertIsNone(problem.solved_second())
        self.assertIsNone(problem.solved_third())

        # Non-active or staff users are not counted in solved_position
        self.assertIsNone(problem.solved_position(staff_user))
        self.assertIsNone(problem.solved_position(inactive_user))
        self.assertEqual(problem.solved_position(user), 1)
Esempio n. 2
0
    def test_podium(self):
        """Test the correct performance of the podium"""
        collection = Collection(name_md='ABC', description_md='blablabla')
        collection.clean()
        collection.save()
        self.assertIn('ABC', str(collection))

        user_model = django.contrib.auth.get_user_model()

        create = 'CREATE TABLE mytable (dd DATE);'
        insert = "INSERT INTO mytable VALUES (TO_DATE('2020/01/31', 'yyyy/mm/dd'))"
        solution = 'SELECT * FROM mytable'
        problem1 = SelectProblem(title_md='Dates',
                                 text_md='Example with dates',
                                 create_sql=create,
                                 insert_sql=insert,
                                 collection=collection,
                                 solution=solution)
        problem2 = SelectProblem(title_md='Dates',
                                 text_md='Example with dates',
                                 create_sql=create,
                                 insert_sql=insert,
                                 collection=collection,
                                 solution=solution)
        user1 = user_model.objects.create_user(username='******',
                                               email='*****@*****.**',
                                               password='******')
        user2 = user_model.objects.create_user(username='******',
                                               email='*****@*****.**',
                                               password='******')
        user3 = user_model.objects.create_user(username='******',
                                               email='*****@*****.**',
                                               password='******')
        user4 = user_model.objects.create_user(username='******',
                                               email='*****@*****.**',
                                               password='******')

        problem1.clean()
        problem1.save()
        problem2.clean()
        problem2.save()
        user1.save()
        user2.save()
        user3.save()

        self.assertIsNone(problem1.solved_first())
        self.assertIsNone(problem1.solved_second())
        self.assertIsNone(problem1.solved_third())

        sub1 = Submission(code='nada',
                          veredict_code=VeredictCode.WA,
                          user=user1,
                          problem=problem1)
        sub2 = Submission(code='nada',
                          veredict_code=VeredictCode.IE,
                          user=user1,
                          problem=problem1)
        sub3 = Submission(code='nada',
                          veredict_code=VeredictCode.TLE,
                          user=user1,
                          problem=problem1)
        sub4 = Submission(code='nada',
                          veredict_code=VeredictCode.RE,
                          user=user1,
                          problem=problem1)
        sub5 = Submission(code='nada',
                          veredict_code=VeredictCode.VE,
                          user=user1,
                          problem=problem1)

        for sub in [sub1, sub2, sub3, sub4, sub5]:
            sub.save()

        self.assertIsNone(problem1.solved_first())
        self.assertIsNone(problem1.solved_second())
        self.assertIsNone(problem1.solved_third())

        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()

        self.assertEqual(problem1.solved_first(), user1)
        self.assertIsNone(problem1.solved_second())
        self.assertIsNone(problem1.solved_third())

        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()
        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()

        self.assertEqual(problem1.solved_first(), user1)
        self.assertIsNone(problem1.solved_second())
        self.assertIsNone(problem1.solved_third())

        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user2,
                   problem=problem1).save()

        self.assertEqual(problem1.solved_first(), user1)
        self.assertEqual(problem1.solved_second(), user2)
        self.assertIsNone(problem1.solved_third())

        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()
        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user3,
                   problem=problem1).save()

        self.assertEqual(problem1.solved_first(), user1)
        self.assertEqual(problem1.solved_second(), user2)
        self.assertEqual(problem1.solved_third(), user3)

        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()
        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user1,
                   problem=problem1).save()
        Submission(code='nada',
                   veredict_code=VeredictCode.AC,
                   user=user4,
                   problem=problem1).save()

        self.assertEqual(problem1.solved_first(), user1)
        self.assertEqual(problem1.solved_second(), user2)
        self.assertEqual(problem1.solved_third(), user3)

        self.assertIsNone(problem2.solved_first())
        self.assertIsNone(problem2.solved_second())
        self.assertIsNone(problem2.solved_third())