Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Mar 8, 2024
1 parent 68c5e38 commit 39bce20
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 30 deletions.
15 changes: 10 additions & 5 deletions lemarche/tenders/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,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),
)
40 changes: 20 additions & 20 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -969,6 +955,20 @@ def unread_stats(self, user):
.aggregate(**aggregates)
)

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 = [
Expand Down Expand Up @@ -1048,15 +1048,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):
Expand Down
31 changes: 26 additions & 5 deletions lemarche/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -790,20 +790,20 @@ def setUpTestData(cls):
deadline_date=date_tomorrow,
kind=tender_constants.KIND_TENDER,
)
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,
Expand All @@ -813,6 +813,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)
Expand All @@ -838,6 +849,16 @@ def test_unread_stats(self):
self.assertEqual(stats[f"unread_count_{tender_constants.KIND_QUOTE}_annotated"], 1)
self.assertEqual(stats[f"unread_count_{tender_constants.KIND_PROJECT}_annotated"], 0)

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):
Expand Down

0 comments on commit 39bce20

Please sign in to comment.