From 2afddf17ac366165459bcde3c57acedeac83c6d0 Mon Sep 17 00:00:00 2001 From: LuizaMaluf Date: Tue, 14 Nov 2023 20:59:09 -0300 Subject: [PATCH] feat(validators): contest status form validator tests --- apps/contests/tests.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/contests/tests.py b/apps/contests/tests.py index 2ed2d12..0fc8f9d 100644 --- a/apps/contests/tests.py +++ b/apps/contests/tests.py @@ -70,21 +70,18 @@ def test_cancelled(self) -> None: self.assertEqual(ContestStatus.CANCELLED, "Cancelled") def test_valid_status(self) -> None: - valid_status = ContestStatus.RUNNING - self.assertIsNone(ContestStatus.validate_contest_status(valid_status)) - - def test_invalid_status(self) -> None: - invalid_status = "InvalidStatus" - with self.assertRaises(ValueError) as context: - ContestStatus.validate_contest_status( - ContestStatus(invalid_status) - ) - expected_message = ( - f"Invalid contest status: {invalid_status}. " - f"Must be one of {list(ContestStatus.__members__.values())}" - ) - actual_message = str(context.exception) - self.assertEqual(expected_message, actual_message) + valid_statuses = [ + ContestStatus.PENDING, + ContestStatus.RUNNING, + ContestStatus.FINISHED, + ContestStatus.CANCELLED, + ] + + for status in valid_statuses: + with self.subTest(status=status): + self.assertIsNone( + ContestStatus.validate_contest_status(status) + ) class ContestModelFormTestCase(TestCase):