Skip to content

Commit

Permalink
Adds end to end test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Jun 4, 2024
1 parent 0508e6d commit 1593942
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/manager/celery/tasks/test_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from unittest.mock import MagicMock, call, patch

import pytest
Expand All @@ -12,6 +13,7 @@
update_read_pointer,
)
from palace.manager.scripts.initialization import InstanceInitializationScript
from palace.manager.search.external_search import Filter
from tests.fixtures.celery import CeleryFixture
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.search import EndToEndSearchFixture
Expand Down Expand Up @@ -73,6 +75,37 @@ def test_search_reindex(
end_to_end_search_fixture.expect_results([work1, work2, work4], "", ordered=False)


def test_PP_1332_fiction_returns_results(
db: DatabaseTransactionFixture, end_to_end_search_fixture: EndToEndSearchFixture
) -> None:
work1 = db.work(with_open_access_download=True, fiction=True)
work2 = db.work(with_open_access_download=True, fiction=False)
documents = get_work_search_documents(db.session, 2, 0)
assert [doc["_id"] for doc in documents] == [work2.id, work1.id]
assert "nonfiction" == documents[0]["fiction"]
assert "fiction" == documents[1]["fiction"]
end_to_end_search_fixture.populate_search_index()
end_to_end_search_fixture.expect_results(
expect=[work1, work2], ordered=False, query_string=""
)
default_filter = Filter()
default_filter.search_type = "json"
qs = {"query": {"key": "fiction", "value": "fiction"}}
end_to_end_search_fixture.expect_results(
expect=[work1],
ordered=False,
filter=default_filter,
query_string=json.dumps(qs),
)
qs["query"]["value"] = "nonfiction"
end_to_end_search_fixture.expect_results(
expect=[work2],
ordered=False,
filter=default_filter,
query_string=json.dumps(qs),
)


@patch("palace.manager.celery.tasks.search.exponential_backoff")
def test_search_reindex_failures(
mock_backoff: MagicMock,
Expand Down

0 comments on commit 1593942

Please sign in to comment.