Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 22, 2024
1 parent 66d2b0e commit e67af16
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lemarche/templates/tenders/_detail_cta.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h3>{{ tender.cta_card_title_text|safe }}</h3>
<p>{{ tender.cta_card_paragraph_text|safe }}</p>

{% if user_can_click %}
{% if tender_is_anonymous %}
{% if tender_response_is_anonymous %}
<form method="POST" action="{% url 'tenders:detail-contact-click-stat' tender.slug %}?siae_id={{ siae_id }}">
{% csrf_token %}
<button type="submit" class="btn btn-primary btn-block" name="detail_contact_click_confirm" value="true">{{ tender.cta_card_button_text|safe }}</button>
Expand Down
2 changes: 1 addition & 1 deletion lemarche/templates/tenders/_detail_sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% else %}
{% if user.is_authenticated or siae_id %}
{% if not siae_has_detail_contact_click_date %}
{% include "tenders/_detail_cta.html" with tender=tender user_can_click=True tender_is_anonymous=True %}
{% include "tenders/_detail_cta.html" with tender=tender user_can_click=True tender_response_is_anonymous=True %}
{% else %}
{% include "tenders/_detail_success_contact.html" %}
{% endif %}
Expand Down
10 changes: 4 additions & 6 deletions lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
{% if not tender.deadline_date_outdated and not tender.response_is_anonymous %}
{% if siae_has_detail_contact_click_date %}
<div class="row">
{% if not tender.response_is_anonymous %}
<div class="col-12 col-lg-8">
<div class="alert alert-info fade show" role="status">
{% include "tenders/_detail_contact.html" with tender=tender source="alert" %}
</div>
<div class="col-12 col-lg-8">
<div class="alert alert-info fade show" role="status">
{% include "tenders/_detail_contact.html" with tender=tender source="alert" %}
</div>
{% endif %}
</div>
<div class="col-12 col-lg-4">
<div class="alert alert-info mt-3 mt-lg-0" role="alert">
<p class="mb-1">
Expand Down
92 changes: 70 additions & 22 deletions lemarche/www/tenders/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -617,19 +617,36 @@ 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(),
)

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)
Expand All @@ -643,7 +660,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)
Expand Down Expand Up @@ -768,7 +785,7 @@ def test_tender_author_has_additional_stats(self):

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
Expand All @@ -782,7 +799,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é")
Expand Down Expand Up @@ -811,14 +828,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 concerned
self.client.force_login(self.siae_user_2)
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_3)
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,
author=self.user_buyer_1,
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é")
Expand Down Expand Up @@ -965,11 +1013,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 ?")
Expand Down Expand Up @@ -1009,12 +1057,12 @@ def test_update_tendersiae_stats_on_tender_view(self):
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=
# reload anonymous user 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)
Expand Down Expand Up @@ -1055,7 +1103,7 @@ def test_create_tendersiae_stats_on_tender_view_by_existing_user(self):
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")
Expand All @@ -1074,7 +1122,7 @@ 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
# 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")
Expand Down

0 comments on commit e67af16

Please sign in to comment.