Skip to content

Commit

Permalink
Search without accents
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Jul 20, 2023
1 parent 29d6544 commit 40d373c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class GTEventsQuery(BaseQuery):
def filter_properties(self, filters):
if filters.get("search_name", None):
search_name = filters.get("search_name", None)
self = self.filter(GTEvents.name.ilike(f"%{search_name}%"))
self = self.filter(
func.unaccent(GTEvents.name).ilike(func.unaccent(f"%{search_name}%"))
)
filters.pop("search_name")

if "begin_date" in filters:
Expand Down
13 changes: 13 additions & 0 deletions backend/test/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
"published_en": True,
"bookable": False,
},
{
# id:
"name": "Pytest avec accents àeù öhôh",
"capacity": None,
"begin_date": "01/07/2023",
"end_date": "01/10/2023",
"published": True,
"x": 765227.4922990737,
"y": 6365673.938623513,
"published_fr": True,
"published_en": True,
"bookable": False,
},
]


Expand Down
8 changes: 8 additions & 0 deletions backend/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ def test_get_events(self):
)
assert response.status_code == 200

def test_get_events_search_name(self):
for search_name in ["ohoh", "öhôh"]:
response = self.client.get(
url_for("app_routes.get_events", search_name=search_name)
)
assert response.status_code == 200
assert len(json.loads(response.data)["results"]) > 1

def test_get_one_event(self, events):
data = GTEvents.query.limit(1).one()
assert (
Expand Down

0 comments on commit 40d373c

Please sign in to comment.