Skip to content

Commit

Permalink
yeah, well
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesivsm committed Jan 29, 2018
1 parent 37f59d9 commit 5a06d8e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 43 deletions.
3 changes: 2 additions & 1 deletion jarr_common/article_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ def _is_filter_matching(filter_, article):
pattern = filter_.get('pattern', '')
filter_type = FiltersType(filter_.get('type'))
filter_trigger = FiltersTrigger(filter_.get('action on'))
title = article.get('title', '')
if filter_type is not FiltersType.REGEX:
pattern = pattern.lower()
title = article.get('title', '').lower()
title = title.lower()
tags = [tag.lower() for tag in article.get('tags', [])]
if filter_type is FiltersType.REGEX:
match = re.match(pattern, title)
Expand Down
73 changes: 31 additions & 42 deletions tests/controllers/article_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ def test_article_rights(self):

def test_create_using_filters(self):
feed_ctr = FeedController(2)
feed1 = feed_ctr.read()[0].dump()
feed2 = feed_ctr.read()[1].dump()
feed3 = feed_ctr.read()[2].dump()
art_ctr = ArticleController(2)
feed1, feed2, feed3 = [f.dump() for f in feed_ctr.read()][0:3]
feed_ctr.update({'id': feed3['id']},
{'filters': [{"type": "regex",
"pattern": ".*(pattern1|pattern2).*",
Expand All @@ -39,46 +38,41 @@ def test_create_using_filters(self):
"action on": "match",
"action": "skipped"}]})

art1 = ArticleController(2).create(
entry_id="will be read and faved 1",
feed_id=feed1['id'],
title="garbage pattern1 pattern3 garbage",
content="doesn't matter",
link="cluster1")
art1 = art_ctr.create(entry_id="will be read and faved 1",
feed_id=feed1['id'],
title="garbage pattern1 pattern3 garbage",
content="doesn't matter",
link="cluster1")
self.assertTrue(art1.cluster.read)
self.assertFalse(art1.cluster.liked)

art2 = ArticleController(2).create(
entry_id="will be ignored 2",
feed_id=feed1['id'],
title="garbage see pattern garbage",
content="doesn't matter2",
link="is ignored 2")
art2 = art_ctr.create(entry_id="will be ignored 2",
feed_id=feed1['id'],
title="garbage see pattern garbage",
content="doesn't matter2",
link="is ignored 2")
self.assertFalse(art2.cluster.read)
self.assertFalse(art2.cluster.liked)

art3 = ArticleController(2).create(
entry_id="will be read 3",
user_id=2,
feed_id=feed2['id'],
title="garbage pattern3 garbage",
content="doesn't matter",
link="doesn't matter either3")
art3 = art_ctr.create(entry_id="will be read 3",
user_id=2,
feed_id=feed2['id'],
title="garbage pattern3 garbage",
content="doesn't matter",
link="doesn't matter either3")
self.assertFalse(art3.cluster.read)
self.assertFalse(art3.cluster.liked)

art4 = ArticleController(2).create(
entry_id="will be ignored 4",
user_id=2,
feed_id=feed2['id'],
title="garbage see pattern garbage",
content="doesn't matter2",
link="doesn't matter either4")
art4 = art_ctr.create(entry_id="will be ignored 4",
user_id=2,
feed_id=feed2['id'],
title="garbage see pattern garbage",
content="doesn't matter2",
link="doesn't matter either4")
self.assertFalse(art4.cluster.read)
self.assertFalse(art4.cluster.liked)

art5 = ArticleController(2).create(
entry_id="will be faved 5",
art5 = art_ctr.create(entry_id="will be faved 5",
feed_id=feed3['id'],
title="garbage anti-attern3 garbage",
content="doesn't matter",
Expand All @@ -87,26 +81,23 @@ def test_create_using_filters(self):
"should be read because it clustered")
self.assertTrue(art5.cluster.liked)

art6 = ArticleController(2).create(
entry_id="will be faved 6",
art6 = art_ctr.create(entry_id="will be faved 6",
feed_id=feed3['id'],
title="garbage pattern1 garbage",
content="doesn't matter2",
link="doesn't matter 6")
self.assertFalse(art6.cluster.read)
self.assertFalse(art6.cluster.liked)

art7 = ArticleController(2).create(
entry_id="will be read 7",
art7 = art_ctr.create(entry_id="will be read 7",
feed_id=feed3['id'],
title="garbage pattern3 garbage",
content="doesn't matter3",
link="doesn't matter either7")
self.assertTrue(art7.cluster.read)
self.assertTrue(art7.cluster.liked)

art8 = ArticleController(2).create(
entry_id="will be ignored",
art8 = art_ctr.create(entry_id="will be ignored",
feed_id=feed3['id'],
title="garbage pattern4 garbage",
content="doesn't matter4-matter4_matter4",
Expand All @@ -115,8 +106,7 @@ def test_create_using_filters(self):
self.assertFalse(art8.cluster.read)
self.assertTrue(art8.cluster.liked)

art9 = ArticleController(2).create(
entry_id="unique9",
art9 = art_ctr.create(entry_id="unique9",
feed_id=feed2['id'],
title="garbage", tags=['garbage', 'pattern4'],
content="doesn't matterç",
Expand All @@ -125,12 +115,11 @@ def test_create_using_filters(self):
self.assertEqual(0,
ArticleController(2).read(entry_id='unique9').count())

art10 = ArticleController(2).create(
art10 = art_ctr.create(
entry_id="will be ignored",
feed_id=feed2['id'],
title="garbage", tags=['pattern5 garbage', 'garbage'],
content="doesn't matter10",
link="doesn't matter either10")
self.assertIsNone(art10)
self.assertEqual(0,
ArticleController(2).read(entry_id='unique10').count())
self.assertEqual(0, art_ctr.read(entry_id='unique10').count())

0 comments on commit 5a06d8e

Please sign in to comment.