From c6bb6d567e873fe9d97626c55f5ac043f6c96b31 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 15 Nov 2023 12:26:38 +0100 Subject: [PATCH] Tender detail stats: add extra tests --- lemarche/www/tenders/tests.py | 154 ++++++++++++++++++++-------------- 1 file changed, 91 insertions(+), 63 deletions(-) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index b6bf94ec8..e5653c4dd 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -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) @@ -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}) @@ -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