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/7] 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/7] 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/7] 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/7] 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/7] 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" }] From 778e142f11a4fe898d797fdbbad73ea0825126a0 Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:24:56 +0100 Subject: [PATCH 6/7] Move vespa search continuation token tests to separate file --- .../vespa/test_vespa_search_cont_tokens.py | 116 ++++++++++++++++++ tests/search/vespa/test_vespasearch.py | 102 --------------- 2 files changed, 116 insertions(+), 102 deletions(-) create mode 100644 tests/search/vespa/test_vespa_search_cont_tokens.py diff --git a/tests/search/vespa/test_vespa_search_cont_tokens.py b/tests/search/vespa/test_vespa_search_cont_tokens.py new file mode 100644 index 00000000..b4b9201e --- /dev/null +++ b/tests/search/vespa/test_vespa_search_cont_tokens.py @@ -0,0 +1,116 @@ +from typing import Mapping + +import pytest + +from app.api.api_v1.routers import search +from tests.search.vespa.setup_search_tests import _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 +def test_continuation_token__families(test_vespa, data_db, monkeypatch, data_client): + monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) + + _populate_db_families(data_db) + + params = {"query_string": "the", "limit": 2, "page_size": 1} + response = _make_search_request(data_client, params) + continuation = response["continuation_token"] + first_family_ids = [f["family_slug"] for f in response["families"]] + + # Confirm we have grabbed a subset of all results + assert len(response["families"]) < response["total_family_hits"] + + # Get next results set + params = {"query_string": "the", "continuation_tokens": [continuation]} + response = _make_search_request(data_client, params) + second_family_ids = [f["family_slug"] for f in response["families"]] + + # Confirm we actually got different results + assert sorted(first_family_ids) != sorted(second_family_ids) + + # Go back to prev and confirm its what we had initially + params = { + "query_string": "the", + "continuation_tokens": [response["prev_continuation_token"]], + "limit": 2, + "page_size": 1, + } + response = _make_search_request(data_client, params) + prev_family_ids = [f["family_slug"] for f in response["families"]] + + assert sorted(first_family_ids) == sorted(prev_family_ids) + + +@pytest.mark.search +def test_continuation_token__passages(test_vespa, data_db, monkeypatch, data_client): + monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) + + _populate_db_families(data_db) + + # Get second set of families + params = { + "query_string": "the", + "document_ids": ["CCLW.executive.10246.4861", "CCLW.executive.4934.1571"], + "limit": 1, + "page_size": 1, + } + first_family = _make_search_request(data_client, params) + params["continuation_tokens"] = [first_family["continuation_token"]] + second_family_first_passages = _make_search_request(data_client, params) + second_family_first_passages_ids = [ + h["text_block_id"] + for h in second_family_first_passages["families"][0]["family_documents"][0][ + "document_passage_matches" + ] + ] + + # Get next set of passages + this_family_continuation = second_family_first_passages["this_continuation_token"] + next_passages_continuation = second_family_first_passages["families"][0][ + "continuation_token" + ] + params["continuation_tokens"] = [ + this_family_continuation, + next_passages_continuation, + ] + second_family_second_passages = _make_search_request(data_client, params) + second_family_second_passages_ids = [ + h["text_block_id"] + for h in second_family_second_passages["families"][0]["family_documents"][0][ + "document_passage_matches" + ] + ] + + # Confirm we actually got different results + assert sorted(second_family_first_passages_ids) != sorted( + second_family_second_passages_ids + ) + + # Go to previous set and confirm its the same + prev_passages_continuation = second_family_second_passages["families"][0][ + "prev_continuation_token" + ] + + params["continuation_tokens"] = [ + this_family_continuation, + prev_passages_continuation, + ] + response = _make_search_request(data_client, params) + second_family_prev_passages_ids = [ + h["text_block_id"] + for h in response["families"][0]["family_documents"][0][ + "document_passage_matches" + ] + ] + + assert sorted(second_family_second_passages_ids) != sorted( + second_family_prev_passages_ids + ) diff --git a/tests/search/vespa/test_vespasearch.py b/tests/search/vespa/test_vespasearch.py index cd8f8ddb..3f45ae2d 100644 --- a/tests/search/vespa/test_vespasearch.py +++ b/tests/search/vespa/test_vespasearch.py @@ -434,108 +434,6 @@ def test_multiple_filters(label, query, test_vespa, data_db, monkeypatch, data_c _ = _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) - - _populate_db_families(data_db) - - params = {"query_string": "the", "limit": 2, "page_size": 1} - response = _make_search_request(data_client, params) - continuation = response["continuation_token"] - first_family_ids = [f["family_slug"] for f in response["families"]] - - # Confirm we have grabbed a subset of all results - assert len(response["families"]) < response["total_family_hits"] - - # Get next results set - params = {"query_string": "the", "continuation_tokens": [continuation]} - response = _make_search_request(data_client, params) - second_family_ids = [f["family_slug"] for f in response["families"]] - - # Confirm we actually got different results - assert sorted(first_family_ids) != sorted(second_family_ids) - - # Go back to prev and confirm its what we had initially - params = { - "query_string": "the", - "continuation_tokens": [response["prev_continuation_token"]], - "limit": 2, - "page_size": 1, - } - response = _make_search_request(data_client, params) - prev_family_ids = [f["family_slug"] for f in response["families"]] - - assert sorted(first_family_ids) == sorted(prev_family_ids) - - -@pytest.mark.search -def test_continuation_token__passages(test_vespa, data_db, monkeypatch, data_client): - monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) - - _populate_db_families(data_db) - - # Get second set of families - params = { - "query_string": "the", - "document_ids": ["CCLW.executive.10246.4861", "CCLW.executive.4934.1571"], - "limit": 1, - "page_size": 1, - } - first_family = _make_search_request(data_client, params) - params["continuation_tokens"] = [first_family["continuation_token"]] - second_family_first_passages = _make_search_request(data_client, params) - second_family_first_passages_ids = [ - h["text_block_id"] - for h in second_family_first_passages["families"][0]["family_documents"][0][ - "document_passage_matches" - ] - ] - - # Get next set of passages - this_family_continuation = second_family_first_passages["this_continuation_token"] - next_passages_continuation = second_family_first_passages["families"][0][ - "continuation_token" - ] - params["continuation_tokens"] = [ - this_family_continuation, - next_passages_continuation, - ] - second_family_second_passages = _make_search_request(data_client, params) - second_family_second_passages_ids = [ - h["text_block_id"] - for h in second_family_second_passages["families"][0]["family_documents"][0][ - "document_passage_matches" - ] - ] - - # Confirm we actually got different results - assert sorted(second_family_first_passages_ids) != sorted( - second_family_second_passages_ids - ) - - # Go to previous set and confirm its the same - prev_passages_continuation = second_family_second_passages["families"][0][ - "prev_continuation_token" - ] - - params["continuation_tokens"] = [ - this_family_continuation, - prev_passages_continuation, - ] - response = _make_search_request(data_client, params) - second_family_prev_passages_ids = [ - h["text_block_id"] - for h in response["families"][0]["family_documents"][0][ - "document_passage_matches" - ] - ] - - assert sorted(second_family_second_passages_ids) != sorted( - second_family_prev_passages_ids - ) - - @pytest.mark.search def test_case_insensitivity(test_vespa, data_db, monkeypatch, data_client): monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) From 26c0a8ced14a271acc4a4ef2f319eb1806302141 Mon Sep 17 00:00:00 2001 From: Katy Baulch <46493669+katybaulch@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:42:44 +0100 Subject: [PATCH 7/7] Group pagination and continuation token tests --- ...ens.py => test_vespa_search_pagination.py} | 49 ++++++++++++++++++- tests/search/vespa/test_vespasearch.py | 44 ----------------- 2 files changed, 48 insertions(+), 45 deletions(-) rename tests/search/vespa/{test_vespa_search_cont_tokens.py => test_vespa_search_pagination.py} (73%) diff --git a/tests/search/vespa/test_vespa_search_cont_tokens.py b/tests/search/vespa/test_vespa_search_pagination.py similarity index 73% rename from tests/search/vespa/test_vespa_search_cont_tokens.py rename to tests/search/vespa/test_vespa_search_pagination.py index b4b9201e..7e9c6664 100644 --- a/tests/search/vespa/test_vespa_search_cont_tokens.py +++ b/tests/search/vespa/test_vespa_search_pagination.py @@ -3,7 +3,10 @@ import pytest from app.api.api_v1.routers import search -from tests.search.vespa.setup_search_tests import _populate_db_families +from tests.search.vespa.setup_search_tests import ( + VESPA_FIXTURE_COUNT, + _populate_db_families, +) SEARCH_ENDPOINT = "/api/v1/searches" @@ -14,6 +17,50 @@ def _make_search_request(client, params: Mapping[str, str]): return response.json() +@pytest.mark.search +def test_simple_pagination_families(test_vespa, data_client, data_db, monkeypatch): + monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) + _populate_db_families(data_db) + + PAGE_SIZE = 2 + + # Query one + params = { + "query_string": "and", + "page_size": PAGE_SIZE, + "offset": 0, + } + body_one = _make_search_request(data_client, params) + assert body_one["hits"] == VESPA_FIXTURE_COUNT + assert len(body_one["families"]) == PAGE_SIZE + assert ( + body_one["families"][0]["family_slug"] + == "agriculture-sector-plan-2015-2019_7999" + ) + assert ( + body_one["families"][1]["family_slug"] + == "national-environment-policy-of-guinea_f0df" + ) + + # Query two + params = { + "query_string": "and", + "page_size": PAGE_SIZE, + "offset": 2, + } + body_two = _make_search_request(data_client, params) + assert body_two["hits"] == VESPA_FIXTURE_COUNT + assert len(body_two["families"]) == PAGE_SIZE + assert ( + body_two["families"][0]["family_slug"] + == "national-energy-policy-and-energy-action-plan_9262" + ) + assert ( + body_two["families"][1]["family_slug"] + == "submission-to-the-unfccc-ahead-of-the-first-technical-dialogue_e760" + ) + + @pytest.mark.search def test_continuation_token__families(test_vespa, data_db, monkeypatch, data_client): monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) diff --git a/tests/search/vespa/test_vespasearch.py b/tests/search/vespa/test_vespasearch.py index 3f45ae2d..4cae6e81 100644 --- a/tests/search/vespa/test_vespasearch.py +++ b/tests/search/vespa/test_vespasearch.py @@ -45,50 +45,6 @@ def test_empty_search_term_performs_browse( query_spy.assert_called_once() -@pytest.mark.search -def test_simple_pagination_families(test_vespa, data_client, data_db, monkeypatch): - monkeypatch.setattr(search, "_VESPA_CONNECTION", test_vespa) - _populate_db_families(data_db) - - PAGE_SIZE = 2 - - # Query one - params = { - "query_string": "and", - "page_size": PAGE_SIZE, - "offset": 0, - } - body_one = _make_search_request(data_client, params) - assert body_one["hits"] == VESPA_FIXTURE_COUNT - assert len(body_one["families"]) == PAGE_SIZE - assert ( - body_one["families"][0]["family_slug"] - == "agriculture-sector-plan-2015-2019_7999" - ) - assert ( - body_one["families"][1]["family_slug"] - == "national-environment-policy-of-guinea_f0df" - ) - - # Query two - params = { - "query_string": "and", - "page_size": PAGE_SIZE, - "offset": 2, - } - body_two = _make_search_request(data_client, params) - assert body_two["hits"] == VESPA_FIXTURE_COUNT - assert len(body_two["families"]) == PAGE_SIZE - assert ( - body_two["families"][0]["family_slug"] - == "national-energy-policy-and-energy-action-plan_9262" - ) - assert ( - body_two["families"][1]["family_slug"] - == "submission-to-the-unfccc-ahead-of-the-first-technical-dialogue_e760" - ) - - @pytest.mark.search @pytest.mark.parametrize("exact_match", [True, False]) def test_search_body_valid(exact_match, test_vespa, data_client, data_db, monkeypatch):