2019-07-15 09:32:14 +00:00
|
|
|
|
import pytest
|
|
|
|
|
|
2019-07-09 14:03:41 +00:00
|
|
|
|
from funkwhale_api.tags import serializers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_tag_serializer(factories):
|
|
|
|
|
tag = factories["tags.Tag"]()
|
|
|
|
|
|
|
|
|
|
serializer = serializers.TagSerializer(tag)
|
|
|
|
|
|
|
|
|
|
expected = {
|
|
|
|
|
"name": tag.name,
|
|
|
|
|
"creation_date": tag.creation_date.isoformat().split("+")[0] + "Z",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert serializer.data == expected
|
2019-07-15 09:32:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"name",
|
|
|
|
|
[
|
|
|
|
|
"",
|
|
|
|
|
"invalid because spaces",
|
|
|
|
|
"invalid-because-dashes",
|
|
|
|
|
"invalid because non breaking spaces",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_tag_name_field_validation(name):
|
|
|
|
|
field = serializers.TagNameField()
|
|
|
|
|
with pytest.raises(serializers.serializers.ValidationError):
|
|
|
|
|
field.to_internal_value(name)
|