From 55fc4db4e0a7d70dd38ad5f1bc0562e96a837cbe Mon Sep 17 00:00:00 2001
From: Raphael Odini {{ tender.cta_card_paragraph_text|safe }}{{ tender.cta_card_title_text|safe }}
diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index aed0ecbcb..0156ad522 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -99,16 +99,16 @@ def _check_every_step(self, tenders_step_data, final_redirect_page: str = revers ) def test_anyone_can_access_create_tender(self): - # anonymous + # anonymous user url = reverse("tenders:create") response = self.client.get(url) self.assertEqual(response.status_code, 200) - # buyer + # user buyer self.client.force_login(self.user_buyer) url = reverse("tenders:create") response = self.client.get(url) self.assertEqual(response.status_code, 200) - # siae + # user siae self.client.force_login(self.user_siae) url = reverse("tenders:create") response = self.client.get(url) @@ -573,9 +573,13 @@ 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_4 = SiaeFactory(name="ESAT 4") + cls.siae_5 = SiaeFactory(name="ESAT 5") 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_3]) - cls.siae_user_3 = UserFactory(kind=User.KIND_SIAE) + cls.siae_user_4 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_4]) + cls.siae_user_5 = UserFactory(kind=User.KIND_SIAE, siaes=[cls.siae_5]) + cls.siae_user_without_siae = 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) cls.user_partner = UserFactory(kind=User.KIND_PARTNER) @@ -610,6 +614,15 @@ def setUpTestData(cls): detail_display_date=timezone.now(), detail_contact_click_date=timezone.now(), ) + cls.tendersiae_1_4 = TenderSiae.objects.create( + tender=cls.tender_1, + siae=cls.siae_4, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_not_interested_click_date=timezone.now(), + ) TenderQuestionFactory(tender=cls.tender_1) cls.tender_2 = TenderFactory( author=cls.user_buyer_1, @@ -617,19 +630,45 @@ def setUpTestData(cls): status=tender_constants.STATUS_SENT, first_sent_at=timezone.now(), ) + cls.tender_3_response_is_anonymous = TenderFactory( + author=cls.user_buyer_1, + contact_company_name="Another company", + status=tender_constants.STATUS_SENT, + first_sent_at=timezone.now(), + response_is_anonymous=True, + ) + cls.tendersiae_3_1 = TenderSiae.objects.create( + tender=cls.tender_3_response_is_anonymous, + siae=cls.siae_1, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_contact_click_date=timezone.now(), + ) + cls.tendersiae_3_4 = TenderSiae.objects.create( + tender=cls.tender_3_response_is_anonymous, + siae=cls.siae_4, + source="EMAIL", + email_send_date=timezone.now(), + email_link_click_date=timezone.now(), + detail_display_date=timezone.now(), + detail_not_interested_click_date=timezone.now(), + ) def test_anyone_can_view_sent_tenders(self): - # 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, "Voir l'appel d'offres") - # users - for user in User.objects.all(): - self.client.force_login(user) - url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + for tender in Tender.objects.all(): + # anonymous user + url = reverse("tenders:detail", kwargs={"slug": tender.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 200) + self.assertContains(response, tender.title) + # users + for user in User.objects.all(): + self.client.force_login(user) + url = reverse("tenders:detail", kwargs={"slug": tender.slug}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) def test_only_author_or_admin_can_view_non_sent_tender(self): tender_draft = TenderFactory(author=self.user_buyer_1, status=tender_constants.STATUS_DRAFT) @@ -643,7 +682,7 @@ def test_only_author_or_admin_can_view_non_sent_tender(self): validated_at=timezone.now(), ) for tender in [tender_draft, tender_published, tender_validated_but_not_sent]: - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": tender.slug}) response = self.client.get(url) self.assertEqual(response.status_code, 302) @@ -757,18 +796,18 @@ def test_tender_author_has_additional_stats(self): self.client.force_login(self.user_buyer_1) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "1 prestataire ciblé") + self.assertContains(response, "2 prestataires ciblés") self.assertContains(response, "1 prestataire intéressé") # but hidden for non-author self.client.force_login(self.user_buyer_2) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertNotContains(response, "1 prestataire ciblé") + self.assertNotContains(response, "2 prestataires ciblés") self.assertNotContains(response, "1 prestataire intéressé") def test_admin_has_extra_info(self): url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) - # anonymous + # anonymous user response = self.client.get(url) self.assertNotContains(response, "Informations Admin") # other users @@ -782,7 +821,7 @@ def test_admin_has_extra_info(self): self.assertContains(response, "Informations Admin") def test_tender_contact_display(self): - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Clôturé") @@ -793,13 +832,20 @@ def test_tender_contact_display(self): response = self.client.get(url) self.assertContains(response, "Contactez le client dès maintenant") self.assertNotContains(response, "Voir l'appel d'offres") + # siae user not interested + self.client.force_login(self.siae_user_4) + url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertContains(response, "Vous n'êtes pas intéressé par ce besoin") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Voir l'appel d'offres") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "veuillez d'abord vous") @@ -811,6 +857,45 @@ def test_tender_contact_display(self): self.assertContains(response, "Coordonnées") self.assertNotContains(response, "Voir l'appel d'offres") + def test_tender_response_is_anonymous_contact_display(self): + # anonymous user + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Clôturé") + self.assertNotContains(response, "Voir l'appel d'offres") + # siae user interested + self.client.force_login(self.siae_user_1) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertContains(response, "Votre intérêt a été signalé au client") + # siae user not interested + self.client.force_login(self.siae_user_4) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Contactez le client dès maintenant") + self.assertNotContains(response, "Voir l'appel d'offres") + self.assertNotContains(response, "Votre intérêt a été signalé au client") + self.assertContains(response, "Vous n'êtes pas intéressé par ce besoin") + # siae user not concerned + self.client.force_login(self.siae_user_5) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "Voir l'appel d'offres") + # siae user without siae + self.client.force_login(self.siae_user_without_siae) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertNotContains(response, "veuillez d'abord vous") + self.assertNotContains(response, "Voir l'appel d'offres") + # author + self.client.force_login(self.user_buyer_1) + url = reverse("tenders:detail", kwargs={"slug": self.tender_3_response_is_anonymous.slug}) + response = self.client.get(url) + self.assertContains(response, "Coordonnées") + self.assertNotContains(response, "Voir l'appel d'offres") + def test_tender_outdated_contact_display(self): tender_2 = TenderFactory( kind=tender_constants.KIND_QUOTE, @@ -818,7 +903,7 @@ def test_tender_outdated_contact_display(self): deadline_date=timezone.now() - timedelta(days=1), ) TenderSiae.objects.create(tender=tender_2, siae=self.siae_1, detail_contact_click_date=timezone.now()) - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") @@ -831,13 +916,13 @@ def test_tender_outdated_contact_display(self): self.assertNotContains(response, "Contactez le client dès maintenant") self.assertNotContains(response, "Répondre à cette opportunité") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") self.assertNotContains(response, "Répondre à cette opportunité") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": tender_2.slug}) response = self.client.get(url) self.assertContains(response, "Clôturé") @@ -965,11 +1050,11 @@ def test_tender_contact_details_display(self): self.assertContains(response, "Lien partagé") def test_tender_cocontracting_display(self): - # anonymous + # anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") - # anonymous but with siae_id in url + # anonymous user but with siae_id in url url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(f"{url}?siae_id=15") self.assertContains(response, "Répondre en co-traitance ?") @@ -979,7 +1064,7 @@ def test_tender_cocontracting_display(self): response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") # siae user not concerned - self.client.force_login(self.siae_user_2) + self.client.force_login(self.siae_user_5) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertContains(response, "Répondre en co-traitance ?") @@ -990,7 +1075,7 @@ def test_tender_cocontracting_display(self): response = self.client.get(url) self.assertContains(response, "Répondre en co-traitance ?") # siae user without siae - self.client.force_login(self.siae_user_3) + self.client.force_login(self.siae_user_without_siae) url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) self.assertNotContains(response, "Répondre en co-traitance ?") @@ -1002,92 +1087,92 @@ def test_tender_cocontracting_display(self): 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.count(), 2 + 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 + # first load anonymous user 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= + self.assertContains(response, "Déjà 2 prestataires inclusifs") + # reload anonymous user with ?siae_id= (already in tendersiae) 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.count(), 3) # 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.assertContains(response, "Déjà 3 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.count(), 3) # 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.assertContains(response, "Déjà 3 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.count(), 3) # 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.assertContains(response, "Déjà 3 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.count(), 2 + 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 + # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "Déjà 1 prestataire inclusif") + self.assertContains(response, "Déjà 2 prestataires inclusifs") # 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.count(), 2 + 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") + self.assertContains(response, "Déjà 3 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 + self.assertEqual(self.tender_1.tendersiae_set.count(), 2) + self.assertEqual(self.tender_1.tendersiae_set.first().siae, self.siae_4) + self.assertIsNotNone(self.tender_1.tendersiae_set.first().detail_display_date) # siae_4 + # first load anonymous user url = reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) response = self.client.get(url) - self.assertContains(response, "Déjà 1 prestataire inclusif") + self.assertContains(response, "Déjà 2 prestataires inclusifs") # 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.count(), 2 + 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") + self.assertContains(response, "Déjà 4 prestataires inclusifs") class TenderDetailContactClickStatViewTest(TestCase): diff --git a/lemarche/www/tenders/views.py b/lemarche/www/tenders/views.py index 738f4a3c9..62e614376 100644 --- a/lemarche/www/tenders/views.py +++ b/lemarche/www/tenders/views.py @@ -377,6 +377,9 @@ def get_context_data(self, **kwargs): context["siae_has_detail_contact_click_date"] = TenderSiae.objects.filter( tender=self.object, siae_id=int(self.siae_id), detail_contact_click_date__isnull=False ).exists() + context["siae_has_detail_not_interested_click_date"] = TenderSiae.objects.filter( + tender=self.object, siae_id=int(self.siae_id), detail_not_interested_click_date__isnull=False + ).exists() if user.is_authenticated: if user.kind == User.KIND_SIAE: context["siae_has_detail_contact_click_date"] = ( @@ -385,6 +388,12 @@ def get_context_data(self, **kwargs): tender=self.object, siae__in=user.siaes.all(), detail_contact_click_date__isnull=False ).exists() ) + context["siae_has_detail_not_interested_click_date"] = ( + getattr(context, "siae_has_detail_not_interested_click_date", None) + or TenderSiae.objects.filter( + tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=False + ).exists() + ) if show_nps: context["show_nps"] = True elif user.kind == User.KIND_PARTNER: