Skip to content

Commit

Permalink
Fix admin time, upgrade related test (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
otargowski authored Jul 22, 2023
1 parent 1190d0c commit 6518a0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
28 changes: 19 additions & 9 deletions oioioi/clock/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import calendar
import time
from datetime import datetime, timezone # pylint: disable=E0611

from dateutil.parser import parse as parse_date
from django.contrib.auth.models import User
from django.test.utils import override_settings
from django.urls import reverse
Expand Down Expand Up @@ -65,12 +63,24 @@ def test_countdown_with_extended_rounds(self):
@override_settings(CONTEST_MODE=ContestMode.neutral)
def test_admin_time(self):
self.assertTrue(self.client.login(username='test_admin'))
session = self.client.session
session['admin_time'] = datetime(2012, 12, 12, tzinfo=timezone.utc).isoformat()
session.save()
# As seconds since the epoch
changed_time = datetime(2012, 12, 12, tzinfo=timezone.utc).timestamp()
response = self.client.get(reverse('get_status')).json()
current_time = response['time']
post_data = {'ok-button': '', 'admin-time': '2012-12-12+0:0:0'}
post_url = reverse('admin_time')

response = self.client.post(post_url, post_data, follow=True)
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('get_status')).json()
self.assertTrue(response['is_admin_time_set'])
self.assertEqual(
response['time'],
calendar.timegm(parse_date(session['admin_time']).timetuple()),
)
self.assertEqual(response['time'], changed_time)

post_data = {'reset-button': '', 'admin-time': '2012-12-12+0:0:0'}

response = self.client.post(post_url, post_data, follow=True)
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('get_status')).json()
self.assertFalse(response['is_admin_time_set'])
# This test shouldn't take more than a minute.
self.assertLess(abs(response['time'] - current_time), 60)
4 changes: 2 additions & 2 deletions oioioi/clock/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def admin_time(request, next_page=None):
messages.error(request, _("Invalid date. Admin-time was not set."))
return safe_redirect(request, next_page)
if current_admin_time.year >= 1900:
local_tz = timezone.localtime().tzinfo
request.session['admin_time'] = (
timezone.localtime(timezone.now())
.tzinfo.localize(current_admin_time)
current_admin_time.replace(tzinfo=local_tz)
.astimezone(pytz.utc)
.isoformat()
)
Expand Down

0 comments on commit 6518a0e

Please sign in to comment.