From 4e5f5ebbc2763e59ddc9a3fa45890e67438f3fe7 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Thu, 7 Mar 2024 16:00:34 +0100 Subject: [PATCH] Add tests --- lemarche/tenders/constants.py | 15 ++++++++----- lemarche/tenders/models.py | 40 +++++++++++++++++------------------ lemarche/tenders/tests.py | 31 ++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/lemarche/tenders/constants.py b/lemarche/tenders/constants.py index 558340714..a0efc6165 100644 --- a/lemarche/tenders/constants.py +++ b/lemarche/tenders/constants.py @@ -168,14 +168,19 @@ ] TENDER_SIAE_STATUS_EMAIL_SEND_DATE = "EMAIL_SEND_DATE" +TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY = "Contactée" TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE = "EMAIL_LINK_CLICK_DATE" +TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY = "Cliquée" TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE = "DETAIL_DISPLAY_DATE" +TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY = "Vue" TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE = "DETAIL_CONTACT_CLICK_DATE" +TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY = "Intéressée" TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE = "DETAIL_NOT_INTERESTED_CLICK_DATE" +TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY = "Pas intéressée" TENDER_SIAE_STATUS_CHOICES = ( - (TENDER_SIAE_STATUS_EMAIL_SEND_DATE, "Contactée"), - (TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE, "Cliquée"), - (TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE, "Vue"), - (TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, "Intéressée"), - (TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE, "Pas intéressée"), + (TENDER_SIAE_STATUS_EMAIL_SEND_DATE, TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY), + (TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE, TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE, TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY), + (TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE, TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY), ) diff --git a/lemarche/tenders/models.py b/lemarche/tenders/models.py index c9838d5c4..f1ce38159 100644 --- a/lemarche/tenders/models.py +++ b/lemarche/tenders/models.py @@ -912,20 +912,6 @@ def __str__(self): class TenderSiaeQuerySet(models.QuerySet): - def email_click_reminder(self, gte_days_ago, lt_days_ago): - return ( - self.filter(email_send_date__gte=gte_days_ago) - .filter(email_send_date__lt=lt_days_ago) - .filter(email_link_click_date__isnull=True) - .filter(detail_display_date__isnull=True) - .filter(detail_contact_click_date__isnull=True) - ) - - def detail_contact_click_post_reminder(self, gte_days_ago, lt_days_ago): - return self.filter(detail_contact_click_date__gte=gte_days_ago).filter( - detail_contact_click_date__lt=lt_days_ago - ) - def with_prefetch_related(self): return self.prefetch_related("tender", "siae") @@ -953,6 +939,20 @@ def with_status(self): ) ) + def email_click_reminder(self, gte_days_ago, lt_days_ago): + return ( + self.filter(email_send_date__gte=gte_days_ago) + .filter(email_send_date__lt=lt_days_ago) + .filter(email_link_click_date__isnull=True) + .filter(detail_display_date__isnull=True) + .filter(detail_contact_click_date__isnull=True) + ) + + def detail_contact_click_post_reminder(self, gte_days_ago, lt_days_ago): + return self.filter(detail_contact_click_date__gte=gte_days_ago).filter( + detail_contact_click_date__lt=lt_days_ago + ) + class TenderSiae(models.Model): FIELDS_RELATION = [ @@ -1032,15 +1032,15 @@ class Meta: @property def status(self): if self.detail_not_interested_click_date: - return "Pas intéressée" - if self.contact_click_date: - return "Intéressée" + return tender_constants.TENDER_SIAE_STATUS_DETAIL_NOT_INTERESTED_CLICK_DATE_DISPLAY + if self.detail_contact_click_date: + return tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY if self.detail_display_date: - return "Vue" + return tender_constants.TENDER_SIAE_STATUS_DETAIL_DISPLAY_DATE_DISPLAY if self.email_link_click_date: - return "Cliquée" + return tender_constants.TENDER_SIAE_STATUS_EMAIL_LINK_CLICK_DATE_DISPLAY if self.email_send_date: - return "Contactée" + return tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY class PartnerShareTenderQuerySet(models.QuerySet): diff --git a/lemarche/tenders/tests.py b/lemarche/tenders/tests.py index 5453ae288..bbdcab9d1 100644 --- a/lemarche/tenders/tests.py +++ b/lemarche/tenders/tests.py @@ -775,7 +775,7 @@ def test_tender_partner_is_active(self): self.assertEqual(len(result_2), 4 + 1) -class TenderSiaeModelQuerysetTest(TestCase): +class TenderSiaeModelAndQuerysetTest(TestCase): @classmethod def setUpTestData(cls): cls.user_siae = UserFactory(kind=User.KIND_SIAE) @@ -788,20 +788,20 @@ def setUpTestData(cls): cls.tender_with_siae_1 = TenderFactory( siaes=[cls.siae_with_tender_1, siae_with_tender_2], deadline_date=date_tomorrow ) - TenderSiae.objects.create( + cls.tendersiae_1 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_3, email_send_date=date_last_week ) - TenderSiae.objects.create( + cls.tendersiae_2 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_4, email_send_date=date_two_days_ago ) - TenderSiae.objects.create( + cls.tendersiae_3 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_5, email_send_date=date_two_days_ago, email_link_click_date=date_two_days_ago, detail_contact_click_date=date_two_days_ago, ) - TenderSiae.objects.create( + cls.tendersiae_4 = TenderSiae.objects.create( tender=cls.tender_with_siae_1, siae=siae_with_tender_5, detail_display_date=date_last_week, @@ -811,6 +811,17 @@ def setUpTestData(cls): siaes=[siae_with_tender_2, siae_with_tender_3], deadline_date=date_tomorrow ) + def test_with_status(self): + tendersiae_queryset = TenderSiae.objects.with_status() + self.assertEqual( + tendersiae_queryset.get(id=self.tendersiae_1.id).status_annotated, + tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE, + ) + self.assertEqual( + tendersiae_queryset.get(id=self.tendersiae_4.id).status_annotated, + tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE, + ) + def test_email_click_reminder(self): lt_days_ago = timezone.now() - timedelta(days=2) gte_days_ago = timezone.now() - timedelta(days=2 + 1) @@ -830,6 +841,16 @@ def test_detail_contact_click_post_reminder(self): 1, ) + def test_status_property(self): + self.assertEqual( + TenderSiae.objects.get(id=self.tendersiae_1.id).status, + tender_constants.TENDER_SIAE_STATUS_EMAIL_SEND_DATE_DISPLAY, + ) + self.assertEqual( + TenderSiae.objects.get(id=self.tendersiae_4.id).status, + tender_constants.TENDER_SIAE_STATUS_DETAIL_CONTACT_CLICK_DATE_DISPLAY, + ) + class TenderAdminTest(TestCase): def setUp(cls):