Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Use environment variable to determine whether to filter dead links by default; fix flaky tests (#1043)
sarayourfriendf9b43fda5d71
diff --git a/api/catalog/api/serializers/media_serializers.py b/api/catalog/api/serializers/media_serializers.pyindex a69073c9e..4bf73cae8 100644--- a/api/catalog/api/serializers/media_serializers.py+++ b/api/catalog/api/serializers/media_serializers.py@@ -91,7 +91,7 @@ class MediaSearchRequestSerializer(serializers.Serializer):label="filter_dead",help_text="Control whether 404 links are filtered out.",required=False,- default=True,+ default=settings.FILTER_DEAD_LINKS_BY_DEFAULT,)extension = serializers.CharField(label="extension",diff --git a/api/catalog/settings.py b/api/catalog/settings.pyindex d8eee58b6..4bf3fd877 100644--- a/api/catalog/settings.py+++ b/api/catalog/settings.py@@ -33,6 +33,10 @@ BASE_DIR = Path(__file__).resolve().parent.parent# Where to collect static files in production/development deploymentsSTATIC_ROOT = config("STATIC_ROOT", default="/var/api_static_content/static")+FILTER_DEAD_LINKS_BY_DEFAULT = config(+ "FILTER_DEAD_LINKS_BY_DEFAULT", cast=bool, default=True+)+# Quick-start development settings - unsuitable for production# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/diff --git a/api/env.docker b/api/env.dockerindex e12d4a499..c8481245d 100644--- a/api/env.docker+++ b/api/env.docker@@ -22,3 +22,5 @@ SEMANTIC_VERSION=1.0.0ELASTICSEARCH_URL=esWATERMARK_ENABLED=True++FILTER_DEAD_LINKS_BY_DEFAULT=Falsediff --git a/api/env.template b/api/env.templateindex cb4c80717..3766fe17c 100644--- a/api/env.template+++ b/api/env.template@@ -69,3 +69,5 @@ IS_PROXIED=False#SENTRY_SAMPLE_RATE=1.0#SENTRY_DSN=++#FILTER_DEAD_LINKS_BY_DEFAULT=Falsediff --git a/api/test/audio_integration_test.py b/api/test/audio_integration_test.pyindex 69ad8b8e6..260ada631 100644--- a/api/test/audio_integration_test.py+++ b/api/test/audio_integration_test.py@@ -50,9 +50,7 @@ def force_result_validity():@pytest.fixturedef audio_fixture(force_result_validity):- res = requests.get(- f"{API_URL}/v1/audio/", data={"filter_dead": False}, verify=False- )+ res = requests.get(f"{API_URL}/v1/audio/", verify=False)parsed = res.json()force_result_validity(parsed)assert res.status_code == 200@@ -67,7 +65,7 @@ def jamendo_audio_fixture(force_result_validity):"""res = requests.get(f"{API_URL}/v1/audio/",- data={"source": "jamendo", "filter_dead": False},+ data={"source": "jamendo"},verify=False,)parsed = res.json()@@ -133,7 +131,7 @@ def test_audio_detail_without_thumb():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")assert resp.status_code == 200parsed = json.loads(resp.text)assert parsed["results"][0]["thumbnail"] is Nonediff --git a/api/test/auth_test.py b/api/test/auth_test.pyindex f35b73f2b..d4675a335 100644--- a/api/test/auth_test.py+++ b/api/test/auth_test.py@@ -98,7 +98,7 @@ def test_auth_rate_limit_reporting(@pytest.mark.django_dbdef test_page_size_limit_unauthed(client):- query_params = {"filter_dead": False, "page_size": 20}+ query_params = {"page_size": 20}res = client.get("/v1/images/", query_params)assert res.status_code == 200query_params["page_size"] = 21@@ -110,10 +110,10 @@ def test_page_size_limit_unauthed(client):def test_page_size_limit_authed(client, test_auth_token_exchange):time.sleep(1)token = test_auth_token_exchange["access_token"]- query_params = {"filter_dead": False, "page_size": 21}+ query_params = {"page_size": 21}res = client.get("/v1/images/", query_params, HTTP_AUTHORIZATION=f"Bearer {token}")assert res.status_code == 200- query_params = {"filter_dead": False, "page_size": 500}+ query_params = {"page_size": 500}res = client.get("/v1/images/", query_params, HTTP_AUTHORIZATION=f"Bearer {token}")assert res.status_code == 200diff --git a/api/test/media_integration.py b/api/test/media_integration.pyindex f90acb059..029b4e68d 100644--- a/api/test/media_integration.py+++ b/api/test/media_integration.py@@ -47,12 +47,13 @@ def search_quotes(media_path, q="test"):def search_quotes_exact(media_path, q):"""Only returns exact matches for the given query"""- unquoted_response = requests.get(f"{API_URL}/v1/{media_path}?q={q}", verify=False)+ url_format = f"{API_URL}/v1/{media_path}?q={{q}}"+ unquoted_response = requests.get(url_format.format(q=q), verify=False)assert unquoted_response.status_code == 200unquoted_result_count = unquoted_response.json()["result_count"]assert unquoted_result_count > 0- quoted_response = requests.get(f'{API_URL}/v1/{media_path}?q="{q}"', verify=False)+ quoted_response = requests.get(url_format.format(q=f'"{q}"'), verify=False)assert quoted_response.status_code == 200quoted_result_count = quoted_response.json()["result_count"]assert quoted_result_count > 0diff --git a/api/test/search_qa.py b/api/test/search_qa.pyindex 4c21a57f9..176baee84 100644--- a/api/test/search_qa.py+++ b/api/test/search_qa.py@@ -20,9 +20,7 @@ class QAScores(Enum):@pytest.mark.skip(reason="This test is nondeterministic")def test_phrase_relevance():- res = requests.get(- f"{API_URL}/image/search?q=home office&filter_dead=false&qa=true"- )+ res = requests.get(f"{API_URL}/image/search?q=home office&qa=true")parsed = json.loads(res.text)pprint.pprint(parsed)assert int(parsed["results"][0]["id"]) == QAScores.TARGET.value