From 22d0a1882145a09f276b464c3f7bea9e3f103c8f Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Wed, 27 Mar 2024 11:40:12 +0100 Subject: [PATCH] Add test --- lemarche/www/tenders/tests.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lemarche/www/tenders/tests.py b/lemarche/www/tenders/tests.py index 7b43bdab1..cfd46cf76 100644 --- a/lemarche/www/tenders/tests.py +++ b/lemarche/www/tenders/tests.py @@ -1148,18 +1148,34 @@ def test_update_tendersiae_stats_on_tender_view(self): response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertContains(response, "Déjà 3 prestataires inclusifs") - # reload anonymous user with ?siae_id= (already in tendersiae) + # 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(), 4) # 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().user) 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à 4 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) + # reload anonymous user with siae_id & user_id (already in tendersiae) + url = ( + reverse("tenders:detail", kwargs={"slug": self.tender_1.slug}) + + f"?siae_id={self.siae_2.id}&user_id={self.siae_user_2.id}" + ) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertEqual(self.tender_1.tendersiae_set.count(), 4) # 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.assertIsNotNone(self.tender_1.tendersiae_set.first().user) # user 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à 4 prestataires inclusifs") + self.assertNotContains(response, "contactez dès maintenant le client") + # reload logged in user with siae_id (updates 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)