diff --git a/superdesk/tests/mocks/search_provider.py b/superdesk/tests/mocks/search_provider.py index bf84a0013b..0f832ab2f8 100644 --- a/superdesk/tests/mocks/search_provider.py +++ b/superdesk/tests/mocks/search_provider.py @@ -1,85 +1,23 @@ -from superdesk import SearchProvider, register_search_provider -from superdesk.utils import ListCursor +from flask import json +from eve.utils import ParsedRequest + +from superdesk import SearchProvider, register_search_provider, get_resource_service from superdesk.errors import SuperdeskApiError from apps.search_providers import allowed_search_providers - - -FIXTURES = [ - { - "type": "text", - "mimetype": "application/superdesk.item.text", - "pubstatus": "usable", - "_id": "urn:localhost:sofab:english-abcd123", - "guid": "urn:localhost:sofab:english-abcd123", - "headline": "Test English Headline", - "slugline": "test-slugline", - "body_html": "

Test English body

", - "versioncreated": "2024-03-20T15:27:15Z", - "firstcreated": "2024-03-20T15:27:15Z", - "source": "sofab", - "language": "en", - "word_count": 3, - "_fetchable": False, - }, - { - "type": "text", - "mimetype": "application/superdesk.item.text", - "pubstatus": "usable", - "_id": "urn:localhost:sofab:deutsch-abcd123", - "guid": "urn:localhost:sofab:deutsch-abcd123", - "headline": "Test Deutsch Headline", - "slugline": "test-slugline", - "body_html": "

Test Deutsch body

", - "versioncreated": "2024-03-20T15:27:15Z", - "firstcreated": "2024-03-20T15:27:15Z", - "source": "sofab", - "language": "de", - "word_count": 3, - "_fetchable": False, - }, - { - "type": "text", - "mimetype": "application/superdesk.item.text", - "pubstatus": "usable", - "_id": "urn:localhost:sofab:deutsch-abcd123-2", - "guid": "urn:localhost:sofab:deutsch-abcd123-2", - "headline": "Test Deutsch Headline 2", - "slugline": "test-slugline", - "body_html": "

Test Deutsch body 2

", - "versioncreated": "2024-03-20T15:27:15Z", - "firstcreated": "2024-03-20T15:27:15Z", - "source": "sofab", - "language": "de", - "word_count": 4, - "_fetchable": False, - }, - { - "type": "text", - "mimetype": "application/superdesk.item.text", - "pubstatus": "usable", - "_id": "urn:localhost:sofab:french-abcd123", - "guid": "urn:localhost:sofab:french-abcd123", - "headline": "Test French Headline", - "slugline": "test-slugline", - "body_html": "

Test French body

", - "versioncreated": "2024-03-20T15:27:15Z", - "firstcreated": "2024-03-20T15:27:15Z", - "source": "sofab", - "language": "fr", - "word_count": 3, - "_fetchable": False, - }, -] +from apps.archive.common import ARCHIVE class TestSearchProvider(SearchProvider): label = "Test Search Provider" def find(self, query): - return ListCursor(FIXTURES) + request = ParsedRequest() + request.args = {"source": json.dumps(query), "repo": "archive,published"} + return get_resource_service("search").get(req=request, lookup=None) def fetch(self, guid): - item = next((item for item in FIXTURES if item.get("_id") == guid), None) + item = get_resource_service(ARCHIVE).find_one(req=None, _id=guid) + if item is None: raise SuperdeskApiError.notFoundError("Search item not found") return item