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

Commit

Permalink
Define request response mappings and use them to run tests on the end…
Browse files Browse the repository at this point in the history
…points
  • Loading branch information
dhruvkb committed Sep 1, 2021
1 parent 4862f95 commit a001243
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openverse-api/catalog/api/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
39 changes: 39 additions & 0 deletions openverse-api/test/examples_test.py
Original file line number Diff line number Diff line change
@@ -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']

0 comments on commit a001243

Please sign in to comment.