|
25 | 25 |
|
26 | 26 | from cms.db import UserTest, Submission |
27 | 27 | from cms.server.contest.submission import get_submission_count, \ |
28 | | - check_max_number, get_latest_submission, check_min_interval |
| 28 | + check_max_number, get_latest_submission, check_min_interval, is_last_minutes |
29 | 29 | from cmscommon.datetime import make_datetime |
30 | 30 |
|
31 | 31 |
|
@@ -399,5 +399,86 @@ def test_limit_unrestricted(self): |
399 | 399 | self.get_latest_submission.assert_not_called() |
400 | 400 |
|
401 | 401 |
|
| 402 | +class TestIsLastMinutes(DatabaseMixin, unittest.TestCase): |
| 403 | + |
| 404 | + def setUp(self): |
| 405 | + super().setUp() |
| 406 | + self.contest = self.add_contest() |
| 407 | + self.task = self.add_task(contest=self.contest) |
| 408 | + self.participation = self.add_participation(unrestricted=False, |
| 409 | + contest=self.contest) |
| 410 | + |
| 411 | + self.timestamp = make_datetime() |
| 412 | + |
| 413 | + def test_unconfigured_min_submission_interval_grace_period(self): |
| 414 | + self.setup_contest_with_no_user_time() |
| 415 | + |
| 416 | + self.assertFalse( |
| 417 | + is_last_minutes(self.timestamp, self.participation)) |
| 418 | + |
| 419 | + def test_no_per_user_time_and_last_minutes(self): |
| 420 | + self.setup_contest_with_no_user_time() |
| 421 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=15) |
| 422 | + |
| 423 | + self.assertTrue( |
| 424 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 425 | + |
| 426 | + def test_no_per_user_time_and_not_last_minutes(self): |
| 427 | + self.setup_contest_with_no_user_time() |
| 428 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=10) |
| 429 | + |
| 430 | + self.assertFalse( |
| 431 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 432 | + |
| 433 | + def test_per_user_time_and_last_minutes(self): |
| 434 | + self.participation.contest.per_user_time = timedelta(hours=5) |
| 435 | + self.participation.contest.start = self.timestamp - timedelta(hours=10) |
| 436 | + self.participation.contest.stop = self.timestamp |
| 437 | + self.participation.starting_time = self.timestamp - timedelta(hours=5) |
| 438 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=15) |
| 439 | + |
| 440 | + self.assertTrue( |
| 441 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 442 | + |
| 443 | + def test_per_user_time_and_not_last_minutes(self): |
| 444 | + self.participation.contest.per_user_time = timedelta(hours=5) |
| 445 | + self.participation.contest.start = self.timestamp - timedelta(hours=10) |
| 446 | + self.participation.contest.stop = self.timestamp |
| 447 | + self.participation.starting_time = self.timestamp - timedelta(hours=5) |
| 448 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=10) |
| 449 | + |
| 450 | + self.assertFalse( |
| 451 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 452 | + |
| 453 | + def test_consider_extra_time(self): |
| 454 | + self.setup_contest_with_no_user_time() |
| 455 | + |
| 456 | + self.participation.extra_time = timedelta(seconds=1) |
| 457 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=15) |
| 458 | + |
| 459 | + self.assertFalse( |
| 460 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 461 | + |
| 462 | + def test_consider_delay(self): |
| 463 | + self.setup_contest_with_no_user_time() |
| 464 | + |
| 465 | + self.participation.delay_time = timedelta(seconds=1) |
| 466 | + self.contest.min_submission_interval_grace_period = timedelta(minutes=15) |
| 467 | + |
| 468 | + self.assertFalse( |
| 469 | + is_last_minutes(self.timestamp - timedelta(minutes=15), self.participation)) |
| 470 | + |
| 471 | + def test_unrestricted_participation(self): |
| 472 | + self.setup_contest_with_no_user_time() |
| 473 | + self.participation.unrestricted = True |
| 474 | + |
| 475 | + self.assertFalse(is_last_minutes(self.timestamp, self.participation)) |
| 476 | + |
| 477 | + def setup_contest_with_no_user_time(self): |
| 478 | + self.participation.contest.per_user_time = None |
| 479 | + self.participation.contest.start = self.timestamp - timedelta(hours=5) |
| 480 | + self.participation.contest.stop = self.timestamp |
| 481 | + |
| 482 | + |
402 | 483 | if __name__ == "__main__": |
403 | 484 | unittest.main() |
0 commit comments