-
Notifications
You must be signed in to change notification settings - Fork 42
fix type for advanced freetext and allow free-text for Item search #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2fd8c8f
bb91b68
c0767f3
bbf0cb5
b5fdaba
947a977
eaf6dd8
af4b331
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| CollectionSearchExtension, | ||
| CollectionSearchFilterExtension, | ||
| FieldsExtension, | ||
| FreeTextAdvancedExtension, | ||
| FreeTextExtension, | ||
| ItemCollectionFilterExtension, | ||
| OffsetPaginationExtension, | ||
|
|
@@ -402,3 +403,58 @@ async def default_client(default_app): | |
| transport=ASGITransport(app=default_app), base_url="http://test" | ||
| ) as c: | ||
| yield c | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| async def app_advanced_freetext(database): | ||
| """Default stac-fastapi-pgstac application without only the transaction extensions.""" | ||
| api_settings = Settings(testing=True) | ||
|
|
||
| application_extensions = [ | ||
| TransactionExtension(client=TransactionsClient(), settings=api_settings) | ||
| ] | ||
|
|
||
| collection_extensions = [ | ||
| FreeTextAdvancedExtension(), | ||
| OffsetPaginationExtension(), | ||
| ] | ||
| collection_search_extension = CollectionSearchExtension.from_extensions( | ||
| collection_extensions | ||
| ) | ||
| application_extensions.append(collection_search_extension) | ||
|
|
||
| app = StacApi( | ||
| settings=api_settings, | ||
| extensions=application_extensions, | ||
| client=CoreCrudClient(), | ||
| health_check=health_check, | ||
| collections_get_request_model=collection_search_extension.GET, | ||
| ) | ||
|
|
||
| postgres_settings = PostgresSettings( | ||
| pguser=database.user, | ||
| pgpassword=database.password, | ||
| pghost=database.host, | ||
| pgport=database.port, | ||
| pgdatabase=database.dbname, | ||
| ) | ||
| logger.info("Creating app Fixture") | ||
| time.time() | ||
|
||
| await connect_to_db( | ||
| app.app, | ||
| postgres_settings=postgres_settings, | ||
| add_write_connection_pool=True, | ||
| ) | ||
| yield app.app | ||
| await close_db_connection(app.app) | ||
|
|
||
| logger.info("Closed Pools.") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| async def app_client_advanced_freetext(app_advanced_freetext): | ||
| logger.info("creating app_client") | ||
| async with AsyncClient( | ||
| transport=ASGITransport(app=app_advanced_freetext), base_url="http://test" | ||
| ) as c: | ||
| yield c | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no tests for the Also, there could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe this PR is meant to implement free-text item search, just correct some stuff around free-text collection search. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if you're passing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exactly, but it also enables free-text for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Good point about the Pydantic model. I'm not sure to understand the " I was able to activate it is my implementation (https://github.com/crim-ca/stac-app/pull/28/files). It should do the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I just mean that As mentioned in #263 (comment) it works only for Advanced because we don't do |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,6 +365,71 @@ async def test_collection_search_freetext( | |
| assert resp.json()["collections"][0]["id"] == load_test2_collection.id | ||
|
|
||
| resp = await app_client.get( | ||
| "/collections", | ||
| params={"q": "temperature,calibrated"}, | ||
| ) | ||
| assert resp.json()["numberReturned"] == 2 | ||
| assert resp.json()["numberMatched"] == 2 | ||
| assert len(resp.json()["collections"]) == 2 | ||
|
|
||
| resp = await app_client.get( | ||
| "/collections", | ||
| params={"q": "temperature,yo"}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| assert resp.json()["numberReturned"] == 1 | ||
| assert resp.json()["numberMatched"] == 1 | ||
| assert len(resp.json()["collections"]) == 1 | ||
| assert resp.json()["collections"][0]["id"] == load_test2_collection.id | ||
|
|
||
| resp = await app_client.get( | ||
| "/collections", | ||
| params={"q": "nosuchthing"}, | ||
| ) | ||
| assert len(resp.json()["collections"]) == 0 | ||
|
|
||
|
|
||
| @requires_pgstac_0_9_2 | ||
| @pytest.mark.asyncio | ||
| async def test_collection_search_freetext_advanced( | ||
| app_client_advanced_freetext, load_test_collection, load_test2_collection | ||
| ): | ||
| # free-text | ||
| resp = await app_client_advanced_freetext.get( | ||
| "/collections", | ||
| params={"q": "temperature"}, | ||
| ) | ||
| assert resp.json()["numberReturned"] == 1 | ||
| assert resp.json()["numberMatched"] == 1 | ||
| assert len(resp.json()["collections"]) == 1 | ||
| assert resp.json()["collections"][0]["id"] == load_test2_collection.id | ||
|
|
||
| resp = await app_client_advanced_freetext.get( | ||
| "/collections", | ||
| params={"q": "temperature,calibrated"}, | ||
| ) | ||
| assert resp.json()["numberReturned"] == 2 | ||
| assert resp.json()["numberMatched"] == 2 | ||
| assert len(resp.json()["collections"]) == 2 | ||
|
|
||
| resp = await app_client_advanced_freetext.get( | ||
| "/collections", | ||
| params={"q": "temperature,yo"}, | ||
| ) | ||
| assert resp.json()["numberReturned"] == 1 | ||
| assert resp.json()["numberMatched"] == 1 | ||
| assert len(resp.json()["collections"]) == 1 | ||
| assert resp.json()["collections"][0]["id"] == load_test2_collection.id | ||
|
|
||
| resp = await app_client_advanced_freetext.get( | ||
| "/collections", | ||
| params={"q": "temperature OR yo"}, | ||
| ) | ||
| assert resp.json()["numberReturned"] == 1 | ||
| assert resp.json()["numberMatched"] == 1 | ||
| assert len(resp.json()["collections"]) == 1 | ||
| assert resp.json()["collections"][0]["id"] == load_test2_collection.id | ||
|
|
||
| resp = await app_client_advanced_freetext.get( | ||
| "/collections", | ||
| params={"q": "nosuchthing"}, | ||
| ) | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR we changed and we now forward
kwargsto_clean_search_argsmethod.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if
POST /searchwith{"q": 123}is submitted? Doesqmake it all the way to the DB and raises due to invalid types? There won't be any early API model validation of the parameter?