From 09fc56dc35d41eef420f735b9bd02df04ae50bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20No=C3=A9?= Date: Thu, 21 Nov 2024 09:55:27 +0100 Subject: [PATCH] Improved test coverage --- dashboard/models.py | 1 - dashboard/tests/models/test_observation.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dashboard/models.py b/dashboard/models.py index cca9a40..7e60079 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -390,7 +390,6 @@ def set_or_migrate_initial_data_import( @staticmethod def date_older_than_user_delay(user: WebsiteUser, the_date) -> bool: - # TODO: test this logic !! today = timezone.now().date() return the_date < ( diff --git a/dashboard/tests/models/test_observation.py b/dashboard/tests/models/test_observation.py index beeb4f1..c2a65f9 100644 --- a/dashboard/tests/models/test_observation.py +++ b/dashboard/tests/models/test_observation.py @@ -54,6 +54,7 @@ def setUp(self): first_name="John", last_name="Frusciante", email="frusciante@gmail.com", + notification_delay_days=365, # 1 year, the default value ) # comment_author has also an alert that match second_obs @@ -210,6 +211,21 @@ def test_mark_as_unseen_by_failure_3(self): observation=self.obs, user=self.comment_author ) + def test_date_older_than_user_delay(self): + """The method works as expected""" + yesterday = datetime.date.today() - datetime.timedelta(days=1) + + self.assertFalse( + self.obs.date_older_than_user_delay(self.comment_author, the_date=yesterday) + ) + + two_years_ago = datetime.date.today() - datetime.timedelta(days=365 * 2) + self.assertTrue( + self.obs.date_older_than_user_delay( + self.comment_author, the_date=two_years_ago + ) + ) + def test_replace_observation(self): """High-level test: after creating a new observation with the same stable_id, make sure we can migrate the linked entities then and then delete the initial observation"""