예제 #1
0
 def setUp(self):
     contest1 = Contest.objects.get(id='c1')
     contest2 = Contest.objects.get(id='c2')
     rounds = [
         Round(
             name='round1',
             contest=contest1,
             start_date=datetime(2013, 10, 11, 8, 0, tzinfo=utc),
             end_date=datetime(2013, 12, 5, 9, 0, tzinfo=utc),
         ),
         Round(
             name='round2',
             contest=contest1,
             start_date=datetime(2013, 10, 22, 10, 0, tzinfo=utc),
             end_date=datetime(2013, 11, 5, 11, 0, tzinfo=utc),
         ),
         Round(
             name='round1p',
             contest=contest2,
             start_date=datetime(2014, 1, 2, 3, 10, tzinfo=utc),
             end_date=None,
         ),
     ]
     self.round1_result = {
         'status': 'OK',
         'round_name': 'round1',
         'start': '2013-10-11 08:00:00',
         'start_sec': 1381478400,
         'end': '2013-12-05 09:00:00',
         'end_sec': 1386234000,
     }
     self.round2_result = {
         'status': 'OK',
         'round_name': 'round2',
         'start': '2013-10-22 10:00:00',
         'start_sec': 1382436000,
         'end': '2013-11-05 11:00:00',
         'end_sec': 1383649200,
     }
     self.round1p_result = {
         'status': 'OK',
         'round_name': 'round1p',
         'start': '2014-01-02 03:10:00',
         'start_sec': 1388632200,
         'end': None,
         'end_sec': None,
     }
     Round.objects.bulk_create(rounds)
     self.assertTrue(self.client.login(username='******'))
예제 #2
0
 def setUp(self):
     Round.objects.all().delete()
     contest = Contest.objects.get()
     rounds = [
         Round(name='round1',
               contest=contest,
               start_date=datetime(2013, 10, 11, 8, 0, tzinfo=utc),
               end_date=datetime(2013, 12, 5, 9, 0, tzinfo=utc)),
         Round(name='round2',
               contest=contest,
               start_date=datetime(2013, 10, 22, 10, 0, tzinfo=utc),
               end_date=datetime(2013, 11, 5, 11, 0, tzinfo=utc))
     ]
     Round.objects.bulk_create(rounds)
     self.client.login(username='******')
예제 #3
0
파일: tests.py 프로젝트: sio2project/oioioi
    def test_countdown_with_extended_rounds(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r1.save()
        user = User.objects.get(username='******')
        RoundTimeExtension(user=user, round=r1, extra_time=10).save()

        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(reverse('get_status',
            kwargs={'contest_id': contest.id})).json()
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r1_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r1_end.timetuple()) + 600)
예제 #4
0
파일: tests.py 프로젝트: tmkkk/oioioi
    def test_countdown_with_extended_rounds(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r1.save()
        user = User.objects.get(username='******')
        RoundTimeExtension(user=user, round=r1, extra_time=10).save()

        self.assertTrue(self.client.login(username='******'))
        response = self.client.get(
            reverse('get_status', kwargs={'contest_id': contest.id})).json()
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r1_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r1_end.timetuple()) + 600)
예제 #5
0
파일: forms.py 프로젝트: marmistrz/oioioi
    def save(self, commit=True):
        instance = super(SimpleContestForm, self).save(commit=False)
        rounds = instance.round_set.all()
        if len(rounds) > 1:
            raise ValueError("SimpleContestForm does not support contests "
                             "with more than one round.")
        if len(rounds) == 1:
            round = rounds[0]
        else:
            instance.save()
            round = Round(contest=instance, name=_("Round 1"))
        self._set_dates(round)
        round.save()

        if commit:
            instance.save()

        return instance
예제 #6
0
파일: forms.py 프로젝트: matrach/oioioi
    def save(self, commit=True):
        instance = super(SimpleContestForm, self).save(commit=False)
        rounds = instance.round_set.all()
        if len(rounds) > 1:
            raise ValueError("SimpleContestForm does not support contests "
                    "with more than one round.")
        if len(rounds) == 1:
            round = rounds[0]
        else:
            instance.save()
            round = Round(contest=instance, name=_("Round 1"))
        self._set_dates(round)
        round.save()

        if commit:
            instance.save()

        return instance
