From 5d4cec2d2b98f6572c80c9b05a2c963b499152ce Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:54:41 +0100 Subject: [PATCH 1/5] Move vespa search tests under dedicated vespa folder --- tests/search/{ => vespa}/data_download/test_this_search.py | 2 +- tests/search/{ => vespa}/data_download/test_whole_database.py | 2 +- tests/search/{ => vespa}/setup_search_tests.py | 2 +- tests/search/{ => vespa}/test_vespa_ids_search.py | 2 +- tests/search/{ => vespa}/test_vespasearch.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename tests/search/{ => vespa}/data_download/test_this_search.py (97%) rename tests/search/{ => vespa}/data_download/test_whole_database.py (92%) rename tests/search/{ => vespa}/setup_search_tests.py (99%) rename tests/search/{ => vespa}/test_vespa_ids_search.py (98%) rename tests/search/{ => vespa}/test_vespasearch.py (99%) diff --git a/tests/search/data_download/test_this_search.py b/tests/search/vespa/data_download/test_this_search.py similarity index 97% rename from tests/search/data_download/test_this_search.py rename to tests/search/vespa/data_download/test_this_search.py index f9bdd713..8dad470d 100644 --- a/tests/search/data_download/test_this_search.py +++ b/tests/search/vespa/data_download/test_this_search.py @@ -6,7 +6,7 @@ import pytest from app.api.api_v1.routers import search -from tests.search.setup_search_tests import _populate_db_families +from tests.search.vespa.setup_search_tests import _populate_db_families SEARCH_ENDPOINT = "/api/v1/searches" CSV_DOWNLOAD_ENDPOINT = "/api/v1/searches/download-csv" diff --git a/tests/search/data_download/test_whole_database.py b/tests/search/vespa/data_download/test_whole_database.py similarity index 92% rename from tests/search/data_download/test_whole_database.py rename to tests/search/vespa/data_download/test_whole_database.py index 7be699e8..74896a58 100644 --- a/tests/search/data_download/test_whole_database.py +++ b/tests/search/vespa/data_download/test_whole_database.py @@ -2,7 +2,7 @@ import pytest -from tests.search.setup_search_tests import _populate_db_families +from tests.search.vespa.setup_search_tests import _populate_db_families ALL_DATA_DOWNLOAD_ENDPOINT = "/api/v1/searches/download-all-data" diff --git a/tests/search/setup_search_tests.py b/tests/search/vespa/setup_search_tests.py similarity index 99% rename from tests/search/setup_search_tests.py rename to tests/search/vespa/setup_search_tests.py index f4a6732c..2306118c 100644 --- a/tests/search/setup_search_tests.py +++ b/tests/search/vespa/setup_search_tests.py @@ -27,7 +27,7 @@ from sqlalchemy.orm import Session VESPA_FIXTURE_COUNT = 5 -FIXTURE_DIR = Path(__file__).parent / "search_fixtures" +FIXTURE_DIR = Path(__file__).parent.parent / "search_fixtures" VESPA_FAMILY_PATH = FIXTURE_DIR / "vespa_family_document.json" VESPA_DOCUMENT_PATH = FIXTURE_DIR / "vespa_document_passage.json" diff --git a/tests/search/test_vespa_ids_search.py b/tests/search/vespa/test_vespa_ids_search.py similarity index 98% rename from tests/search/test_vespa_ids_search.py rename to tests/search/vespa/test_vespa_ids_search.py index f0db2828..203490da 100644 --- a/tests/search/test_vespa_ids_search.py +++ b/tests/search/vespa/test_vespa_ids_search.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import Session from app.api.api_v1.routers import search -from tests.search.setup_search_tests import _populate_db_families +from tests.search.vespa.setup_search_tests import _populate_db_families SEARCH_ENDPOINT = "/api/v1/searches" diff --git a/tests/search/test_vespasearch.py b/tests/search/vespa/test_vespasearch.py similarity index 99% rename from tests/search/test_vespasearch.py rename to tests/search/vespa/test_vespasearch.py index e9a2f565..21031707 100644 --- a/tests/search/test_vespasearch.py +++ b/tests/search/vespa/test_vespasearch.py @@ -8,7 +8,7 @@ from app.api.api_v1.routers import search from app.core.lookups import get_country_slug_from_country_code -from tests.search.setup_search_tests import ( +from tests.search.vespa.setup_search_tests import ( VESPA_FIXTURE_COUNT, _create_document, _create_family, From c1f25415e3085f58ecb99dddd33c024bb686d4b7 Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:56:54 +0100 Subject: [PATCH 2/5] Move /search_fixtures under vespa search folder & rename to fixtures --- .trunk/trunk.yaml | 2 +- makefile-docker.defs | 10 +++++----- .../fixtures}/vespa_document_passage.json | 0 .../fixtures}/vespa_family_document.json | 0 .../fixtures}/vespa_search_weights.json | 0 .../vespa_test_schema/query-profiles/default.xml | 0 .../vespa_test_schema/schemas/document_passage.sd | 0 .../vespa_test_schema/schemas/family_document.sd | 0 .../vespa_test_schema/schemas/search_weights.sd | 0 .../fixtures}/vespa_test_schema/services.xml | 0 tests/search/vespa/setup_search_tests.py | 2 +- 11 files changed, 7 insertions(+), 7 deletions(-) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_document_passage.json (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_family_document.json (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_search_weights.json (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_test_schema/query-profiles/default.xml (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_test_schema/schemas/document_passage.sd (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_test_schema/schemas/family_document.sd (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_test_schema/schemas/search_weights.sd (100%) rename tests/search/{search_fixtures => vespa/fixtures}/vespa_test_schema/services.xml (100%) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 2065f308..13b8a442 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -39,7 +39,7 @@ lint: paths: # Ignore test data JSON files - tests/data/**/*.json - - tests/search/search_fixtures/**/*.json + - tests/search/vespa/fixtures/**/*.json - scripts/** - linters: [markdownlint] paths: diff --git a/makefile-docker.defs b/makefile-docker.defs index bb92d124..09ac26f0 100644 --- a/makefile-docker.defs +++ b/makefile-docker.defs @@ -80,17 +80,17 @@ vespa_healthy: .ONESHELL: vespa_deploy_schema: vespa config set target local - @vespa deploy tests/search/search_fixtures/vespa_test_schema --wait 300 + @vespa deploy tests/search/vespa/fixtures/vespa_test_schema --wait 300 .ONESHELL: vespa_load_data: vespa config set target local - vespa feed --progress=3 tests/search/search_fixtures/vespa_search_weights.json - vespa feed --progress=3 tests/search/search_fixtures/vespa_family_document.json - vespa feed --progress=3 tests/search/search_fixtures/vespa_document_passage.json + vespa feed --progress=3 tests/search/vespa/fixtures/vespa_search_weights.json + vespa feed --progress=3 tests/search/vespa/fixtures/vespa_family_document.json + vespa feed --progress=3 tests/search/vespa/fixtures/vespa_document_passage.json vespa_setup: vespa_confirm_cli_installed vespa_healthy vespa_deploy_schema vespa_load_data - # Deploys a vespa application to a local vespa container and loads search_fixtures + # Deploys a vespa application to a local vespa container and loads search fixtures .ONESHELL: test_search: diff --git a/tests/search/search_fixtures/vespa_document_passage.json b/tests/search/vespa/fixtures/vespa_document_passage.json similarity index 100% rename from tests/search/search_fixtures/vespa_document_passage.json rename to tests/search/vespa/fixtures/vespa_document_passage.json diff --git a/tests/search/search_fixtures/vespa_family_document.json b/tests/search/vespa/fixtures/vespa_family_document.json similarity index 100% rename from tests/search/search_fixtures/vespa_family_document.json rename to tests/search/vespa/fixtures/vespa_family_document.json diff --git a/tests/search/search_fixtures/vespa_search_weights.json b/tests/search/vespa/fixtures/vespa_search_weights.json similarity index 100% rename from tests/search/search_fixtures/vespa_search_weights.json rename to tests/search/vespa/fixtures/vespa_search_weights.json diff --git a/tests/search/search_fixtures/vespa_test_schema/query-profiles/default.xml b/tests/search/vespa/fixtures/vespa_test_schema/query-profiles/default.xml similarity index 100% rename from tests/search/search_fixtures/vespa_test_schema/query-profiles/default.xml rename to tests/search/vespa/fixtures/vespa_test_schema/query-profiles/default.xml diff --git a/tests/search/search_fixtures/vespa_test_schema/schemas/document_passage.sd b/tests/search/vespa/fixtures/vespa_test_schema/schemas/document_passage.sd similarity index 100% rename from tests/search/search_fixtures/vespa_test_schema/schemas/document_passage.sd rename to tests/search/vespa/fixtures/vespa_test_schema/schemas/document_passage.sd diff --git a/tests/search/search_fixtures/vespa_test_schema/schemas/family_document.sd b/tests/search/vespa/fixtures/vespa_test_schema/schemas/family_document.sd similarity index 100% rename from tests/search/search_fixtures/vespa_test_schema/schemas/family_document.sd rename to tests/search/vespa/fixtures/vespa_test_schema/schemas/family_document.sd diff --git a/tests/search/search_fixtures/vespa_test_schema/schemas/search_weights.sd b/tests/search/vespa/fixtures/vespa_test_schema/schemas/search_weights.sd similarity index 100% rename from tests/search/search_fixtures/vespa_test_schema/schemas/search_weights.sd rename to tests/search/vespa/fixtures/vespa_test_schema/schemas/search_weights.sd diff --git a/tests/search/search_fixtures/vespa_test_schema/services.xml b/tests/search/vespa/fixtures/vespa_test_schema/services.xml similarity index 100% rename from tests/search/search_fixtures/vespa_test_schema/services.xml rename to tests/search/vespa/fixtures/vespa_test_schema/services.xml diff --git a/tests/search/vespa/setup_search_tests.py b/tests/search/vespa/setup_search_tests.py index 2306118c..a58d6f75 100644 --- a/tests/search/vespa/setup_search_tests.py +++ b/tests/search/vespa/setup_search_tests.py @@ -27,7 +27,7 @@ from sqlalchemy.orm import Session VESPA_FIXTURE_COUNT = 5 -FIXTURE_DIR = Path(__file__).parent.parent / "search_fixtures" +FIXTURE_DIR = Path(__file__).parent / "fixtures" VESPA_FAMILY_PATH = FIXTURE_DIR / "vespa_family_document.json" VESPA_DOCUMENT_PATH = FIXTURE_DIR / "vespa_document_passage.json" From 22716a2817cdfbff66593f5b2df32583fb4f2360 Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:58:08 +0100 Subject: [PATCH 3/5] Bump to 1.14.20 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 13a3f60e..11a21afc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "navigator_backend" -version = "1.14.19" +version = "1.14.20" description = "" authors = ["CPR-dev-team "] packages = [{ include = "app" }, { include = "tests" }] From bd60c7ea353ee952c3ed67c2c3f880d9a209d66c Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:18:38 +0100 Subject: [PATCH 4/5] Move vespa search result order tests to separate file --- .../vespa/test_vespa_search_result_order.py | 61 +++++++++++++++++++ tests/search/vespa/test_vespasearch.py | 44 ------------- 2 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 tests/search/vespa/test_vespa_search_result_order.py 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) From 258f2d54e8a178494ff1ccbd2a888ab94d5680c9 Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:23:45 +0100 Subject: [PATCH 5/5] Bump to 1.14.19 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" }]