diff --git a/api/test/unit/serializers/test_media_serializers.py b/api/test/unit/serializers/test_media_serializers.py index 3b854980c73..ea2500a2681 100644 --- a/api/test/unit/serializers/test_media_serializers.py +++ b/api/test/unit/serializers/test_media_serializers.py @@ -99,6 +99,27 @@ 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() + 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),