From 182b162b5dbd3a360a29d5e08424dd6909a2b9fd Mon Sep 17 00:00:00 2001 From: Tim DiLauro Date: Mon, 13 May 2024 16:08:09 -0400 Subject: [PATCH] Move report generation to same endpoint URL as report info. --- src/palace/manager/api/admin/routes.py | 2 +- tests/manager/api/admin/test_routes.py | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/palace/manager/api/admin/routes.py b/src/palace/manager/api/admin/routes.py index 76ca5bfc3d..c9cfd50278 100644 --- a/src/palace/manager/api/admin/routes.py +++ b/src/palace/manager/api/admin/routes.py @@ -726,7 +726,7 @@ def inventory_report_info(): @app.route( - "/admin/reports/generate_inventory_report/", + "/admin/reports/inventory_report/", methods=["POST"], ) @allows_library diff --git a/tests/manager/api/admin/test_routes.py b/tests/manager/api/admin/test_routes.py index db79e39b24..ae42b0b7e6 100644 --- a/tests/manager/api/admin/test_routes.py +++ b/tests/manager/api/admin/test_routes.py @@ -753,18 +753,20 @@ def test_change_order(self, fixture: AdminRouteFixture): class TestAdminInventoryReports: CONTROLLER_NAME = "admin_report_controller" + URL = "/admin/reports/inventory_report/" @pytest.fixture(scope="function") def fixture(self, admin_route_fixture: AdminRouteFixture) -> AdminRouteFixture: admin_route_fixture.set_controller_name(self.CONTROLLER_NAME) return admin_route_fixture + def test_inventory_report(self, fixture: AdminRouteFixture): + fixture.assert_supported_methods(self.URL, "GET", "POST") + def test_inventory_report_info( self, fixture: AdminRouteFixture, monkeypatch: pytest.MonkeyPatch ): - url = "/admin/reports/inventory_report/" - fixture.assert_supported_methods(url, "GET") - + url = self.URL mock_response = MagicMock( return_value=Response( '{"collections": []}', @@ -774,7 +776,23 @@ def test_inventory_report_info( ) monkeypatch.setattr(fixture.controller.inventory_report_info, "response", mock_response) # type: ignore fixture.assert_authenticated_request_calls( - url, fixture.controller.inventory_report_info # type: ignore + url, fixture.controller.inventory_report_info, http_method="GET" # type: ignore + ) + + def test_generate_inventory_report( + self, fixture: AdminRouteFixture, monkeypatch: pytest.MonkeyPatch + ): + url = self.URL + mock_response = MagicMock( + return_value=Response( + '{"message": "A success message."}', + status=HTTPStatus.ACCEPTED, + mimetype=MediaTypes.APPLICATION_JSON_MEDIA_TYPE, + ) + ) + monkeypatch.setattr(fixture.controller.generate_inventory_report, "response", mock_response) # type: ignore + fixture.assert_authenticated_request_calls( + url, fixture.controller.generate_inventory_report, http_method="POST" # type: ignore )