Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 29, 2024
1 parent 701c71e commit 6fee619
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ def setUpTestData(self):

def test_user_can_notify_cocontracting_wish_with_siae_id(self):
url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
# missing data
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
response = self.client.post(url, data={})
Expand All @@ -1326,8 +1327,6 @@ def test_user_can_notify_cocontracting_wish_with_siae_id(self):
)
mock_send_mail_async.assert_not_called()
self.assertIsNone(tendersiae.detail_cocontracting_click_date)

detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
response = self.client.get(detail_url)
self.assertContains(response, "Répondre en co-traitance ?")
self.assertNotContains(response, "Votre intérêt a bien été signalé au client.")
Expand All @@ -1346,13 +1345,12 @@ def test_user_can_notify_cocontracting_wish_with_siae_id(self):

def test_user_can_notify_cocontracting_wish_with_authenticated_user(self):
self.client.force_login(self.siae_user)

url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})

response = self.client.get(detail_url)
self.assertContains(response, "Répondre en co-traitance ?")
self.assertNotContains(response, "Votre intérêt a bien été signalé au client.")

url = reverse("tenders:detail-cocontracting-click", kwargs={"slug": self.tender.slug})
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNone(tendersiae.detail_cocontracting_click_date)
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
Expand All @@ -1363,11 +1361,9 @@ def test_user_can_notify_cocontracting_wish_with_authenticated_user(self):
email_body = mock_send_mail_async.call_args[1]["email_body"]
self.assertTrue(f"La structure {self.siae.name } souhaite répondre en co-traitance" in email_body)
self.assertIsNotNone(tendersiae.detail_cocontracting_click_date)

response = self.client.get(detail_url)
self.assertContains(response, "Votre intérêt a bien été signalé au client.")
self.assertNotContains(response, "Répondre en co-traitance ?")

user_without_siae = UserFactory(kind=User.KIND_SIAE)
self.client.force_login(user_without_siae)
with mock.patch("lemarche.www.tenders.tasks.send_mail_async") as mock_send_mail_async:
Expand Down Expand Up @@ -1406,6 +1402,7 @@ def setUpTestData(self):

def test_user_can_notify_not_interested_wish_with_siae_id(self):
url = reverse("tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
# missing data
response = self.client.post(url, data={})
self.assertEqual(response.status_code, 403)
Expand All @@ -1414,13 +1411,11 @@ def test_user_can_notify_not_interested_wish_with_siae_id(self):
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertContains(response, self.cta_message_error)
self.assertIsNone(tendersiae.detail_not_interested_click_date)

detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug}) + f"?siae_id={self.siae.id}"
# workflow
response = self.client.get(detail_url)
self.assertContains(response, self.cta_message)
self.assertNotContains(response, self.cta_message_success)

response = self.client.post(f"{url}?siae_id={self.siae.id}", data={})
response = self.client.post(f"{url}?siae_id={self.siae.id}", data={}, follow=True)
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertContains(response, self.cta_message_success)
self.assertIsNotNone(tendersiae.detail_not_interested_click_date)
Expand All @@ -1430,30 +1425,21 @@ def test_user_can_notify_not_interested_wish_with_siae_id(self):

def test_user_can_notify_not_interested_wish_with_authenticated_user(self):
self.client.force_login(self.siae_user)

url = reverse("tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug})
detail_url = reverse("tenders:detail", kwargs={"slug": self.tender.slug})
# workflow
response = self.client.get(detail_url)
self.assertContains(response, self.cta_message)
self.assertNotContains(response, self.cta_message_success)

url = reverse("tenders:detail-not-interested-click", kwargs={"slug": self.tender.slug})
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertIsNone(tendersiae.detail_not_interested_click_date)
response = self.client.post(url, data={"detail_not_interested_feedback": "reason"})
response = self.client.post(url, data={"detail_not_interested_feedback": "reason"}, follow=True)
tendersiae = TenderSiae.objects.get(tender=self.tender, siae=self.siae)
self.assertContains(response, self.cta_message_success)
self.assertIsNotNone(tendersiae.detail_not_interested_click_date)
self.assertEqual(tendersiae.detail_not_interested_feedback, "reason")

response = self.client.get(detail_url)
self.assertContains(response, self.cta_message_success)
self.assertNotContains(response, self.cta_message)

user_without_siae = UserFactory(kind=User.KIND_SIAE)
self.client.force_login(user_without_siae)
response = self.client.post(url, data={})
self.assertContains(response, self.cta_message_error)


# TODO: this test doesn't work anymore. find a way to test logging post-email in non-prod environments?
# class TenderTasksTest(TestCase):
Expand Down

0 comments on commit 6fee619

Please sign in to comment.