Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Olga Bulat <[email protected]>

Use script setup and t from useNuxtApp.$i18n

Signed-off-by: Olga Bulat <[email protected]>
  • Loading branch information
obulat committed Apr 1, 2024
1 parent c793630 commit 6e8a96a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/test/unit/serializers/test_media_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 6e8a96a

Please sign in to comment.