diff --git a/openverse-api/catalog/api/examples/__init__.py b/openverse-api/catalog/api/examples/__init__.py index 550027607..9d6f55bf5 100644 --- a/openverse-api/catalog/api/examples/__init__.py +++ b/openverse-api/catalog/api/examples/__init__.py @@ -37,3 +37,17 @@ image_oembed_200_example, image_oembed_404_example, ) + +audio_mappings = { + audio_search_curl: audio_search_200_example, + audio_stats_curl: audio_stats_200_example, + audio_detail_curl: audio_detail_200_example, + audio_complain_curl: audio_complain_201_example, +} +image_mappings = { + image_search_curl: image_search_200_example, + image_stats_curl: image_stats_200_example, + image_detail_curl: image_detail_200_example, + image_complain_curl: image_complain_201_example, + image_oembed_curl: image_oembed_200_example, +} diff --git a/openverse-api/test/examples_test.py b/openverse-api/test/examples_test.py new file mode 100644 index 000000000..2c64937f5 --- /dev/null +++ b/openverse-api/test/examples_test.py @@ -0,0 +1,39 @@ +import json +import os +import subprocess + +import pytest + +from test.constants import API_URL + +os.environ['AUDIO_REQ_TOKEN'] = '' +os.environ['AUDIO_REQ_ORIGIN'] = API_URL +os.environ['AUDIO_REQ_IDX'] = '440a0240-8b20-49e2-a4e6-6fee550fcc41' + +from catalog.api.examples import ( # noqa | Set env vars before import + audio_mappings, + image_mappings, +) + + +def execute_request(request): + proc = subprocess.run(request, check=True, capture_output=True, shell=True) + return json.loads(proc.stdout) + + +@pytest.mark.parametrize( + 'in_val, out_val', + list(audio_mappings.items()) +) +def test_audio_success_examples(in_val, out_val): + res = execute_request(in_val) + assert res == out_val['application/json'] + + +@pytest.mark.parametrize( + 'in_val, out_val', + list(image_mappings.items()) +) +def test_image_success_examples(in_val, out_val): + res = execute_request(in_val) + assert res == out_val['application/json']