Skip to content

Commit

Permalink
Correct region/subregion->name fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed Dec 21, 2024
1 parent 899e772 commit d633596
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/routes/thematic/geoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def _admin_boundary_lookup_sql(
f" WHERE country='{country_name}'"
)
if region_name is not None:
sql += f" AND WHERE region='{region_name}'"
sql += f" AND WHERE name_1='{region_name}'"
if subregion_name is not None:
sql += f" AND WHERE subregion='{subregion_name}'"
sql += f" AND WHERE name_2='{subregion_name}'"

return sql

Expand Down
33 changes: 28 additions & 5 deletions tests_v2/unit/app/routes/thematic/geoencoder/test_geoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,38 @@


@pytest.mark.asyncio
async def test__admin_boundary_lookup_sql() -> None:
async def test__admin_boundary_lookup_sql_country() -> None:
sql = _admin_boundary_lookup_sql(
"some_dataset", "some_country", None, None
)
assert sql == (
"SELECT gid_0, gid_1, gid_2, country, name_1, name_2 FROM some_dataset"
" WHERE country='some_country'"
)


@pytest.mark.asyncio
async def test__admin_boundary_lookup_sql_country_region() -> None:
sql = _admin_boundary_lookup_sql(
"some_dataset", "some_country", "some_region", None
)
assert sql == (
"SELECT gid_0, gid_1, gid_2, country, name_1, name_2 FROM some_dataset"
" WHERE country='some_country'"
" AND WHERE name_1='some_region'"
)


@pytest.mark.asyncio
async def test__admin_boundary_lookup_sql_all() -> None:
sql = _admin_boundary_lookup_sql(
"some_dataset", "some_country", "some_region", "some_subregion"
)
assert sql == (
"SELECT gid_0, gid_1, gid_2, country, name_1, name_2 FROM some_dataset "
"WHERE country='some_country' "
"AND WHERE region='some_region' "
"AND WHERE subregion='some_subregion'"
"SELECT gid_0, gid_1, gid_2, country, name_1, name_2 FROM some_dataset"
" WHERE country='some_country'"
" AND WHERE name_1='some_region'"
" AND WHERE name_2='some_subregion'"
)


Expand Down

0 comments on commit d633596

Please sign in to comment.