def test_window_end_time(self): Database.set_meta("start_time", 1000) Database.set_meta("contest_duration", 150) Database.set_meta("window_duration", 100) Database.set_meta("extra_time", 20) self.assertEqual(BaseHandler.get_window_end_time(10, 20), 1130) self.assertEqual(BaseHandler.get_window_end_time(0, 0), 1100)
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 test_window_end_time_no_window(self): Database.set_meta("start_time", 1000) Database.set_meta("contest_duration", 150) # Database.set_meta("window_duration", nope) Database.set_meta("extra_time", 20) self.assertEqual(BaseHandler.get_window_end_time(20, 42), None)