diff --git a/src/ref_geo/routes.py b/src/ref_geo/routes.py index 460354c..3cb6a50 100644 --- a/src/ref_geo/routes.py +++ b/src/ref_geo/routes.py @@ -210,17 +210,19 @@ def get_areas(): query = query.where(LAreas.enable == True) if "id_type" in params: - query = query.where(LAreas.id_type.in_(params.getlist("id_type"))) + # getlist() of request.args does not use the syntax url?param=val1,val2 + id_type = params.get("id_type").split(",") + query = query.where(LAreas.id_type.in_(id_type)) if "type_code" in params: - query = query.where( - LAreas.area_type.has(BibAreasTypes.type_code.in_(params.getlist("type_code"))) - ) + # getlist() of request.args does not use the syntax url?param=val1,val2 + type_code = params.get("type_code").split(",") + query = query.where(LAreas.area_type.has(BibAreasTypes.type_code.in_(type_code))) if "area_name" in params: query = query.where(LAreas.area_name.ilike("%{}%".format(params.get("area_name")))) - without_geom = params.get("without_geom", False, lambda x: x == "true") + without_geom = request.args.get("without_geom", False, lambda x: x == "true") if without_geom: query = query.options(defer("geom")) marsh_params["exclude"] = ["geom"] diff --git a/src/ref_geo/tests/test_ref_geo.py b/src/ref_geo/tests/test_ref_geo.py index d490445..d54280e 100644 --- a/src/ref_geo/tests/test_ref_geo.py +++ b/src/ref_geo/tests/test_ref_geo.py @@ -46,6 +46,11 @@ def area_commune(): return db.session.execute(select(BibAreasTypes).filter_by(type_code="COM")).scalar_one() +@pytest.fixture(scope="function") +def area_departement(): + return db.session.execute(select(BibAreasTypes).filter_by(type_code="DEP")).scalar_one() + + @pytest.mark.usefixtures("client_class", "temporary_transaction") class TestRefGeo: expected_altitude = pytest.approx({"altitude_min": 984, "altitude_max": 2335}, rel=1e-2) @@ -290,6 +295,20 @@ def test_get_areas_type_code(self, area_commune): assert response.status_code == 200 assert all(area["id_type"] == area_commune.id_type for area in response.json) + def test_get_areas_type_codes(self, area_commune, area_departement): + + type_codes = [area_commune.type_code, area_departement.type_code] + + response = self.client.get( + url_for("ref_geo.get_areas"), query_string={"type_code": ",".join(type_codes)} + ) + + assert response.status_code == 200 + assert all( + area["id_type"] in [area_commune.id_type, area_departement.id_type] + for area in response.json + ) + def test_get_areas_area_name(self): response = self.client.get(url_for("ref_geo.get_areas"), query_string={"area_name": CITY})