Beispiel #1
0
    def test_exclusive_contests_error(self):
        self._assertContestVisible('c1')
        self._assertContestVisible('c2')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c1
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c2
        ex_conf.start_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 16, tzinfo=utc)
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 13, tzinfo=utc)):
            response = self.client.get('/c/c1/id/')
            self.assertContains(response,
                    'participate in more than one contest that exc')
            self.assertEqual(len(mail.outbox), 1)
            message = mail.outbox[0]
            self.assertEqual(list(message.to), ['*****@*****.**'])
            self.assertIn('in more than one exclusive contest', message.body)
            self.assertIn('c1', message.body)
            self.assertIn('c2', message.body)
Beispiel #2
0
    def test_contest_admin_with_participant(self):
        self.c2.controller_name = \
            'oioioi.participants.tests.ParticipantsContestController'
        self.c2.save()

        ContestPermission(user=self.user, contest=self.c1,
                          permission='contests.contest_admin').save()
        Participant(user=self.user, contest=self.c2).save()

        ex_conf1 = ExclusivenessConfig()
        ex_conf1.contest = self.c1
        ex_conf1.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf1.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf1.save()
        ex_conf2 = ExclusivenessConfig()
        ex_conf2.contest = self.c2
        ex_conf2.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf2.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf2.save()

        self.client.login(username='******')

        with fake_time(datetime(2012, 1, 1, 10, tzinfo=utc)):
            self._assertContestVisible('c2')
            self._assertContestRedirects('c1', '/c/c2')
Beispiel #3
0
    def test_contest_admin_with_participant(self):
        self.c2.controller_name = (
            'oioioi.participants.tests.ParticipantsContestController')
        self.c2.save()

        ContestPermission(user=self.user,
                          contest=self.c1,
                          permission='contests.contest_admin').save()
        Participant(user=self.user, contest=self.c2).save()

        ex_conf1 = ExclusivenessConfig()
        ex_conf1.contest = self.c1
        ex_conf1.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf1.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf1.save()
        ex_conf2 = ExclusivenessConfig()
        ex_conf2.contest = self.c2
        ex_conf2.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf2.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf2.save()

        self.assertTrue(self.client.login(username='******'))

        with fake_time(datetime(2012, 1, 1, 10, tzinfo=utc)):
            self._assertContestVisible('c2')
            self._assertContestRedirects('c1', '/c/c2')
Beispiel #4
0
    def test_exclusive_contest(self):
        self._assertContestVisible('c1')
        self._assertContestVisible('c2')

        self.client.login(username='******')

        self._assertContestVisible('c1')
        self._assertContestVisible('c2')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c2
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 9, 59, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestVisible('c2')

        with fake_time(datetime(2012, 1, 1, 11, tzinfo=utc)):
            self._assertContestRedirects('c1', '/c/c2/')
            self._assertContestVisible('c2')

        with fake_time(datetime(2012, 1, 1, 14, 1, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestVisible('c2')
Beispiel #5
0
def add_ex_conf(contest, start_date, end_date=None, enabled=True):
    ex_conf = ExclusivenessConfig()
    ex_conf.contest = contest
    ex_conf.start_date = start_date
    ex_conf.end_date = end_date
    ex_conf.enabled = enabled
    ex_conf.save()
    return ex_conf
Beispiel #6
0
def add_ex_conf(contest, start_date, end_date=None, enabled=True):
    ex_conf = ExclusivenessConfig()
    ex_conf.contest = contest
    ex_conf.start_date = start_date
    ex_conf.end_date = end_date
    ex_conf.enabled = enabled
    ex_conf.save()
    return ex_conf
Beispiel #7
0
    def setUp(self):
        self.test_user = User.objects.get(username='******')
        self.test_user2 = User.objects.get(username='******')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = Contest.objects.get(id='c1')
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()
Beispiel #8
0
    def test_default_selector(self):
        self.client.login(username='******')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c1
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 12, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestVisible('c2')
Beispiel #9
0
    def test_enabled_field(self):
        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c2
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.enabled = False
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 11, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestVisible('c2')

            ex_conf.enabled = True
            ex_conf.save()

            self._assertContestRedirects('c1', '/c/c2/')
            self._assertContestVisible('c2')
Beispiel #10
0
    def test_exclusiveness_on(self):
        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()

        response = self.user.get(self.url, follow=True)
        self.assertEqual(response.status_code, 403)

        response = self.admin.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Exclusiveness configs', response.content)

        response = self.contestadmin.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Exclusiveness configs', response.content)
Beispiel #11
0
    def test_exclusiveness_on(self):
        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c
        ex_conf.start_date = datetime(2012, 1, 1, 10, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 14, tzinfo=utc)
        ex_conf.save()

        response = self.user.get(self.url, follow=True)
        self.assertEqual(response.status_code, 403)

        response = self.admin.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Exclusiveness configs', response.content)

        response = self.contestadmin.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Exclusiveness configs', response.content)
Beispiel #12
0
    def test_participants_selector(self):
        self.c1.controller_name = \
            'oioioi.participants.tests.ParticipantsContestController'
        self.c1.save()

        Participant(user=self.user, contest=self.c1).save()

        self.client.login(username='******')

        self._assertContestVisible('c1')
        self._assertContestVisible('c2')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c1
        ex_conf.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 10, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestRedirects('c2', '/c/c1/')
            self.client.login(username='******')
            self._assertContestVisible('c2')
Beispiel #13
0
    def test_participants_selector(self):
        self.c1.controller_name = (
            'oioioi.participants.tests.ParticipantsContestController')
        self.c1.save()

        Participant(user=self.user, contest=self.c1).save()

        self.assertTrue(self.client.login(username='******'))

        self._assertContestVisible('c1')
        self._assertContestVisible('c2')

        ex_conf = ExclusivenessConfig()
        ex_conf.contest = self.c1
        ex_conf.start_date = datetime(2012, 1, 1, 8, tzinfo=utc)
        ex_conf.end_date = datetime(2012, 1, 1, 12, tzinfo=utc)
        ex_conf.save()

        with fake_time(datetime(2012, 1, 1, 10, tzinfo=utc)):
            self._assertContestVisible('c1')
            self._assertContestRedirects('c2', '/c/c1/')
            self.assertTrue(self.client.login(username='******'))
            self._assertContestVisible('c2')