Skip to content

Commit

Permalink
reprise requete recherche de taxons dans synthese + test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrieuclp committed Jul 29, 2024
1 parent 55c1f66 commit 392b23e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pypnnomenclature.models import BibNomenclaturesTypes, TNomenclatures
from werkzeug.exceptions import Forbidden, NotFound, BadRequest, Conflict
from werkzeug.datastructures import MultiDict
from sqlalchemy import distinct, func, desc, asc, select, case
from sqlalchemy import distinct, func, desc, asc, select, case, or_
from sqlalchemy.orm import joinedload, lazyload, selectinload, contains_eager
from geojson import FeatureCollection, Feature
import sqlalchemy as sa
Expand Down Expand Up @@ -987,6 +987,9 @@ def get_autocomplete_taxons_synthese():
:query str group2_inpn : filter with INPN group 2
"""
search_name = request.args.get("search_name", "")

TaxrefSearchResult = aliased(Taxref)
TaxrefSynthese = aliased(Taxref)
query = (
select(
VMTaxrefListForautocomplete,
Expand All @@ -995,7 +998,9 @@ def get_autocomplete_taxons_synthese():
),
)
.distinct()
.join(Synthese, Synthese.cd_nom == VMTaxrefListForautocomplete.cd_nom)
.join(TaxrefSearchResult, TaxrefSearchResult.cd_nom == VMTaxrefListForautocomplete.cd_nom)
.join(TaxrefSynthese, or_(TaxrefSearchResult.cd_nom == TaxrefSynthese.cd_nom, TaxrefSearchResult.cd_nom == TaxrefSynthese.cd_ref))
.join(Synthese, Synthese.cd_nom == TaxrefSynthese.cd_nom)
)
search_name = search_name.replace(" ", "%")
query = query.where(
Expand Down
9 changes: 9 additions & 0 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,15 @@ def test_get_autocomplete_taxons_synthese(self, synthese_data, users):
assert response.status_code == 200
assert response.json[0]["cd_nom"] == synthese_data["obs1"].cd_nom

#recherche par le nom valide d'un taxon, alors que seul un synonyme est présent en synthese
response = self.client.get(
url_for("gn_synthese.get_autocomplete_taxons_synthese"),
query_string={"search_name": taxon.nom_valide},
)

assert response.status_code == 200
assert response.json[0]["cd_nom"] == taxon.cd_ref and response.json[0]["cd_nom"] != synthese_data["obs1"].cd_nom


@pytest.fixture(scope="class")
def synthese_module():
Expand Down

0 comments on commit 392b23e

Please sign in to comment.