diff --git a/tildes/tests/test_topic_tags.py b/tildes/tests/test_topic_tags.py index 5fc8104..a988be4 100644 --- a/tildes/tests/test_topic_tags.py +++ b/tildes/tests/test_topic_tags.py @@ -36,3 +36,9 @@ def test_tags_lowercased(text_topic): """Ensure tags get converted to lowercase.""" text_topic.tags = ["ONE", "Two", "thRee"] assert text_topic.tags == ["one", "two", "three"] + + +def test_tags_synonyms(text_topic): + """ Ensure synonyms are replaced.""" + text_topic.tags = ["spoilers"] + assert text_topic.tags == ["spoiler"] diff --git a/tildes/tildes/schemas/topic.py b/tildes/tildes/schemas/topic.py index 8e6fc0b..0019555 100644 --- a/tildes/tildes/schemas/topic.py +++ b/tildes/tildes/schemas/topic.py @@ -16,6 +16,7 @@ from tildes.schemas.group import GroupSchema from tildes.schemas.user import UserSchema TITLE_MAX_LENGTH = 200 +TAG_SYNONYMS = {"spoiler": ["spoilers"]} class TopicSchema(Schema): @@ -57,6 +58,11 @@ class TopicSchema(Schema): if not tag or tag.isspace(): continue + # handle synonyms + for name, synonyms in TAG_SYNONYMS.items(): + if tag in synonyms: + tag = name + # skip any duplicate tags if tag in tags: continue