aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-05-19 10:21:07 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-07-02 15:34:16 +0200
commit5fba105078286cebb299eaa59eec4f801b5bc84e (patch)
treea5f11e56d9d8f1bdc861c2913d6d230490f2691c
parentadding filters mechanism + splitting tests + adding tests for filters (diff)
downloadnewspipe-5fba105078286cebb299eaa59eec4f801b5bc84e.tar.gz
newspipe-5fba105078286cebb299eaa59eec4f801b5bc84e.tar.bz2
newspipe-5fba105078286cebb299eaa59eec4f801b5bc84e.zip
adding comments and tests
-rw-r--r--pyaggr3g470r/controllers/article.py9
-rw-r--r--tests/controllers/article.py10
2 files changed, 11 insertions, 8 deletions
diff --git a/pyaggr3g470r/controllers/article.py b/pyaggr3g470r/controllers/article.py
index 9051a910..b3a79838 100644
--- a/pyaggr3g470r/controllers/article.py
+++ b/pyaggr3g470r/controllers/article.py
@@ -33,15 +33,16 @@ class ArticleController(AbstractController):
.group_by(Article.feed_id).all())
def create(self, **attrs):
+ # handling special denorm for article rights
assert 'feed_id' in attrs
feed = FeedController(
attrs.get('user_id', self.user_id)).get(id=attrs['feed_id'])
if 'user_id' in attrs:
assert feed.user_id == attrs['user_id'] or self.user_id is None
attrs['user_id'] = feed.user_id
- if not feed.filters:
- return super().create(**attrs)
- for filter_ in feed.filters:
+
+ # handling feed's filters
+ for filter_ in feed.filters or []:
match = False
if filter_.get('type') == 'regex':
match = re.match(filter_['pattern'], attrs.get('title', ''))
@@ -63,5 +64,3 @@ class ArticleController(AbstractController):
attrs['link'])
return super().create(**attrs)
-
-
diff --git a/tests/controllers/article.py b/tests/controllers/article.py
index 51260546..5e873694 100644
--- a/tests/controllers/article.py
+++ b/tests/controllers/article.py
@@ -41,7 +41,11 @@ class ArticleControllerTest(BasePyaggTest):
{'filters': [{"type": "regex",
"pattern": ".*(pattern1|pattern2).*",
"action on": "no match",
- "action": "mark as favorite"}]})
+ "action": "mark as favorite"},
+ {"type": "simple match",
+ "pattern": "no see pattern",
+ "action on": "match",
+ "action": "mark as read"}]})
art1 = ArticleController(2).create(
entry_id="thisisnotatest",
feed_id=feed1['id'],
@@ -85,7 +89,7 @@ class ArticleControllerTest(BasePyaggTest):
art7 = ArticleController(2).create(
entry_id="thisisnotatesteither",
feed_id=feed3['id'],
- title="garbage pattern3 garbage",
+ title="garbage no see pattern3 garbage",
content="doesn't matter3",
link="doesn't matter either3")
art8 = ArticleController(2).create(
@@ -107,7 +111,7 @@ class ArticleControllerTest(BasePyaggTest):
self.assertFalse(art5.like)
self.assertFalse(art6.readed)
self.assertFalse(art6.like)
- self.assertFalse(art7.readed)
+ self.assertTrue(art7.readed)
self.assertTrue(art7.like)
self.assertFalse(art8.readed)
self.assertTrue(art8.like)
bgstack15