diff --git a/pyproject.toml b/pyproject.toml index 11a21afc..13a3f60e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "navigator_backend" -version = "1.14.20" +version = "1.14.19" description = "" authors = ["CPR-dev-team "] packages = [{ include = "app" }, { include = "tests" }] diff --git a/tests/search/vespa/test_vespa_search_result_order.py b/tests/search/vespa/test_vespa_search_result_order.py new file mode 100644 index 00000000..b2412604 --- /dev/null +++ b/tests/search/vespa/test_vespa_search_result_order.py @@ -0,0 +1,61 @@ +from typing import Mapping + +import pytest + +from app.api.api_v1.routers import search +from tests.search.vespa.setup_search_tests import ( + VESPA_FIXTURE_COUNT, + _populate_db_families, +) + +SEARCH_ENDPOINT = "/api/v1/searches" + + +def _make_search_request(client, params: Mapping[str, str]): + response = client.post(SEARCH_ENDPOINT, json=params) + assert response.status_code == 200, response.text + return response.json() + + +@pytest.mark.search +@pytest.mark.parametrize("label, query", [("search", "the"), ("browse", "")]) +def test_result_order_score( + label, query, test_vespa, data_db, monkeypatch, data_client +): + monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) + _populate_db_families(data_db) + + params = { + "query_string": query, + "sort_field": "date", + "sort_order": "asc", + } + asc_date_body = _make_search_request(data_client, params) + asc_dates = [f["family_date"] for f in asc_date_body["families"]] + + params["sort_order"] = "desc" + desc_date_body = _make_search_request(data_client, params) + desc_dates = [f["family_date"] for f in desc_date_body["families"]] + + assert VESPA_FIXTURE_COUNT == len(asc_dates) == len(desc_dates) + assert asc_dates == list(reversed(desc_dates)) + assert asc_dates[0] < desc_dates[0] + assert asc_dates[-1] > desc_dates[-1] + + +@pytest.mark.search +@pytest.mark.parametrize("label, query", [("search", "the"), ("browse", "")]) +def test_result_order_title( + label, query, test_vespa, data_db, monkeypatch, data_client +): + monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) + _populate_db_families(data_db) + + params = { + "query_string": query, + "sort_field": "title", + "sort_order": "asc", + } + + # Scope of test is to confirm this does not cause a failure + _ = _make_search_request(data_client, params) diff --git a/tests/search/vespa/test_vespasearch.py b/tests/search/vespa/test_vespasearch.py index 21031707..cd8f8ddb 100644 --- a/tests/search/vespa/test_vespasearch.py +++ b/tests/search/vespa/test_vespasearch.py @@ -434,50 +434,6 @@ def test_multiple_filters(label, query, test_vespa, data_db, monkeypatch, data_c _ = _make_search_request(data_client, params) -@pytest.mark.search -@pytest.mark.parametrize("label, query", [("search", "the"), ("browse", "")]) -def test_result_order_score( - label, query, test_vespa, data_db, monkeypatch, data_client -): - monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) - _populate_db_families(data_db) - - params = { - "query_string": query, - "sort_field": "date", - "sort_order": "asc", - } - asc_date_body = _make_search_request(data_client, params) - asc_dates = [f["family_date"] for f in asc_date_body["families"]] - - params["sort_order"] = "desc" - desc_date_body = _make_search_request(data_client, params) - desc_dates = [f["family_date"] for f in desc_date_body["families"]] - - assert VESPA_FIXTURE_COUNT == len(asc_dates) == len(desc_dates) - assert asc_dates == list(reversed(desc_dates)) - assert asc_dates[0] < desc_dates[0] - assert asc_dates[-1] > desc_dates[-1] - - -@pytest.mark.search -@pytest.mark.parametrize("label, query", [("search", "the"), ("browse", "")]) -def test_result_order_title( - label, query, test_vespa, data_db, monkeypatch, data_client -): - monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) - _populate_db_families(data_db) - - params = { - "query_string": query, - "sort_field": "title", - "sort_order": "asc", - } - - # Scope of test is to confirm this does not cause a failure - _ = _make_search_request(data_client, params) - - @pytest.mark.search def test_continuation_token__families(test_vespa, data_db, monkeypatch, data_client): monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa)