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

Commit

Permalink
Make thumbnail link null for in audio detail endpoint when it doesn't…
Browse files Browse the repository at this point in the history
… exist (#765)
krysal authored Jun 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c2df644 commit 7414174
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions api/catalog/api/serializers/audio_serializers.py
Original file line number Diff line number Diff line change
@@ -138,12 +138,14 @@ def get_peaks(obj) -> list[int]:
def to_representation(self, instance):
# Get the original representation
output = super().to_representation(instance)
audio = instance

if isinstance(instance, Hit):
# TODO: Remove when updating ES indexes
# TODO: Remove this DB query when updating ES index
audio = Audio.objects.get(identifier=instance.identifier)
if not audio.thumbnail:
output["thumbnail"] = None

if isinstance(audio, Audio) and not audio.thumbnail:
output["thumbnail"] = None

return output

11 changes: 9 additions & 2 deletions api/test/audio_integration_test.py
Original file line number Diff line number Diff line change
@@ -81,9 +81,16 @@ def test_audio_thumb(audio_fixture):
thumb(audio_fixture)


def test_audio_without_thumb():
def test_audio_detail_without_thumb():
resp = requests.get(f"{API_URL}/v1/audio/00289ffb-0c74-4008-8388-0bf6d8173dee")
assert resp.status_code == 200
parsed = json.loads(resp.text)
assert parsed["thumbnail"] is None


def test_audio_search_without_thumb():
"""The first audio of this search should not have a thumbnail."""
resp = requests.get(f"{API_URL}/v1/audio?q=zaus&filter_dead=false")
resp = requests.get(f"{API_URL}/v1/audio/?q=zaus&filter_dead=false")
assert resp.status_code == 200
parsed = json.loads(resp.text)
assert parsed["results"][0]["thumbnail"] is None

0 comments on commit 7414174

Please sign in to comment.