-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ae9f79
commit 43a77bc
Showing
10 changed files
with
77 additions
and
460 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
import random | ||
from unittest.mock import patch | ||
|
||
from palace.manager.scripts.search import RebuildSearchIndexScript | ||
from palace.manager.sqlalchemy.model.coverage import WorkCoverageRecord | ||
from tests.fixtures.database import DatabaseTransactionFixture | ||
from tests.fixtures.search import ExternalSearchFixtureFake | ||
|
||
|
||
class TestRebuildSearchIndexScript: | ||
def test_do_run( | ||
self, | ||
db: DatabaseTransactionFixture, | ||
external_search_fake_fixture: ExternalSearchFixtureFake, | ||
): | ||
index = external_search_fake_fixture.external_search | ||
work = db.work(with_license_pool=True) | ||
work2 = db.work(with_license_pool=True) | ||
wcr = WorkCoverageRecord | ||
decoys = [wcr.QUALITY_OPERATION, wcr.SUMMARY_OPERATION] | ||
|
||
# Set up some coverage records. | ||
for operation in decoys + [wcr.UPDATE_SEARCH_INDEX_OPERATION]: | ||
for w in (work, work2): | ||
wcr.add_for(w, operation, status=random.choice(wcr.ALL_STATUSES)) | ||
|
||
coverage_qu = db.session.query(wcr).filter( | ||
wcr.operation == wcr.UPDATE_SEARCH_INDEX_OPERATION | ||
) | ||
original_coverage = [x.id for x in coverage_qu] | ||
|
||
# Run the script. | ||
script = RebuildSearchIndexScript(db.session, search_index_client=index) | ||
[progress] = script.do_run() | ||
|
||
# The mock methods were called with the values we expect. | ||
assert {work.id, work2.id} == set( | ||
map( | ||
lambda d: d["_id"], external_search_fake_fixture.service.documents_all() | ||
) | ||
) | ||
|
||
# The script returned a list containing a single | ||
# CoverageProviderProgress object containing accurate | ||
# information about what happened (from the CoverageProvider's | ||
# point of view). | ||
assert ( | ||
"Items processed: 2. Successes: 2, transient failures: 0, persistent failures: 0" | ||
== progress.achievements | ||
) | ||
|
||
# The old WorkCoverageRecords for the works were deleted. Then | ||
# the CoverageProvider did its job and new ones were added. | ||
new_coverage = [x.id for x in coverage_qu] | ||
assert 2 == len(new_coverage) | ||
assert set(new_coverage) != set(original_coverage) | ||
def test_do_run(self, db: DatabaseTransactionFixture): | ||
# If we are called with no arguments, we default to asynchronously rebuilding the search index. | ||
with patch( | ||
"palace.manager.scripts.search.search_reindex" | ||
) as mock_search_reindex: | ||
RebuildSearchIndexScript(db.session).do_run() | ||
mock_search_reindex.delay.assert_called_once_with() | ||
|
||
# If we are called with the --blocking argument, we rebuild the search index synchronously. | ||
with patch( | ||
"palace.manager.scripts.search.search_reindex" | ||
) as mock_search_reindex: | ||
RebuildSearchIndexScript(db.session, cmd_args=["--blocking"]).do_run() | ||
mock_search_reindex.assert_called_once_with() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.