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

Use environment variable to determine whether to filter dead links by default; fix flaky tests #1043

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/catalog/api/serializers/media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions api/catalog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
# Where to collect static files in production/development deployments
STATIC_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/

Expand Down
2 changes: 2 additions & 0 deletions api/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ SEMANTIC_VERSION=1.0.0
ELASTICSEARCH_URL=es

WATERMARK_ENABLED=True

FILTER_DEAD_LINKS_BY_DEFAULT=False
2 changes: 2 additions & 0 deletions api/env.template
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ IS_PROXIED=False

#SENTRY_SAMPLE_RATE=1.0
#SENTRY_DSN=

#FILTER_DEAD_LINKS_BY_DEFAULT=False
8 changes: 3 additions & 5 deletions api/test/audio_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def force_validity(query_response):

@pytest.fixture
def 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
Expand All @@ -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()
Expand Down Expand Up @@ -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 == 200
parsed = json.loads(resp.text)
assert parsed["results"][0]["thumbnail"] is None
Expand Down
6 changes: 3 additions & 3 deletions api/test/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_auth_rate_limit_reporting(

@pytest.mark.django_db
def 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 == 200
query_params["page_size"] = 21
Expand All @@ -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 == 200
5 changes: 3 additions & 2 deletions api/test/media_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == 200
unquoted_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 == 200
quoted_result_count = quoted_response.json()["result_count"]
assert quoted_result_count > 0
Expand Down
4 changes: 1 addition & 3 deletions api/test/search_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down