Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Fix related media endpoint (#808)
Browse files Browse the repository at this point in the history
* Fix related media endpoint

* Lint

* Use list comprehension

Co-authored-by: Krystle Salazar <[email protected]>

Co-authored-by: Krystle Salazar <[email protected]>
  • Loading branch information
sarayourfriend and krysal authored Jul 21, 2022
1 parent 3c9a120 commit d7962f1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion api/catalog/api/controllers/elasticsearch/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from elasticsearch_dsl import Search
from elasticsearch_dsl.response import Hit

from catalog.api.controllers.elasticsearch.utils import (
exclude_filtered_providers,
Expand Down Expand Up @@ -51,9 +52,16 @@ def related_media(uuid, index, filter_dead):

result_count, _ = get_result_and_page_count(response, results, page_size)

dumpable_results = (
results.to_dict()
if isinstance(results, Hit)
else [r.to_dict() for r in results]
)

logger.debug(
"finished post processing and returning related "
f"result_count={result_count} "
f"results={json.dumps(results)}"
f"results={json.dumps(dumpable_results)}"
)

return results, result_count
2 changes: 1 addition & 1 deletion api/catalog/api/controllers/elasticsearch/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def perform_search(
dumpable_results = (
results.to_dict()
if isinstance(results, Hit)
else list(map(lambda r: r.to_dict(), results))
else [r.to_dict() for r in results]
)

logger.debug(
Expand Down
5 changes: 5 additions & 0 deletions api/test/audio_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from test.media_integration import (
detail,
license_filter_case_insensitivity,
related,
report,
search,
search_all_excluded,
Expand Down Expand Up @@ -122,3 +123,7 @@ def test_audio_uuid_validation():
uuid_validation("audio", "123456789123456789123456789123456789")
uuid_validation("audio", "12345678-1234-5678-1234-1234567891234")
uuid_validation("audio", "abcd")


def test_image_related(audio_fixture):
related(audio_fixture)
5 changes: 5 additions & 0 deletions api/test/image_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from test.media_integration import (
detail,
license_filter_case_insensitivity,
related,
report,
search,
search_all_excluded,
Expand Down Expand Up @@ -139,3 +140,7 @@ def test_image_uuid_validation():
uuid_validation("images", "123456789123456789123456789123456789")
uuid_validation("images", "12345678-1234-5678-1234-1234567891234")
uuid_validation("images", "abcd")


def test_image_related(image_fixture):
related(image_fixture)
6 changes: 6 additions & 0 deletions api/test/media_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@ def license_filter_case_insensitivity(media_type):
def uuid_validation(media_type, identifier):
response = requests.get(f"{API_URL}/v1/{media_type}/{identifier}", verify=False)
assert response.status_code == 404


def related(fixture):
related_url = fixture["results"][0]["related_url"]
response = requests.get(related_url)
assert response.status_code == 200

0 comments on commit d7962f1

Please sign in to comment.