Skip to content

Commit

Permalink
mocks: Use archive & published repos for TestSearchProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Mar 28, 2024
1 parent ec32d82 commit 2800e0a
Showing 1 changed file with 10 additions and 72 deletions.
82 changes: 10 additions & 72 deletions superdesk/tests/mocks/search_provider.py
Original file line number Diff line number Diff line change
@@ -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": "<p>Test English body</p>",
"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": "<p>Test Deutsch body</p>",
"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": "<p>Test Deutsch body 2</p>",
"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": "<p>Test French body</p>",
"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
Expand Down

0 comments on commit 2800e0a

Please sign in to comment.