See #432: enforce a maximum number of tags per entity
This commit is contained in:
parent
bd271c8ead
commit
1b34ae2335
5 changed files with 57 additions and 0 deletions
|
|
@ -53,6 +53,24 @@ def test_set_tags(factories, existing, given, expected):
|
|||
assert match.content_object == obj
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"max, tags, expected",
|
||||
[
|
||||
(5, ["hello", "world"], ["hello", "world"]),
|
||||
# we truncate extra tags
|
||||
(1, ["hello", "world"], ["hello"]),
|
||||
(2, ["hello", "world", "foo"], ["hello", "world"]),
|
||||
],
|
||||
)
|
||||
def test_set_tags_honor_TAGS_MAX_BY_OBJ(factories, max, tags, expected, settings):
|
||||
settings.TAGS_MAX_BY_OBJ = max
|
||||
obj = factories["music.Artist"]()
|
||||
|
||||
models.set_tags(obj, *tags)
|
||||
|
||||
assert sorted(obj.tagged_items.values_list("tag__name", flat=True)) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("factory_name", ["music.Track", "music.Album", "music.Artist"])
|
||||
def test_models_that_support_tags(factories, factory_name):
|
||||
tags = ["tag1", "tag2"]
|
||||
|
|
|
|||
|
|
@ -29,3 +29,18 @@ def test_tag_name_field_validation(name):
|
|||
field = serializers.TagNameField()
|
||||
with pytest.raises(serializers.serializers.ValidationError):
|
||||
field.to_internal_value(name)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"max, tags, expected",
|
||||
[
|
||||
(5, ["hello", "world"], ["hello", "world"]),
|
||||
# we truncate extra tags
|
||||
(1, ["hello", "world"], ["hello"]),
|
||||
(2, ["hello", "world", "foo"], ["hello", "world"]),
|
||||
],
|
||||
)
|
||||
def test_tags_list_field_honor_TAGS_MAX_BY_OBJ(max, tags, expected, settings):
|
||||
settings.TAGS_MAX_BY_OBJ = max
|
||||
field = serializers.TagsListField()
|
||||
assert field.to_internal_value(tags) == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue