Skip to content

Commit

Permalink
Tender detail stats: add extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 15, 2023
1 parent 5f14f83 commit c6bb6d5
Showing 1 changed file with 91 additions and 63 deletions.
154 changes: 91 additions & 63 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,9 @@ class TenderDetailViewTest(TestCase):
def setUpTestData(cls):
cls.siae_1 = SiaeFactory(name="ZZ ESI")
cls.siae_2 = SiaeFactory(name="ABC Insertion")
cls.siae_3 = SiaeFactory(name="ABC Insertion bis")
cls.siae_user_1 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_1])
cls.siae_user_2 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_2])
cls.siae_user_2 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_2, cls.siae_3])
cls.siae_user_3 = UserFactory(kind=User.KIND_SIAE)
cls.user_buyer_1 = UserFactory(kind=User.KIND_BUYER, company_name="Entreprise Buyer")
cls.user_buyer_2 = UserFactory(kind=User.KIND_BUYER)
Expand Down Expand Up @@ -659,68 +660,6 @@ def test_admin_has_extra_info(self):
response = self.client.get(url)
self.assertContains(response, "Informations Admin")

def test_update_tendersiae_stats_on_tender_view(self):
self.tender_1.siaes.add(self.siae_2)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2)
self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date)
self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
# first load anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Déjà 1 prestataire inclusif")
# reload anonymous with ?siae_id=
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}"
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
siae_2_email_link_click_date = self.tender_1.tendersiae_set.first().email_link_click_date
self.assertIsNotNone(siae_2_email_link_click_date)
self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")
# reload logged in (doesn't update email_link_click_date)
self.client.force_login(self.siae_user_2)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}"
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.first().email_link_click_date, siae_2_email_link_click_date)
siae_2_detail_display_date = self.tender_1.tendersiae_set.first().detail_display_date
self.assertIsNotNone(siae_2_detail_display_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")
# reload (doesn't update detail_display_date)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.first().detail_display_date, siae_2_detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")

def test_create_tendersiae_stats_on_tender_view_by_new_siae(self):
# self.tender_1.siaes.add(self.siae_2)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_1)
self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_1
# first load anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertContains(response, "Déjà 1 prestataire inclusif")
# first load
self.client.force_login(self.siae_user_2)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2)
self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")

def test_tender_contact_display(self):
# anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
Expand Down Expand Up @@ -940,6 +879,95 @@ def test_tender_cocontracting_display(self):
response = self.client.get(url)
self.assertNotContains(response, "Répondre en co-traitance ?")

def test_update_tendersiae_stats_on_tender_view(self):
self.tender_1.siaes.add(self.siae_2)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2)
self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date)
self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
# first load anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, "Déjà 1 prestataire inclusif")
# reload anonymous with ?siae_id=
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}"
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged
siae_2_email_link_click_date = self.tender_1.tendersiae_set.first().email_link_click_date
self.assertIsNotNone(siae_2_email_link_click_date) # email_link_click_date updated
self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")
# reload logged in with ?siae_id= (updats detail_display_date, but not email_link_click_date)
self.client.force_login(self.siae_user_2)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + f"?siae_id={self.siae_2.id}"
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged
self.assertEqual(self.tender_1.tendersiae_set.first().email_link_click_date, siae_2_email_link_click_date)
siae_2_detail_display_date = self.tender_1.tendersiae_set.first().detail_display_date
self.assertIsNotNone(siae_2_detail_display_date) # detail_display_date updated
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")
# reload (doesn't update detail_display_date)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 2) # unchanged
self.assertEqual(self.tender_1.tendersiae_set.first().detail_display_date, siae_2_detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")
self.assertNotContains(response, "contactez dès maintenant le client")

def test_create_tendersiae_stats_on_tender_view_by_existing_user(self):
self.tender_1.siaes.add(self.siae_2)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2)
self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date)
self.assertIsNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertEqual(self.tender_1.tendersiae_set.last().siae, self.siae_1)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().email_link_click_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.last().detail_display_date)
# first load anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertContains(response, "Déjà 1 prestataire inclusif")
# first load, new user has already 1 siae contacted, we update only this one
self.client.force_login(self.siae_user_2)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_2)
self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertContains(response, "Déjà 2 prestataires inclusifs")

def test_create_tendersiae_stats_on_tender_view_by_new_user(self):
self.assertEqual(self.tender_1.tendersiae_set.count(), 1)
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_1)
self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_1
# first load anonymous
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertContains(response, "Déjà 1 prestataire inclusif")
# first load, new user has 2 siaes
self.client.force_login(self.siae_user_2)
url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(self.tender_1.tendersiae_set.count(), 1 + 2) # adds both siae_2 & siae_3
self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_3)
self.assertIsNone(self.tender_1.tendersiae_set.first().email_link_click_date)
self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date)
self.assertContains(response, "Déjà 3 prestataires inclusifs")


class TenderDetailContactClickStatViewTest(TestCase):
@classmethod
Expand Down

0 comments on commit c6bb6d5

Please sign in to comment.