-
Notifications
You must be signed in to change notification settings - Fork 24
refactor tests to not need sleep, use fixture for setup/teardown #69
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
Conversation
…ost tests, remove use of execute methods in ES DSL
addopts = -sv | ||
asyncio_mode = auto |
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.
not having this gave a warning, and we'll need it for making everything async
@@ -29,6 +29,7 @@ | |||
"requests", | |||
"ciso8601", | |||
"overrides", | |||
"starlette", |
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.
we have use some classes out of this package, but it was not explicitly deps
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.
I recently had to add this too for a fresh pgstac stac-fastapi backend that we're testing at work
@@ -243,9 +243,8 @@ def post_search(self, search_request, **kwargs) -> ItemCollection: | |||
for sort in search_request.sortby: | |||
if sort.field == "datetime": | |||
sort.field = "properties__datetime" | |||
field = sort.field + ".keyword" |
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.
all sortable fields are keyword by default, so they don't need this set.
else: | ||
item = self.database.prep_create_item(item=item, base_url=base_url) | ||
self.database.create_item(item=item, base_url=base_url) | ||
self.database.create_item(item, refresh=kwargs.get("refresh", False)) |
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.
I haven't wired this through to the API yet, but calling this with "refresh=true" will cause it to refresh the index, so the item is immediately visible to a subsequent search
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.
Nice
@@ -79,7 +89,11 @@ def get_item_collection( | |||
|
|||
# search = search.sort({"id.keyword" : {"order" : "asc"}}) | |||
search = search.query()[0:limit] | |||
collection_children = search.execute().to_dict() | |||
|
|||
body = search.to_dict() |
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.
switched this from using the ES DSL method on search to generating the search and calling client.search, because we're going to convert this to be async next, and that doesn't work with the DSL execute and count methods.
{"id": {"order": "desc"}}, | ||
{"collection": {"order": "desc"}}, | ||
) | ||
return Search().sort( |
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.
client and index no longer need to be defined in the search b/c we're not executing on it.
search = search.query(collection_filter) | ||
|
||
return search | ||
collections_query = [Q("term", **{"collection": cid}) for cid in collection_ids] |
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.
term is an exact match, rather than match_phrase which does something else
item = load_test_data("test_item.json") | ||
es_transactions.create_item(item, request=MockStarletteRequest) | ||
|
||
def test_app_search_response(app_client, ctx): |
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.
the ctx
fixture clears the indexes, loads an item, runs the tests, and then clears the indexes again
@@ -123,238 +116,146 @@ def test_app_context_extension(load_test_data, app_client, es_transactions, es_c | |||
assert "context" in resp_json | |||
assert resp_json["context"]["returned"] == resp_json["context"]["matched"] == 1 | |||
|
|||
es_transactions.delete_collection(collection["id"], request=MockStarletteRequest) |
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.
I removed tons of these calls, as it's handled by ctx
now
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.
Awesome
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.
Nice work!
Related Issue(s):
Description:
PR Checklist:
pre-commit run --all-files
)make test
)make docs
)