Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we handle ProblemDetail response from _crawlable_feed (PP-1975) #2199

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/palace/manager/api/controller/opds_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SearchFacets,
WorkList,
)
from palace.manager.util.flask_util import OPDSFeedResponse
from palace.manager.util.problem_detail import ProblemDetail


Expand Down Expand Up @@ -243,7 +244,7 @@ def crawlable_list_feed(self, list_name):

def _crawlable_feed(
self, title, url, worklist, annotator=None, feed_class=OPDSAcquisitionFeed
):
) -> OPDSFeedResponse | ProblemDetail:
"""Helper method to create a crawlable feed.
:param title: The title to use for the feed.
Expand All @@ -270,6 +271,8 @@ def _crawlable_feed(
worklist=worklist,
base_class=CrawlableFacets,
)
if isinstance(facets, ProblemDetail):
return facets
annotator = annotator or self.manager.annotator(worklist, facets=facets)

return feed_class.page(
Expand Down
23 changes: 21 additions & 2 deletions tests/manager/api/controller/test_crawlfeed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from contextlib import contextmanager
from typing import Any
from unittest.mock import MagicMock
from unittest.mock import MagicMock, create_autospec

import feedparser
from flask import url_for
Expand All @@ -13,7 +13,11 @@
CrawlableFacets,
DynamicLane,
)
from palace.manager.api.problem_details import NO_SUCH_COLLECTION, NO_SUCH_LIST
from palace.manager.api.problem_details import (
NO_SUCH_COLLECTION,
NO_SUCH_LANE,
NO_SUCH_LIST,
)
from palace.manager.core.problem_details import INVALID_INPUT
from palace.manager.feed.acquisition import OPDSAcquisitionFeed
from palace.manager.feed.annotator.circulation import CirculationManagerAnnotator
Expand Down Expand Up @@ -226,6 +230,21 @@ def works(self, _db, facets, pagination, *args, **kwargs):
title="Lane title", url="Lane URL", worklist=mock_lane, feed_class=MockFeed
)

# Lane that cannot be accessed -> problem detail
inaccessible_lane = MockLane()
inaccessible_lane.accessible_to = create_autospec(
mock_lane.accessible_to, return_value=False
)
with circulation_fixture.request_context_with_library("/"):
response = circulation_fixture.manager.opds_feeds._crawlable_feed(
title="Lane title",
url="Lane URL",
worklist=inaccessible_lane,
feed_class=MockFeed,
)
assert isinstance(response, ProblemDetail)
assert NO_SUCH_LANE.uri == response.uri

# Bad pagination data -> problem detail
with circulation_fixture.app.test_request_context("/?size=a"):
response = circulation_fixture.manager.opds_feeds._crawlable_feed(
Expand Down
Loading