Skip to content

Commit

Permalink
Merge pull request #70 from observerly/feature/query/nameSearchFilter
Browse files Browse the repository at this point in the history
feat: Added ability to query { name } column of Body with a sub-string.
  • Loading branch information
michealroberts authored Jan 20, 2023
2 parents 992c0a7 + e8b5a4a commit fcf96e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/crud/crud_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def perform_name_search_filter(

if name:
query = query.filter(
or_(self.model.name.op("LIKE")(name), self.model.iau.op("LIKE")(name))
or_(
self.model.name.op("LIKE")("%{0}%".format(name)),
self.model.iau.op("LIKE")("%{0}%".format(name)),
)
)

return query
Expand Down
21 changes: 21 additions & 0 deletions app/tests/api/api_v1/test_bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ async def test_list_bodies_with_the_name_betelgeuse(client: AsyncClient) -> None
assert body["results"][0]["iau"] == "Betelgeuse"


@pytest.mark.asyncio
async def test_list_bodies_with_the_partial_name_betel(client: AsyncClient) -> None:
page = 1

response = await client.get(
f"{settings.API_V1_STR}/bodies/{page}?name=bete",
headers={"Host": "perseus.docker.localhost"},
)

assert response.status_code == 200

body = response.json()

assert body["count"] == 1
assert body["next_page"] is None
assert body["previous_page"] is None

assert body["results"][0]["name"] == "α Orionis"
assert body["results"][0]["iau"] == "Betelgeuse"


@pytest.mark.asyncio
async def test_list_bodies_with_specific_radial_search(client: AsyncClient) -> None:
page = 1
Expand Down

0 comments on commit fcf96e1

Please sign in to comment.