def test_end_time(self): Database.set_meta("start_time", 1000) Database.set_meta("contest_duration", 150) Database.set_meta("extra_time", 20) self.assertEqual(BaseHandler.get_end_time(20), 1190) self.assertEqual(BaseHandler.get_end_time(0), 1170)
def _ensure_contest_running(token=None): """ Makes sure that the contest is running for the user, if any. If the user has a time window it is also checked. :param token: The optional token of the user. """ extra_time = None start_delay = None if token: Validators._ensure_window_start(token) user = Database.get_user(token) if user: extra_time = user["extra_time"] start_delay = user["contest_start_delay"] if Database.get_meta("start_time") is None: BaseHandler.raise_exc(Forbidden, "FORBIDDEN", "The contest has not started yet") contest_end = BaseHandler.get_end_time(extra_time) window_end = BaseHandler.get_window_end_time(extra_time, start_delay) now = time.time() # check the contest is not finished if contest_end < now: BaseHandler.raise_exc(Forbidden, "FORBIDDEN", "The contest has ended") # if a window is present check it's not finished if window_end and window_end < now: BaseHandler.raise_exc(Forbidden, "FORBIDDEN", "Your window has ended")
def status(self): """ POST /admin/status """ start_time = Database.get_meta('start_time', type=int) extra_time = Database.get_meta('extra_time', type=int, default=0) end_time = BaseHandler.get_end_time(0) return BaseHandler.format_dates( { "start_time": start_time, "extra_time": extra_time, "end_time": end_time, "loaded": ContestManager.has_contest }, fields=["start_time", "end_time"])
def test_end_time_not_started(self): self.assertIsNone(BaseHandler.get_end_time(0))