From f23d6b4f3c97edb0096012ff34def53b81bc4474 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Fri, 20 Jan 2023 12:56:44 +0000 Subject: [PATCH] feat: Added ability to query { constellation } column of Body with a sub-string. feat: Added ability to query { constellation } column of Body with a sub-string. Includes associated additions to test suite for module export definition and expected output. --- app/crud/crud_body.py | 7 ++++- app/tests/api/api_v1/test_bodies.py | 45 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/app/crud/crud_body.py b/app/crud/crud_body.py index cb1eef5..f04e446 100644 --- a/app/crud/crud_body.py +++ b/app/crud/crud_body.py @@ -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 diff --git a/app/tests/api/api_v1/test_bodies.py b/app/tests/api/api_v1/test_bodies.py index 7665be3..6c813af 100644 --- a/app/tests/api/api_v1/test_bodies.py +++ b/app/tests/api/api_v1/test_bodies.py @@ -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