Skip to content
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

Minor test cleanup #1090

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tests/functional/services/search/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def test_search_post_query_simple(search_client, query_doc):
assert req_body == dict(query_doc)


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_search_post_query_with_legacy_helper(search_client):
meta = load_response(search_client.post_search).metadata
query_doc = globus_sdk.SearchQuery("foo")
with pytest.warns(
globus_sdk.RemovedInV4Warning, match="'SearchQuery' is deprecated"
):
query_doc = globus_sdk.SearchQuery("foo")

res = search_client.post_search(meta["index_id"], query_doc)
assert res.http_status == 200
Expand Down Expand Up @@ -91,13 +93,10 @@ def test_search_post_query_simple_with_v1_helper(search_client):
assert req_body == {"@version": "query#1.0.0", "q": "foo"}


@pytest.mark.parametrize(
"query_doc",
[{"q": "foo", "limit": 10, "offset": 0}],
)
def test_search_post_query_arg_overrides(search_client, query_doc):
def test_search_post_query_arg_overrides(search_client):
meta = load_response(search_client.post_search).metadata

query_doc = {"q": "foo", "limit": 10, "offset": 0}
res = search_client.post_search(meta["index_id"], query_doc, limit=100, offset=150)
assert res.http_status == 200

Expand All @@ -117,10 +116,12 @@ def test_search_post_query_arg_overrides(search_client, query_doc):
assert query_doc["offset"] == 0


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_search_post_query_arg_overrides_with_legacy_helper(search_client):
meta = load_response(search_client.post_search).metadata
query_doc = globus_sdk.SearchQuery("foo", limit=10, offset=0)
with pytest.warns(
globus_sdk.RemovedInV4Warning, match="'SearchQuery' is deprecated"
):
query_doc = globus_sdk.SearchQuery("foo", limit=10, offset=0)

res = search_client.post_search(meta["index_id"], query_doc, limit=100, offset=150)
assert res.http_status == 200
Expand Down
46 changes: 24 additions & 22 deletions tests/unit/helpers/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@

import pytest

from globus_sdk import SearchQuery, SearchQueryV1, utils
from globus_sdk.exc.warnings import RemovedInV4Warning
from globus_sdk import RemovedInV4Warning, SearchQuery, SearchQueryV1, utils


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_init_legacy():
"""Creates SearchQuery and verifies results"""
query = SearchQuery()

assert len(query) == 0

# init with supported fields
params = {"q": "foo", "limit": 10, "offset": 0, "advanced": False}
param_query = SearchQuery(**params)
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
param_query = SearchQuery(**params)
for par in params:
assert param_query[par] == params[par]

# init with additional_fields

def test_init_legacy_no_args():
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()

assert len(query) == 0


def test_init_legacy_additional_fields():
add_params = {"param1": "value1", "param2": "value2"}
param_query = SearchQuery(additional_fields=add_params)
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
param_query = SearchQuery(additional_fields=add_params)
for par in add_params:
assert param_query[par] == add_params[par]

Expand Down Expand Up @@ -60,9 +62,9 @@ def test_init_v1():


@pytest.mark.parametrize("attrname", ["q", "limit", "offset", "advanced"])
@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_set_method(attrname):
query = SearchQuery()
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()
method = getattr(query, "set_{}".format("query" if attrname == "q" else attrname))
# start absent
assert attrname not in query
Expand All @@ -72,9 +74,9 @@ def test_set_method(attrname):
assert query[attrname] == "foo"


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_add_facet():
query = SearchQuery()
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()
assert "facets" not in query

# simple terms facet
Expand Down Expand Up @@ -128,9 +130,9 @@ def test_add_facet():
}


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_add_filter():
query = SearchQuery()
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()
assert "filters" not in query

# returns self
Expand Down Expand Up @@ -169,9 +171,9 @@ def test_add_filter():
}


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_add_boost():
query = SearchQuery()
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()
assert "boosts" not in query

# returns self
Expand All @@ -191,9 +193,9 @@ def test_add_boost():
}


@pytest.mark.filterwarnings("ignore:'SearchQuery'*:DeprecationWarning")
def test_add_sort():
query = SearchQuery()
with pytest.warns(RemovedInV4Warning, match="'SearchQuery' is deprecated"):
query = SearchQuery()
assert "sort" not in query

# returns self
Expand Down