Skip to content

Commit 6518a0e

Browse files
authored
Fix admin time, upgrade related test (#240)
1 parent 1190d0c commit 6518a0e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

oioioi/clock/tests.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import calendar
21
import time
32
from datetime import datetime, timezone # pylint: disable=E0611
43

5-
from dateutil.parser import parse as parse_date
64
from django.contrib.auth.models import User
75
from django.test.utils import override_settings
86
from django.urls import reverse
@@ -65,12 +63,24 @@ def test_countdown_with_extended_rounds(self):
6563
@override_settings(CONTEST_MODE=ContestMode.neutral)
6664
def test_admin_time(self):
6765
self.assertTrue(self.client.login(username='test_admin'))
68-
session = self.client.session
69-
session['admin_time'] = datetime(2012, 12, 12, tzinfo=timezone.utc).isoformat()
70-
session.save()
66+
# As seconds since the epoch
67+
changed_time = datetime(2012, 12, 12, tzinfo=timezone.utc).timestamp()
68+
response = self.client.get(reverse('get_status')).json()
69+
current_time = response['time']
70+
post_data = {'ok-button': '', 'admin-time': '2012-12-12+0:0:0'}
71+
post_url = reverse('admin_time')
72+
73+
response = self.client.post(post_url, post_data, follow=True)
74+
self.assertEqual(response.status_code, 200)
7175
response = self.client.get(reverse('get_status')).json()
7276
self.assertTrue(response['is_admin_time_set'])
73-
self.assertEqual(
74-
response['time'],
75-
calendar.timegm(parse_date(session['admin_time']).timetuple()),
76-
)
77+
self.assertEqual(response['time'], changed_time)
78+
79+
post_data = {'reset-button': '', 'admin-time': '2012-12-12+0:0:0'}
80+
81+
response = self.client.post(post_url, post_data, follow=True)
82+
self.assertEqual(response.status_code, 200)
83+
response = self.client.get(reverse('get_status')).json()
84+
self.assertFalse(response['is_admin_time_set'])
85+
# This test shouldn't take more than a minute.
86+
self.assertLess(abs(response['time'] - current_time), 60)

oioioi/clock/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def admin_time(request, next_page=None):
103103
messages.error(request, _("Invalid date. Admin-time was not set."))
104104
return safe_redirect(request, next_page)
105105
if current_admin_time.year >= 1900:
106+
local_tz = timezone.localtime().tzinfo
106107
request.session['admin_time'] = (
107-
timezone.localtime(timezone.now())
108-
.tzinfo.localize(current_admin_time)
108+
current_admin_time.replace(tzinfo=local_tz)
109109
.astimezone(pytz.utc)
110110
.isoformat()
111111
)

0 commit comments

Comments
 (0)