Ensure tags are lower cased after collecting them from raw_content

merge-requests/130/head
Jason Robinson 2017-03-09 23:13:45 +02:00
rodzic 503076a30c
commit 8ccb8eefdf
4 zmienionych plików z 8 dodań i 3 usunięć

Wyświetl plik

@ -1,5 +1,10 @@
# Changelog
## [unreleased]
### Fixes
* Ensure tags are lower cased after collecting them from entity `raw_content`.
## [0.10.0] - 2017-01-28
### Added

Wyświetl plik

@ -148,7 +148,7 @@ class RawContentMixin(BaseEntity):
"""Returns a `set` of unique tags contained in `raw_content`."""
if not self.raw_content:
return set()
return set({word.strip("#") for word in self.raw_content.split() if word.startswith("#")})
return {word.strip("#").lower() for word in self.raw_content.split() if word.startswith("#") and len(word) > 1}
class OptionalRawContentMixin(RawContentMixin):

Wyświetl plik

@ -11,7 +11,7 @@ from federation.tests.factories.entities import TaggedPostFactory, PostFactory
class TestPostEntityTags(object):
def test_post_entity_returns_list_of_tags(self):
post = TaggedPostFactory()
assert post.tags == {"tagone", "tagtwo", "tagthree"}
assert post.tags == {"tagone", "tagtwo", "tagthree", "upper", "snakecase"}
def test_post_entity_without_raw_content_tags_returns_empty_set(self):
post = PostFactory(raw_content=None)

Wyświetl plik

@ -29,7 +29,7 @@ class TaggedPostFactory(PostFactory):
@factory.lazy_attribute
def raw_content(self):
parts = []
for tag in ["tagone", "tagtwo", "tagthree", "tagthree"]: # Yes, three is twice for fun
for tag in ["tagone", "tagtwo", "tagthree", "tagthree", "SnakeCase", "UPPER", ""]:
parts.append(fuzzy.FuzzyText(length=50).fuzz())
parts.append("#%s" % tag)
shuffle(parts)