Skip to content

Commit

Permalink
Test for multi version queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
antarcticrainforest committed Feb 26, 2025
1 parent 5053fbd commit 7066efe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def get_data_loader_config() -> bytes:
return b64encode(
json.dumps(
{
"user": os.getenv("API_REDIS_USER"),
"passwd": os.getenv("API_REDIS_PASSWORD"),
"host": os.getenv("API_REDIS_HOST"),
"user": os.getenv("API_REDIS_USER", ""),
"passwd": os.getenv("API_REDIS_PASSWORD", ""),
"host": os.getenv("API_REDIS_HOST", ""),
"ssl_cert": Path(
os.getenv("API_REDIS_SSL_CERTFILE")
os.getenv("API_REDIS_SSL_CERTFILE", "")
).read_text(),
"ssl_key": Path(
os.getenv("API_REDIS_SSL_KEYFILE")
os.getenv("API_REDIS_SSL_KEYFILE", "")
).read_text(),
}
).encode("utf-8")
Expand Down Expand Up @@ -197,9 +197,7 @@ def invalid_eval_conf_file() -> Iterator[Path]:
with TemporaryDirectory() as temp_dir:
eval_file = Path(temp_dir) / "eval.conf"
eval_file.write_text(
"[foo]\n"
"solr.host = http://localhost\n"
"databrowser.port = 8080"
"[foo]\n" "solr.host = http://localhost\n" "databrowser.port = 8080"
)
with mock.patch.dict(
os.environ,
Expand Down Expand Up @@ -232,7 +230,7 @@ def test_server() -> Iterator[str]:
"REDIS_SSL_CERTFILE",
):
env[key] = os.getenv(f"API_{key}", "")
env["REDIS_PASS"] = os.getenv("API_REDIS_PASSWORD")
env["REDIS_PASS"] = os.getenv("API_REDIS_PASSWORD", "")
with mock.patch.dict(os.environ, env, clear=True):
yield from setup_server()
asyncio.run(shutdown_data_loader())
Expand Down
44 changes: 44 additions & 0 deletions tests/test_query_data_restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,50 @@ def test_databrowser(test_server: str) -> None:
assert len(res2.text.split()) < len(res5.text.split())


def test_multiversion(test_server: str) -> None:
"""Test the behaviour for multi versions."""
res1 = requests.get(
f"{test_server}/databrowser/metadata-search/freva/file",
params={"multi-version": True},
)
assert res1.status_code == 200
assert "facets" in res1.json()
assert "version" in res1.json()["facets"]
version = res1.json()["facets"]["version"][0]

res2 = requests.get(
f"{test_server}/databrowser/metadata-search/freva/file",
params={"multi-version": False},
)
assert res2.status_code == 200
assert "facets" in res2.json()
assert "version" not in res2.json()["facets"]

res3 = requests.get(
f"{test_server}/databrowser/data-search/freva/file",
params={"multi-version": True},
)
assert res3.status_code == 200
res4 = requests.get(
f"{test_server}/databrowser/data-search/freva/file",
params={"multi-version": False},
)
assert res4.status_code == 200
assert len(list(res4.text.split())) < len(list(res3.text.split()))

res5 = requests.get(
f"{test_server}/databrowser/data-search/freva/file",
params={"multi-version": True, "version": version},
)
assert res5.status_code == 200

res6 = requests.get(
f"{test_server}/databrowser/data-search/freva/file",
params={"multi-version": False, "version": version},
)
assert res6.status_code != 200


def test_no_solr(test_server: str) -> None:
"""Test what happens if there is no connection to the solr."""
with mock.patch("freva_rest.rest.server_config.solr_host", "foo.bar"):
Expand Down

0 comments on commit 7066efe

Please sign in to comment.