Skip to content

Commit

Permalink
More updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Apr 18, 2024
1 parent 5c370f7 commit b4bc45b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
4 changes: 1 addition & 3 deletions core/celery/tasks/generate_inventory_and_hold_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)
from core.opds_import import OPDSImporterSettings
from core.service.celery.celery import QueueNames
from core.service.container import container_instance
from core.service.email.email import SendEmailCallable


Expand Down Expand Up @@ -281,10 +280,9 @@ def holds_report_query() -> str:
def generate_inventory_and_hold_reports(
task: Task, library_id: int, email_address: str
) -> None:
services = container_instance()
GenerateInventoryAndHoldsReportsJob(
task.session_maker,
library_id=library_id,
email_address=email_address,
send_email=services.email.container.send_email,
send_email=task.services.email.send_email,
).run()
1 change: 0 additions & 1 deletion tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"tests.fixtures.api_overdrive_files",
"tests.fixtures.api_routes",
"tests.fixtures.authenticator",
"tests.fixtures.celery",
"tests.fixtures.csv_files",
"tests.fixtures.database",
"tests.fixtures.files",
Expand Down
26 changes: 12 additions & 14 deletions tests/core/celery/tasks/test_generate_inventory_and_hold_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@ def test_job_run(
collection.libraries.append(library2)

# Configure test data we expect will not be picked up.
no_inventory_report_settings = OPDSImporterSettings(
include_in_inventory_report=False,
external_account_id="http://opds.com",
data_source="AnotherOpdsDataSource",
)
collection_not_to_include = db.collection(
name="Another Test Collection", settings=no_inventory_report_settings.dict()
create_test_opds_collection(
"Another Test Collection", "AnotherOpdsDataSource", db, library, False
)
collection_not_to_include.libraries = [library]

od_settings = OverdriveSettings(
overdrive_website_id="overdrive_id",
Expand Down Expand Up @@ -261,9 +255,10 @@ def create_test_opds_collection(
data_source: str,
db: DatabaseTransactionFixture,
library: Library,
include_in_inventory_report: bool = True,
):
settings = OPDSImporterSettings(
include_in_inventory_report=True,
include_in_inventory_report=include_in_inventory_report,
external_account_id="http://opds.com",
data_source=data_source,
)
Expand All @@ -280,9 +275,12 @@ def test_generate_inventory_and_hold_reports_task(
library = db.library(short_name="test_library")
# there must be at least one opds collection associated with the library for this to work
create_test_opds_collection("c1", "d1", db, library)
send_email_mock = create_autospec(
services_fixture.services.email.container.send_email
)
services_fixture.services.email.container.send_email = send_email_mock
generate_inventory_and_hold_reports.delay(library.id, "test@email").wait()
send_email_mock.assert_called_once()
services_fixture.email_fixture.mock_emailer.send.assert_called_once()
assert (
"Inventory and Holds Reports"
in services_fixture.email_fixture.mock_emailer.send.call_args.kwargs["subject"]
)
assert services_fixture.email_fixture.mock_emailer.send.call_args.kwargs[
"receivers"
] == ["test@email"]

0 comments on commit b4bc45b

Please sign in to comment.