aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-11-17 08:30:06 +0100
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-11-17 08:30:06 +0100
commitb0e987fbafaa28226c54157fb11993079c5341e2 (patch)
tree1f0cd04a505dce4680155f8bb4c7bb757984c030 /src/tests
parentBugfix: should import Article in order to resolve the 'date' column for the o... (diff)
downloadnewspipe-b0e987fbafaa28226c54157fb11993079c5341e2.tar.gz
newspipe-b0e987fbafaa28226c54157fb11993079c5341e2.tar.bz2
newspipe-b0e987fbafaa28226c54157fb11993079c5341e2.zip
cleaning the mess in the libs directories
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/__init__.py0
-rw-r--r--src/tests/base.py41
-rw-r--r--src/tests/controllers/__init__.py5
-rw-r--r--src/tests/controllers/article.py117
-rw-r--r--src/tests/controllers/feed.py27
-rw-r--r--src/tests/fixtures.py31
6 files changed, 0 insertions, 221 deletions
diff --git a/src/tests/__init__.py b/src/tests/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/src/tests/__init__.py
+++ /dev/null
diff --git a/src/tests/base.py b/src/tests/base.py
deleted file mode 100644
index d6f62583..00000000
--- a/src/tests/base.py
+++ /dev/null
@@ -1,41 +0,0 @@
-import os
-os.environ['PYAGG_TESTING'] = 'true'
-
-import unittest
-from bootstrap import db
-import runserver
-from tests.fixtures import populate_db, reset_db
-from werkzeug.exceptions import NotFound
-
-
-class BasePyaggTest(unittest.TestCase):
- _contr_cls = None
-
- def _get_from_contr(self, obj_id, user_id=None):
- return self._contr_cls(user_id).get(id=obj_id).dump()
-
- def _test_controller_rights(self, obj, user_id):
- obj_id = obj['id']
- self.assertEquals(obj, self._get_from_contr(obj_id))
- self.assertEquals(obj, self._get_from_contr(obj_id, user_id))
- # fetching non existent object
- self.assertRaises(NotFound, self._get_from_contr, 99, user_id)
- # fetching object with inexistent user
- self.assertRaises(NotFound, self._get_from_contr, obj_id, 99)
- # fetching object with wrong user
- self.assertRaises(NotFound, self._get_from_contr, obj_id, user_id + 1)
- self.assertRaises(NotFound, self._contr_cls().delete, 99)
- self.assertRaises(NotFound, self._contr_cls(user_id).delete, 99)
- self.assertEquals(obj['id'],
- self._contr_cls(user_id).delete(obj_id).id)
- self.assertRaises(NotFound, self._contr_cls(user_id).delete, obj_id)
-
- def setUp(self):
- populate_db(db)
-
- def tearDown(self):
- reset_db(db)
-
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/src/tests/controllers/__init__.py b/src/tests/controllers/__init__.py
deleted file mode 100644
index 26922c43..00000000
--- a/src/tests/controllers/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from tests.controllers.feed import FeedControllerTest
-from tests.controllers.article import ArticleControllerTest
-
-
-__all__ = ['FeedControllerTest', 'ArticleControllerTest']
diff --git a/src/tests/controllers/article.py b/src/tests/controllers/article.py
deleted file mode 100644
index a62d1a83..00000000
--- a/src/tests/controllers/article.py
+++ /dev/null
@@ -1,117 +0,0 @@
-from tests.base import BasePyaggTest
-from web.controllers import ArticleController
-from web.controllers import FeedController
-
-
-class ArticleControllerTest(BasePyaggTest):
- _contr_cls = ArticleController
-
- def test_article_rights(self):
- article = ArticleController(2).read()[0].dump()
- self.assertFalse(article['readed'])
- article['readed'] = True # article get read when retreived through get
- self._test_controller_rights(article, article['user_id'])
-
- def test_article_challange_method(self):
- self.assertEquals(0, len(list(ArticleController().challenge(
- [{'id': art.id} for art in ArticleController(3).read()]))))
- self.assertEquals(9, len(list(ArticleController(2).challenge(
- [{'id': art.id} for art in ArticleController(3).read()]))))
- self.assertEquals(9, len(list(ArticleController(2).challenge(
- [{'entry_id': art.id} for art in ArticleController(3).read()]
- ))))
-
- def test_article_get_unread(self):
- self.assertEquals({1: 3, 2: 3, 3: 3},
- ArticleController(2).count_by_feed(readed=False))
- self.assertEquals({4: 3, 5: 3, 6: 3},
- ArticleController(3).count_by_feed(readed=False))
-
- 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()
- feed_ctr.update({'id': feed1['id']},
- {'filters': [{"type": "simple match",
- "pattern": "no see pattern",
- "action on": "match",
- "action": "mark as read"}]})
- feed_ctr.update({'id': feed3['id']},
- {'filters': [{"type": "regex",
- "pattern": ".*(pattern1|pattern2).*",
- "action on": "no match",
- "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'],
- title="garbage no see pattern garbage",
- content="doesn't matter",
- link="doesn't matter either")
- art2 = ArticleController(2).create(
- entry_id="thisisnotatesteither",
- feed_id=feed1['id'],
- title="garbage see pattern garbage",
- content="doesn't matter2",
- link="doesn't matter either2")
-
- art3 = ArticleController(2).create(
- entry_id="thisisnotatest",
- user_id=2,
- feed_id=feed2['id'],
- title="garbage no see pattern garbage",
- content="doesn't matter",
- link="doesn't matter either")
- art4 = ArticleController(2).create(
- entry_id="thisisnotatesteither",
- user_id=2,
- feed_id=feed2['id'],
- title="garbage see pattern garbage",
- content="doesn't matter2",
- link="doesn't matter either2")
-
- art5 = ArticleController(2).create(
- entry_id="thisisnotatest",
- feed_id=feed3['id'],
- title="garbage pattern1 garbage",
- content="doesn't matter",
- link="doesn't matter either")
- art6 = ArticleController(2).create(
- entry_id="thisisnotatesteither",
- feed_id=feed3['id'],
- title="garbage pattern2 garbage",
- content="doesn't matter2",
- link="doesn't matter either2")
- art7 = ArticleController(2).create(
- entry_id="thisisnotatesteither",
- feed_id=feed3['id'],
- title="garbage no see pattern3 garbage",
- content="doesn't matter3",
- link="doesn't matter either3")
- art8 = ArticleController(2).create(
- entry_id="thisisnotatesteither",
- feed_id=feed3['id'],
- title="garbage pattern4 garbage",
- content="doesn't matter4",
- link="doesn't matter either4")
-
- self.assertTrue(art1.readed)
- self.assertFalse(art1.like)
- self.assertFalse(art2.readed)
- self.assertFalse(art2.like)
- self.assertFalse(art3.readed)
- self.assertFalse(art3.like)
- self.assertFalse(art4.readed)
- self.assertFalse(art4.like)
- self.assertFalse(art5.readed)
- self.assertFalse(art5.like)
- self.assertFalse(art6.readed)
- self.assertFalse(art6.like)
- self.assertTrue(art7.readed)
- self.assertTrue(art7.like)
- self.assertFalse(art8.readed)
- self.assertTrue(art8.like)
diff --git a/src/tests/controllers/feed.py b/src/tests/controllers/feed.py
deleted file mode 100644
index 7dd77295..00000000
--- a/src/tests/controllers/feed.py
+++ /dev/null
@@ -1,27 +0,0 @@
-from tests.base import BasePyaggTest
-from web.controllers import FeedController
-from web.controllers import ArticleController
-
-
-class FeedControllerTest(BasePyaggTest):
- _contr_cls = FeedController
-
- def test_feed_rights(self):
- feed = FeedController(2).read()[0].dump()
- self.assertTrue(3,
- ArticleController().read(feed_id=feed['id']).count())
- self._test_controller_rights(feed, feed['user_id'])
- # checking articles are deleted after the feed has been deleted
-
- def test_feed_article_deletion(self):
- feed_ctr = FeedController(2)
- feed = feed_ctr.read()[0].dump()
- feed_ctr.delete(feed['id'])
- self.assertFalse(0,
- ArticleController().read(feed_id=feed['id']).count())
-
- def test_feed_list_fetchable(self):
- self.assertEquals(3, len(FeedController(3).list_fetchable()))
- self.assertEquals(0, len(FeedController(3).list_fetchable()))
- self.assertEquals(3, len(FeedController().list_fetchable()))
- self.assertEquals(0, len(FeedController().list_fetchable()))
diff --git a/src/tests/fixtures.py b/src/tests/fixtures.py
deleted file mode 100644
index 16a9cb81..00000000
--- a/src/tests/fixtures.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from web.models import db_create, db_empty, User, Article, Feed
-
-
-def populate_db(db):
- role_admin, role_user = db_create(db)
- user1, user2 = [User(nickname=name, email="%s@test.te" % name,
- pwdhash=name, roles=[role_user], enabled=True)
- for name in ["user1", "user2"]]
- db.session.add(user1)
- db.session.add(user2)
- db.session.commit()
-
- for user in (user1, user2):
- for feed_name in ['feed1', 'feed2', 'feed3']:
- feed = Feed(link=feed_name, user_id=user.id,
- title="%r %r" % (user.nickname, feed_name))
- db.session.add(feed)
- db.session.commit()
- for article in ['article1', 'article2', 'article3']:
- entry = "%s %s %s" % (user.nickname, feed.title, article)
- article = Article(entry_id=entry, link=article,
- feed_id=feed.id, user_id=user.id,
- title=entry, content=article)
- db.session.add(article)
- db.session.commit()
-
- db.session.commit()
-
-
-def reset_db(db):
- db_empty(db)
bgstack15