From 8ccb8eefdf95b99f32b08c16e02fb8b2dcd5c5b1 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Thu, 9 Mar 2017 23:13:45 +0200 Subject: [PATCH 1/2] Ensure tags are lower cased after collecting them from raw_content --- CHANGELOG.md | 5 +++++ federation/entities/base.py | 2 +- federation/tests/entities/test_base.py | 2 +- federation/tests/factories/entities.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8681f0a..3a6d60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/federation/entities/base.py b/federation/entities/base.py index 89dc55a..5d8261c 100644 --- a/federation/entities/base.py +++ b/federation/entities/base.py @@ -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): diff --git a/federation/tests/entities/test_base.py b/federation/tests/entities/test_base.py index f4b769f..c0ec687 100644 --- a/federation/tests/entities/test_base.py +++ b/federation/tests/entities/test_base.py @@ -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) diff --git a/federation/tests/factories/entities.py b/federation/tests/factories/entities.py index bce2f49..7e9fdf0 100644 --- a/federation/tests/factories/entities.py +++ b/federation/tests/factories/entities.py @@ -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) From 59d2b71041428468915f75c0ed724941d2a78f70 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Thu, 9 Mar 2017 23:14:47 +0200 Subject: [PATCH 2/2] Make pep8speaks less verbose --- .pep8speaks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.pep8speaks.yml b/.pep8speaks.yml index be24d89..0b17ac3 100644 --- a/.pep8speaks.yml +++ b/.pep8speaks.yml @@ -5,3 +5,5 @@ pycodestyle: max-line-length: 120 ignore: - E402 + +no_blank_comment: True