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

SFR-2441: Search format type #509

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions tests/integration/api/test_search_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
import requests
from urllib.parse import quote
from .constants import API_URL

@pytest.mark.parametrize("endpoint", [
("/search?query=keyword:NASA&filter=format:readable")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also try to test downloadable format

])
def test_readable_format_flags(endpoint):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what we are testing here is that the search format filter is working as expected. I recommend changing the test name to reflect that.

url = API_URL + quote(endpoint)
response = requests.get(url)

response_json = response.json()
assert response_json is not None, "Response JSON is empty"

works = response_json.get('data', {}).get('works', [])

for work in works:
for edition in work.get('editions', []):
for item in edition.get('items', []):
if any(link.get('mediaType') == "text/html" for link in item.get('links', [])):
flags = item.get('links', [])[0].get('flags', {})
assert flags.get('reader', False) or flags.get('embed', False), \
f"Flags validation failed: {flags}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pull the html links out here and check to make sure that the reader flag is false and the embed is true for each one.

The logic you have here checks if any link has a media type of text/html but then grabs the first link's flags. However, the link at that index may not have a mediaType of "text/html".

You could potentially go further here and check other media type and ensure that the reader flag is True (I think).

Loading