def testDifficultyOfFeedItems(self): feed = RSSFeedRule().feed1 download_from_feed(feed, zeeguu.db.session, 3) articles = feed.get_articles(limit=2) assert len(articles) == 2 assert articles[0].fk_difficulty
def setUp(self): super().setUp() self.spiegel = RSSFeedRule().feed1 download_from_feed(self.spiegel, self.db.session, 3) self.telegraaf = RSSFeedRule().feed2 download_from_feed(self.telegraaf, self.db.session, 3)
def setUp(self): super().setUp() self.feed1 = RSSFeedRule().feed1 self.feed2 = RSSFeedRule().feed2 RSSFeedRegistration.find_or_create(zeeguu.db.session, self.user, self.feed1) RSSFeedRegistration.find_or_create(zeeguu.db.session, self.user, self.feed2)
def test_recommended(self): self.feed1 = RSSFeedRule().feed1 self.feed2 = RSSFeedRule().feed2 download_from_feed(self.feed1, zeeguu.db.session, 2) download_from_feed(self.feed2, zeeguu.db.session, 3) RSSFeedRegistration.find_or_create(zeeguu.db.session, self.user, self.feed1) RSSFeedRegistration.find_or_create(zeeguu.db.session, self.user, self.feed2) feed_items = self.json_from_api_get(f"/user_articles/recommended/5") assert (len(feed_items) == 5)
def testDownloadWithTopic(self): feed = RSSFeedRule().feed1 topic = Topic("Spiegel") zeeguu.db.session.add(topic) zeeguu.db.session.commit() loc_topic = LocalizedTopic(topic, self.lan, "spiegelDE", "spiegel") zeeguu.db.session.add(loc_topic) zeeguu.db.session.commit() download_from_feed(feed, zeeguu.db.session, 3) article = feed.get_articles(limit=2)[0] assert (topic in article.topics)
def testDownloadWithWords(self): feed = RSSFeedRule().feed1 download_from_feed(feed, zeeguu.db.session, 3) article = feed.get_articles(limit=2)[0] # Try two words, as one might be filtered out word = strip_article_title_word(article.title.split()[0]) article_word = ArticleWord.find_by_word(word) if word in ['www', '' ] or word.isdigit() or len(word) < 3 or len(word) > 25: assert (article_word is None) else: assert (article in article_word.articles)
def test_start_following_feed(self): new_feed_id = RSSFeedRule().feed.id # When form_data = {"source_id": new_feed_id} self.api_post(f'/{START_FOLLOWING_FEED}', form_data) # Then followed_feed_ids = [ each['id'] for each in self.json_from_api_get(f"/{FOLLOWED_FEEDS}") ] assert (new_feed_id in followed_feed_ids)
class FeedTest(ModelTestMixIn, TestCase): def setUp(self): super().setUp() self.spiegel = RSSFeedRule().feed1 download_from_feed(self.spiegel, self.db.session, 3) self.telegraaf = RSSFeedRule().feed2 download_from_feed(self.telegraaf, self.db.session, 3) def test_feed_items(self): assert len(self.spiegel.get_articles()) == 3 assert len(self.spiegel.get_articles(limit=2)) == 2 assert len(self.telegraaf.get_articles()) == 3 def test_after_date_works(self): tomorrow = datetime.now() + timedelta(days=1) assert not self.spiegel.get_articles(after_date=tomorrow) def test_article_ordering(self): ordered_by_difficulty = self.spiegel.get_articles(easiest_first=True) assert ordered_by_difficulty[0].fk_difficulty <= ordered_by_difficulty[ 1].fk_difficulty ordered_by_time = self.spiegel.get_articles(most_recent_first=True) assert ordered_by_time[0].published_time >= ordered_by_time[ 1].published_time
def _create_model_object(self): title = " ".join(self.faker.text().split()[:4]) authors = self.faker.name() content = self.faker.text() summary = self.faker.text() published = datetime.now() - timedelta(minutes=randint(0, 7200)) rss_feed = RSSFeedRule().feed language = LanguageRule().random url = UrlRule().url article = Article(url, title, authors, content, summary, published, rss_feed, language) if self._exists_in_db(article): return self._create_model_object() return article