예제 #7
0
    def test_order_rounds_by_focus(self):
        r1 = Round(start_date=datetime(2012, 1, 1, 8, 0),
                   end_date=datetime(2012, 1, 1, 10, 0))
        r2 = Round(start_date=datetime(2012, 1, 1, 9, 59),
                   end_date=datetime(2012, 1, 1, 11, 00))
        r3 = Round(start_date=datetime(2012, 1, 2, 8, 0),
                   end_date=datetime(2012, 1, 2, 10, 0))
        rounds = [r1, r2, r3]
        controller = ContestController(None)

        class FakeRequest(object):
            def __init__(self, timestamp):
                self.timestamp = timestamp

        for date, expected_order in ((datetime(2011, 1, 1), [r1, r2, r3]),
                                     (datetime(2012, 1, 1, 7, 0),
                                      [r1, r2,
                                       r3]), (datetime(2012, 1, 1, 7,
                                                       55), [r1, r2, r3]),
                                     (datetime(2012, 1, 1, 9, 40),
                                      [r1, r2,
                                       r3]), (datetime(2012, 1, 1, 9,
                                                       45), [r2, r1, r3]),
                                     (datetime(2012, 1, 1, 9, 59, 29),
                                      [r2, r1,
                                       r3]), (datetime(2012, 1, 1, 9, 59,
                                                       31), [r1, r2, r3]),
                                     (datetime(2012, 1, 1, 10, 0, 1),
                                      [r2, r3,
                                       r1]), (datetime(2012, 1, 1, 11, 0,
                                                       1), [r2, r3, r1]),
                                     (datetime(2012, 1, 2, 2, 0, 1),
                                      [r3, r2,
                                       r1]), (datetime(2012, 1, 2, 2, 7,
                                                       55), [r3, r2, r1]),
                                     (datetime(2012, 1, 2, 2, 9, 0),
                                      [r3, r2,
                                       r1]), (datetime(2012, 1, 2, 2, 11,
                                                       0), [r3, r2, r1])):
            self.assertEqual(
                controller.order_rounds_by_focus(FakeRequest(date), rounds),
                expected_order)
예제 #8
0
 def test_fields_autogeneration(self):
     contest = Contest()
     contest.save()
     self.assertEqual(contest.id, 'c1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 2')
     problem = Problem()
     problem.save()
     pi = ProblemInstance(round=round, problem=problem)
     pi.save()
     self.assertEqual(pi.contest, contest)
예제 #9
0
파일: tests.py 프로젝트: tmkkk/oioioi
    def test_countdown(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r2_start = datetime.fromtimestamp(now - 10)
        r2_end = datetime.fromtimestamp(now + 5)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r2 = Round(contest=contest, start_date=r2_start, end_date=r2_end)
        r1.save()
        r2.save()

        response = self.client.get(
            reverse('get_status', kwargs={'contest_id': contest.id})).json()
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r2_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r2_end.timetuple()))
예제 #10
0
파일: tests.py 프로젝트: mahrud/oioioi
 def test_fields_autogeneration(self):
     contest = Contest()
     contest.save()
     self.assertEqual(contest.id, 'c1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 1')
     round = Round(contest=contest)
     round.save()
     self.assertEqual(round.name, 'Round 2')
     problem = Problem()
     problem.save()
     pi = ProblemInstance(round=round, problem=problem)
     pi.save()
     self.assertEqual(pi.contest, contest)
예제 #11
0
파일: tests.py 프로젝트: sio2project/oioioi
    def test_countdown(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r2_start = datetime.fromtimestamp(now - 10)
        r2_end = datetime.fromtimestamp(now + 5)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r2 = Round(contest=contest, start_date=r2_start, end_date=r2_end)
        r1.save()
        r2.save()

        response = self.client.get(reverse('get_status',
            kwargs={'contest_id': contest.id})).json()
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r2_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r2_end.timetuple()))
예제 #12
0
파일: tests.py 프로젝트: mahrud/oioioi
    def test_countdown(self):
        contest = Contest.objects.get()
        now = time.time()
        r1_start = datetime.fromtimestamp(now - 5)
        r1_end = datetime.fromtimestamp(now + 10)
        r2_start = datetime.fromtimestamp(now - 10)
        r2_end = datetime.fromtimestamp(now + 5)
        r1 = Round(contest=contest, start_date=r1_start, end_date=r1_end)
        r2 = Round(contest=contest, start_date=r2_start, end_date=r2_end)
        r1.save()
        r2.save()

        response = self.client.get(reverse('oioioi.clock.views.get_times_view'))
        response = json.loads(response.content)
        round_start_date = response['round_start_date']
        round_end_date = response['round_end_date']
        self.assertEqual(round_start_date, time.mktime(r2_start.timetuple()))
        self.assertEqual(round_end_date, time.mktime(r2_end.timetuple()))
예제 #13
0
파일: forms.py 프로젝트: marmistrz/oioioi
 def clean(self):
     cleaned_data = super(SimpleContestForm, self).clean()
     round = Round()
     self._set_dates(round)
     round.clean()
     return cleaned_data
예제 #14
0
파일: forms.py 프로젝트: matrach/oioioi
 def clean(self):
     cleaned_data = super(SimpleContestForm, self).clean()
     round = Round()
     self._set_dates(round)
     round.clean()
     return cleaned_data