From b4bc45bf406eacf68b76f586c6b69c4838d74f11 Mon Sep 17 00:00:00 2001 From: Daniel Bernstein Date: Thu, 18 Apr 2024 13:40:54 -0700 Subject: [PATCH] More updates. --- .../generate_inventory_and_hold_reports.py | 4 +-- tests/api/conftest.py | 1 - ...est_generate_inventory_and_hold_reports.py | 26 +++++++++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/core/celery/tasks/generate_inventory_and_hold_reports.py b/core/celery/tasks/generate_inventory_and_hold_reports.py index 739040b2af..3d4fb25dd1 100644 --- a/core/celery/tasks/generate_inventory_and_hold_reports.py +++ b/core/celery/tasks/generate_inventory_and_hold_reports.py @@ -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 @@ -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() diff --git a/tests/api/conftest.py b/tests/api/conftest.py index ca15f66743..10c6427c09 100644 --- a/tests/api/conftest.py +++ b/tests/api/conftest.py @@ -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", diff --git a/tests/core/celery/tasks/test_generate_inventory_and_hold_reports.py b/tests/core/celery/tasks/test_generate_inventory_and_hold_reports.py index ad8a5d01f0..0349f2a931 100644 --- a/tests/core/celery/tasks/test_generate_inventory_and_hold_reports.py +++ b/tests/core/celery/tasks/test_generate_inventory_and_hold_reports.py @@ -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", @@ -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, ) @@ -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"]