Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Recherche] Remonter les prestataires qui ont un logo #913

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lemarche/www/siaes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,26 @@ def order_queryset(self, qs):
- push siae to update their profile, and have the freshest data at the top
- we tried random order ("?"), but it had some bugs with pagination
**BUT**
- if a Siae has a a SiaeOffer, or a description, or a User, then it is "boosted"
- if a Siae has a a SiaeOffer, or a description, or a logo, or a User, then it is "boosted"
- if the search is on a CITY perimeter, we order by coordinates first
- if the search is by keyword, order by "similarity" only
"""
DEFAULT_ORDERING = ["-updated_at"]
ORDER_BY_FIELDS = ["-has_offer", "-has_description", "-has_user"] + DEFAULT_ORDERING
ORDER_BY_FIELDS = ["-has_offer", "-has_description", "-has_logo", "-has_user"] + DEFAULT_ORDERING
# annotate on description presence: https://stackoverflow.com/a/65014409/4293684
# qs = qs.annotate(has_description=Exists(F("description"))) # doesn't work
qs = qs.annotate(
has_offer=Case(
When(offer_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
)
qs = qs.annotate(
has_description=Case(
When(description__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
)
qs = qs.annotate(
has_offer=Case(
When(offer_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField()
)
has_logo=Case(When(logo_url__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField())
)
qs = qs.annotate(
has_user=Case(When(user_count__gte=1, then=Value(True)), default=Value(False), output_field=BooleanField())
Expand Down
21 changes: 15 additions & 6 deletions lemarche/www/siaes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,35 +1016,44 @@ def test_should_order_by_last_updated(self):
self.assertEqual(siaes[0].name, "ABC Insertion")

def test_should_bring_the_siae_with_users_to_the_top(self):
siae_with_user = SiaeFactory(name="ZZ ESI")
siae_with_user = SiaeFactory(name="ZZ ESI user")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi tu ne mets pas les factories dans le setUpTestData ? Ça permettrait de vérifier que les structures avec description passent bien devant celles avec logo.

Copy link
Contributor Author

@raphodn raphodn Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait ici il y a plusieurs tests quasi identiques, où l'on créé des structures avec logo, mais aussi avec description ou avec offer ou avec user, et on s'assure qu'elle remonte au dessus.
Donc si on les créé dans le setUpTestData ca serait compliqué à tester chaque cas de figure ensuite

user = UserFactory()
siae_with_user.users.add(user)
url = reverse("siae:search_results", kwargs={})
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 3 + 1)
self.assertEqual(siaes[0].has_user, True)
self.assertEqual(siaes[0].name, "ZZ ESI")
self.assertEqual(siaes[0].name, "ZZ ESI user")

def test_should_bring_the_siae_with_logos_to_the_top(self):
SiaeFactory(name="ZZ ESI logo", logo_url="https://logo.png")
url = reverse("siae:search_results", kwargs={})
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 3 + 1)
self.assertEqual(siaes[0].has_logo, True)
self.assertEqual(siaes[0].name, "ZZ ESI logo")

def test_should_bring_the_siae_with_descriptions_to_the_top(self):
SiaeFactory(name="ZZ ESI 2", description="coucou")
SiaeFactory(name="ZZ ESI description", description="coucou")
url = reverse("siae:search_results", kwargs={})
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 3 + 1)
self.assertEqual(siaes[0].has_description, True)
self.assertEqual(siaes[0].name, "ZZ ESI 2")
self.assertEqual(siaes[0].name, "ZZ ESI description")

def test_should_bring_the_siae_with_offers_to_the_top(self):
siae_with_offer = SiaeFactory(name="ZZ ESI 3")
siae_with_offer = SiaeFactory(name="ZZ ESI offer")
SiaeOfferFactory(siae=siae_with_offer)
siae_with_offer.save() # to update the siae count fields
url = reverse("siae:search_results", kwargs={})
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 3 + 1)
self.assertEqual(siaes[0].has_offer, True)
self.assertEqual(siaes[0].name, "ZZ ESI 3")
self.assertEqual(siaes[0].name, "ZZ ESI offer")

def test_should_bring_the_siae_closer_to_the_city_to_the_top(self):
SiaeFactory(
Expand Down