From e668bc7faef13e0263fc7221731d0d8a9259334d Mon Sep 17 00:00:00 2001 From: "Madjid.A" Date: Tue, 23 Nov 2021 11:44:20 +0100 Subject: [PATCH] add test clean method of suspensions --- itou/approvals/tests.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/itou/approvals/tests.py b/itou/approvals/tests.py index 87a16cc193..c83b0d15c8 100644 --- a/itou/approvals/tests.py +++ b/itou/approvals/tests.py @@ -946,6 +946,30 @@ class SuspensionModelTest(TestCase): Test Suspension model. """ + def test_clean(self): + today = timezone.now().date() + start_at = timezone.now().date() - relativedelta(months=2) + end_at = start_at + relativedelta(months=2) + approval = ApprovalFactory(start_at=start_at, end_at=end_at) + suspension = SuspensionFactory(approval=approval) + + # test the when suspension is out of boundaries + suspension.start_at = start_at - relativedelta(months=1) + with self.assertRaises(ValidationError): + suspension.clean() + + # the case when end_at < start_at + suspension.start_at = start_at + suspension.end_at = start_at - relativedelta(months=1) + with self.assertRaises(ValidationError): + suspension.clean() + + # declare suspension in the future + suspension.start_at = today + relativedelta(days=2) + suspension.end_at = end_at + with self.assertRaises(ValidationError): + suspension.clean() + def test_duration(self): expected_duration = datetime.timedelta(days=2) start_at = timezone.now().date()