From 82701c2a710835989254eb15a430b7bd535e16e8 Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Mon, 6 Nov 2023 16:28:30 -0300 Subject: [PATCH] test: Problem test case --- apps/contests/tests_contests.py | 7 ++++++- apps/problems/tests_problems.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/contests/tests_contests.py b/apps/contests/tests_contests.py index 44ae8d4..01387f0 100644 --- a/apps/contests/tests_contests.py +++ b/apps/contests/tests_contests.py @@ -97,10 +97,15 @@ def test_fieldsets(self) -> None: self.assertEqual(self.contest_admin.fieldsets, expected_fieldsets) -class TestContestsUrls(TestCase): +class ContestsUrlsTestCase(TestCase): def test_detail_url_resolves(self) -> None: url = reverse("contests:detail", args=[1]) resolved_view_name = resolve(url).view_name expected_view_name = "contests:detail" self.assertEqual(resolved_view_name, expected_view_name) + + +class ContestViewsTesteCase(TestCase): + # tentar novamente depois + pass diff --git a/apps/problems/tests_problems.py b/apps/problems/tests_problems.py index a823fba..6198f91 100644 --- a/apps/problems/tests_problems.py +++ b/apps/problems/tests_problems.py @@ -1,8 +1,35 @@ +from datetime import timedelta + from django.test import TestCase +from django.utils import timezone + +from apps.contests.models import Contest +from apps.problems.models import Problem class ProblemTestCase(TestCase): - pass + def test_is_accessible(self) -> None: + now = timezone.now() + + start_time = now - timedelta(hours=1) + end_time = now + timedelta(hours=1) + contest = Contest(start_time=start_time, end_time=end_time) + + problem = Problem(contest=contest) + + self.assertTrue(problem.is_accessible) + + contest.start_time = now - timedelta(hours=2) + contest.end_time = now - timedelta(hours=1) + contest.save() + + self.assertTrue(problem.is_accessible) + + contest.start_time = now + timedelta(hours=1) + contest.end_time = now + timedelta(hours=2) + contest.save() + + self.assertFalse(problem.is_accessible) class DetailViewTestCase(TestCase):