Skip to content

Commit

Permalink
Move report generation to same endpoint URL as report info.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed May 13, 2024
1 parent 16b181c commit 182b162
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/palace/manager/api/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def inventory_report_info():


@app.route(
"/admin/reports/generate_inventory_report/<path:library_short_name>",
"/admin/reports/inventory_report/<path:library_short_name>",
methods=["POST"],
)
@allows_library
Expand Down
26 changes: 22 additions & 4 deletions tests/manager/api/admin/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,18 +753,20 @@ def test_change_order(self, fixture: AdminRouteFixture):

class TestAdminInventoryReports:
CONTROLLER_NAME = "admin_report_controller"
URL = "/admin/reports/inventory_report/<library_short_name>"

@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/<library_short_name>"
fixture.assert_supported_methods(url, "GET")

url = self.URL
mock_response = MagicMock(
return_value=Response(
'{"collections": []}',
Expand All @@ -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
)


Expand Down

0 comments on commit 182b162

Please sign in to comment.