def test_delete_main_cluster_handling(self): suffix = 'suffix' clu = ClusterController().get(id=10) acontr = ArticleController(clu.user_id) fcontr = FeedController(clu.user_id) old_title = clu.main_title old_feed_title, old_art_id = clu.main_feed_title, clu.main_article_id for art_to_del in acontr.read(link=clu.main_article.link, id__ne=clu.main_article.id): acontr.delete(art_to_del.id) other_feed = fcontr.read(id__ne=clu.main_article.feed_id).first() update_on_all_objs(articles=[clu.main_article], feeds=[other_feed], cluster_enabled=True) acontr.create( feed_id=other_feed.id, entry_id=clu.main_article.entry_id + suffix, link=clu.main_article.link, title=clu.main_article.title + suffix, content=clu.main_article.content + suffix, date=clu.main_article.date + timedelta(1), retrieved_date=clu.main_article.retrieved_date + timedelta(1), ) ClusterController(clu.user_id).clusterize_pending_articles() clu = ClusterController().get(id=10) self.assertEqual(2, len(clu.articles)) fcontr.delete(clu.main_article.feed_id) new_cluster = ClusterController(clu.user_id).get(id=clu.id) self.assertEqual(1, len(new_cluster.articles)) self.assertNotEqual(old_title, new_cluster.main_title) self.assertNotEqual(old_feed_title, new_cluster.main_feed_title) self.assertNotEqual(old_art_id, new_cluster.main_article_id)
def feed_cleaner(feed_id): logger.warning("Feed cleaner - start => %s", feed_id) WORKER_BATCH.labels(worker_type='delete').observe(1) fctrl = FeedController() result = fctrl.update({'id': feed_id, 'status': FeedStatus.to_delete}, {'status': FeedStatus.deleting}) if not result: logger.error('feed %r seems locked, not doing anything', feed_id) return try: logger.warning("Deleting feed %r", feed_id) fctrl.delete(feed_id) except Exception: logger.exception('something went wrong when deleting feeds %r', feed_id) fctrl.update({'id': feed_id}, {'status': FeedStatus.to_delete}) raise finally: REDIS_CONN.delete(JARR_FEED_DEL_KEY)
def test_delete(self): feed_ctrl = FeedController() for feed in feed_ctrl.read(): feed_ctrl.delete(feed.id) self.assertEqual(0, ClusterController(2).read().count()) self.assertEqual(0, ArticleController(2).read().count())
class OPMLTest(JarrFlaskCommon): def setUp(self): super().setUp() login = '******' self.user = UserController().get(login=login) self.user2 = UserController().get(login='******') self.fctrl = FeedController(self.user.id) self.cctrl = CategoryController(self.user.id) self.uctrl = UserController() def test_opml_dump_and_restore(self): # downloading OPML export file resp = self.jarr_client('get', '/opml', user=self.user.login) self.assertStatusCode(200, resp) opml_dump = resp.data.decode() self.assertTrue( opml_dump.startswith('<?xml version="1.0" encoding="utf-8"')) self.assertTrue(opml_dump.endswith('</opml>')) # cleaning db actrl = ArticleController(self.user.id) for item in actrl.read(): actrl.delete(item.id) self.assertEqual(0, ClusterController(self.user.id).read().count()) self.assertEqual(0, ArticleController(self.user.id).read().count()) no_category_feed = [] existing_feeds = {} for feed in self.fctrl.read(): if feed.category: if feed.category.name in existing_feeds: existing_feeds[feed.category.name].append(feed.title) else: existing_feeds[feed.category.name] = [feed.title] else: no_category_feed.append(feed.title) self.fctrl.delete(feed.id) for category in self.cctrl.read(): self.cctrl.delete(category.id) # re-importing OPML import_resp = self.jarr_client( 'post', 'opml', to_json=False, data={'opml_file': (BytesIO(resp.data), 'opml.xml')}, headers=None, user=self.user.login) self.assertStatusCode(201, import_resp) self.assertEqual(0, import_resp.json['existing']) self.assertEqual(0, import_resp.json['failed']) self._check_opml_imported(existing_feeds, no_category_feed) import_resp = self.jarr_client( 'post', 'opml', to_json=False, data={'opml_file': (BytesIO(resp.data), 'opml.xml')}, headers=None, user=self.user.login) self.assertStatusCode(200, import_resp) self.assertEqual(0, import_resp.json['created']) self.assertEqual(0, import_resp.json['failed']) def _check_opml_imported(self, existing_feeds, no_category_feed): self.assertEqual( sum(map(len, existing_feeds.values())) + len(no_category_feed), self.fctrl.read().count()) self.assertEqual(len(existing_feeds), self.cctrl.read().count()) for feed in self.fctrl.read(): if feed.category: self.assertIn(feed.category.name, existing_feeds) self.assertIn(feed.title, existing_feeds[feed.category.name]) else: self.assertIn(feed.title, no_category_feed)