From 63f126cddc5296cbf28f7e0d2569aaccd2d79190 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Wed, 23 Mar 2022 14:21:00 +0300 Subject: [PATCH 1/5] Replace plural `categories` as field name with singular `category` Signed-off-by: Olga Bulat --- api/catalog/api/serializers/audio_serializers.py | 6 +++--- api/catalog/api/serializers/image_serializers.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/catalog/api/serializers/audio_serializers.py b/api/catalog/api/serializers/audio_serializers.py index e1a6eea00..fcc5b60d1 100644 --- a/api/catalog/api/serializers/audio_serializers.py +++ b/api/catalog/api/serializers/audio_serializers.py @@ -52,7 +52,7 @@ class AudioSearchRequestSerializer( fields_names = [ *MediaSearchRequestSerializer.fields_names, *AudioSearchRequestSourceSerializer.field_names, - "categories", + "category", "duration", ] """ @@ -60,8 +60,8 @@ class AudioSearchRequestSerializer( used to generate Swagger documentation. """ - categories = serializers.CharField( - label="categories", + category = serializers.CharField( + label="category", help_text="A comma separated list of categories; available categories " "include `music`, `sound_effect`, `podcast`, `audiobook`, " "and `news`.", diff --git a/api/catalog/api/serializers/image_serializers.py b/api/catalog/api/serializers/image_serializers.py index 3def2a669..17dee58db 100644 --- a/api/catalog/api/serializers/image_serializers.py +++ b/api/catalog/api/serializers/image_serializers.py @@ -26,7 +26,7 @@ class ImageSearchRequestSerializer( fields_names = [ *MediaSearchRequestSerializer.fields_names, *ImageSearchRequestSourceSerializer.field_names, - "categories", + "category", "aspect_ratio", "size", ] @@ -36,8 +36,8 @@ class ImageSearchRequestSerializer( """ # Ref: ingestion_server/ingestion_server/categorize.py#Category - categories = serializers.CharField( - label="categories", + category = serializers.CharField( + label="category", help_text="A comma separated list of categories; available categories " "include `illustration`, `photograph`, and " "`digitized_artwork`.", From df76e2cae2e72b08a3b663fee470bdb76f043a9f Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Wed, 23 Mar 2022 19:50:09 +0300 Subject: [PATCH 2/5] Replace `categories` in the search controller Signed-off-by: Olga Bulat --- api/catalog/api/controllers/search_controller.py | 2 +- api/catalog/api/serializers/media_serializers.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/catalog/api/controllers/search_controller.py b/api/catalog/api/controllers/search_controller.py index e96585aee..bebbd86c7 100644 --- a/api/catalog/api/controllers/search_controller.py +++ b/api/catalog/api/controllers/search_controller.py @@ -239,7 +239,7 @@ def search( # names are identical. filters = [ ("extension", None), - ("categories", None), + ("category", None), ("aspect_ratio", None), ("size", None), ("source", None), diff --git a/api/catalog/api/serializers/media_serializers.py b/api/catalog/api/serializers/media_serializers.py index 6bb046a49..586410906 100644 --- a/api/catalog/api/serializers/media_serializers.py +++ b/api/catalog/api/serializers/media_serializers.py @@ -152,6 +152,7 @@ class MediaSearchRequestSerializer(serializers.Serializer): DeprecatedParam("lt", "license_type"), DeprecatedParam("pagesize", "page_size"), DeprecatedParam("provider", "source"), + DeprecatedParam("categories", "category"), ] fields_names = [ "q", From 2f13b8c071fbc97f9733cccd9f9d06b30426a0db Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Wed, 23 Mar 2022 19:52:06 +0300 Subject: [PATCH 3/5] Make `categories` work, too Signed-off-by: Olga Bulat --- api/catalog/api/controllers/search_controller.py | 1 + api/catalog/api/serializers/media_serializers.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/api/catalog/api/controllers/search_controller.py b/api/catalog/api/controllers/search_controller.py index bebbd86c7..626eb7c0a 100644 --- a/api/catalog/api/controllers/search_controller.py +++ b/api/catalog/api/controllers/search_controller.py @@ -240,6 +240,7 @@ def search( filters = [ ("extension", None), ("category", None), + ("categories", "category"), ("aspect_ratio", None), ("size", None), ("source", None), diff --git a/api/catalog/api/serializers/media_serializers.py b/api/catalog/api/serializers/media_serializers.py index 586410906..6bb046a49 100644 --- a/api/catalog/api/serializers/media_serializers.py +++ b/api/catalog/api/serializers/media_serializers.py @@ -152,7 +152,6 @@ class MediaSearchRequestSerializer(serializers.Serializer): DeprecatedParam("lt", "license_type"), DeprecatedParam("pagesize", "page_size"), DeprecatedParam("provider", "source"), - DeprecatedParam("categories", "category"), ] fields_names = [ "q", From c50672b708391de32642cf982e9348f6c879d296 Mon Sep 17 00:00:00 2001 From: Krystle Salazar Date: Thu, 24 Mar 2022 00:48:18 -0400 Subject: [PATCH 4/5] Add test for category filtering (#584) --- api/test/audio_integration_test.py | 6 ++++++ api/test/media_integration.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/api/test/audio_integration_test.py b/api/test/audio_integration_test.py index 72bf5f05c..b2415bdc6 100644 --- a/api/test/audio_integration_test.py +++ b/api/test/audio_integration_test.py @@ -10,6 +10,7 @@ report, search, search_all_excluded, + search_by_category, search_consistency, search_quotes, search_source_and_excluded, @@ -34,6 +35,11 @@ def test_search(audio_fixture): search(audio_fixture) +def test_search_category_filtering(audio_fixture): + search_by_category("audio", "music", audio_fixture) + search_by_category("audio", "pronuntiation", audio_fixture) + + def test_search_all_excluded(): search_all_excluded("audio", ["jamendo", "wikimedia_audio"]) diff --git a/api/test/media_integration.py b/api/test/media_integration.py index 51b858e11..9bc1c3409 100644 --- a/api/test/media_integration.py +++ b/api/test/media_integration.py @@ -14,6 +14,16 @@ def search(fixture): assert fixture["result_count"] > 0 +def search_by_category(media_path, category, fixture): + response = requests.get(f"{API_URL}/v1/{media_path}?category={category}") + assert response.status_code == 200 + data = json.loads(response.text) + assert data["result_count"] < fixture["result_count"] + results = data["results"] + # Make sure each result is from the specified category + assert all(audio_item["category"] == category for audio_item in results) + + def search_all_excluded(media_path, excluded_source): response = requests.get( f"{API_URL}/v1/{media_path}?q=test&excluded_source={','.join(excluded_source)}" From 422aae2fa4bd0fe85d91ea9e79e95af4bd4dd751 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Fri, 25 Mar 2022 17:22:14 +0300 Subject: [PATCH 5/5] Update api/test/audio_integration_test.py Co-authored-by: Madison Swain-Bowden --- api/test/audio_integration_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/test/audio_integration_test.py b/api/test/audio_integration_test.py index b2415bdc6..f545cdb62 100644 --- a/api/test/audio_integration_test.py +++ b/api/test/audio_integration_test.py @@ -37,7 +37,7 @@ def test_search(audio_fixture): def test_search_category_filtering(audio_fixture): search_by_category("audio", "music", audio_fixture) - search_by_category("audio", "pronuntiation", audio_fixture) + search_by_category("audio", "pronunciation", audio_fixture) def test_search_all_excluded():