Skip to content

Commit

Permalink
Merge pull request #71 from observerly/feature/query/constellationSea…
Browse files Browse the repository at this point in the history
…rchFilter
  • Loading branch information
michealroberts committed Jan 21, 2023
2 parents fcf96e1 + f23d6b4 commit 2860f15
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/crud/crud_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ def perform_constellation_search_filter(
constellation = getattr(query_params, "constellation", None)

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

return query

Expand Down
45 changes: 45 additions & 0 deletions app/tests/api/api_v1/test_bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,51 @@ async def test_list_bodies_within_the_constellation_orion(client: AsyncClient) -
assert body["results"][19]["name"] == "ο² Orionis"


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

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

assert response.status_code == 200

body = response.json()

assert body["count"] == 88
assert (
"https://perseus.docker.localhost/api/v1/bodies/2?limit=20&constellation=ori"
in body["next_page"]
)
assert body["previous_page"] is None
assert len(body["results"]) == 20

assert body["results"][0]["name"] == "Great Orion Nebula"
assert body["results"][1]["name"] == "Casper the Friendly Ghost Nebula"
assert body["results"][2]["name"] == "Da Mairan's Nebula"
assert body["results"][3]["name"] == "β Orionis"
assert body["results"][4]["name"] == "α Orionis"
assert body["results"][5]["name"] == "γ Orionis"
assert body["results"][9]["name"] == "δ Orionis"
assert body["results"][6]["name"] == "ε Orionis"
assert body["results"][7]["name"] == "ζ Orionis"
assert body["results"][10]["name"] == "ι Orionis"
assert body["results"][8]["name"] == "κ Orionis"
assert body["results"][11]["name"] == "π³ Orionis"
assert body["results"][12]["name"] == "η Orionis"
assert body["results"][13]["name"] == "λ Orionis"
assert body["results"][14]["name"] == "τ Orionis"
assert body["results"][15]["name"] == "π⁴ Orionis"
assert body["results"][16]["name"] == "π⁵ Orionis"
assert body["results"][17]["name"] == "ζ Orionis"
assert body["results"][18]["name"] == "σ Orionis"
assert body["results"][19]["name"] == "ο² Orionis"


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

0 comments on commit 2860f15

Please sign in to comment.