From 6e8a96a1ea07789ea0af82c714e938b4b76fab44 Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Mon, 1 Apr 2024 15:57:35 +0300 Subject: [PATCH] Add a test Signed-off-by: Olga Bulat Use script setup and t from useNuxtApp.$i18n Signed-off-by: Olga Bulat --- .../serializers/test_media_serializers.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/test/unit/serializers/test_media_serializers.py b/api/test/unit/serializers/test_media_serializers.py index b6819e3c43d..4347d65d6de 100644 --- a/api/test/unit/serializers/test_media_serializers.py +++ b/api/test/unit/serializers/test_media_serializers.py @@ -97,6 +97,28 @@ def test_media_serializer_adds_license_url_if_missing( assert repr["license_url"] == "https://creativecommons.org/publicdomain/zero/1.0/" +def test_media_serializer_logs_when_invalid_or_duplicate_source(media_type_config): + sources = { + "image": ("flickr,flickr,invalid", "flickr"), + "audio": ("freesound,freesound,invalid", "freesound"), + } + with patch("api.serializers.media_serializers.logger.warning") as mock_logger: + serializer_class = media_type_config.search_request_serializer( + context={"media_type": media_type_config.media_type}, + data={"source": sources[media_type_config.media_type][0]}, + ) + assert serializer_class.is_valid() + print("---", mock_logger.calls[0][0]) + assert ( + serializer_class.validated_data["source"] + == sources[media_type_config.media_type][1] + ) + mock_logger.assert_called_with( + f"Invalid sources in search query: {{'invalid'}}; " + f"sources query: '{sources[media_type_config.media_type][0]}'" + ) + + @pytest.mark.parametrize( "has_sensitive_text", (True, False),