def test_pull_rss_feeds(parsefeed): html_content = ( "<p>1. foo</p>\n" "\n" "<p>\n" "#foo bar <a href='baz'>baz</a>\n" "foo bar\n" "</p>\n" "\n" "<p>#foo bar <a href='http://other.com/baz'>\n" "baz\n" "</a></p>\n" ) rendered_html_content = "\n".join([ r"1\. foo", "", r"\#foo bar [baz](http://example.com/baz) foo bar", "", r"\#foo bar [ baz ](http://other.com/baz)", "", " [link](http://example.com/)", ]) parsefeed.return_value = _mock_feed( dict(title='Test', subtitle='test', summary='This is a test'), dict(content_type='text/plain', content='Test feed'), dict(content_type='text/html', content=html_content), dict(summary_detail=dict(type='text/html', value=html_content)), ) base_app = M.AppConfig.query.find().all()[0] tmp_app = M.AppConfig( tool_name='Blog', discussion_id=base_app.discussion_id, project_id=base_app.project_id, options={'ordinal': 0, 'show_right_bar': True, 'project_name': base_app.project.name, 'mount_point': 'blog', 'mount_label': 'Blog'}) new_external_feeds = ['http://example.com/news/feed/'] BM.Globals(app_config_id=tmp_app._id, external_feeds=new_external_feeds) ThreadLocalORMSession.flush_all() from forgeblog.command import rssfeeds # importing this sets html2text.BODY_WIDTH to a value this test expects cmd = rssfeeds.RssFeedsCommand('pull-rss-feeds') cmd.run([test_config, '-a', tmp_app._id]) cmd.command() parsefeed.assert_called_with('http://example.com/news/feed/') posts = BM.BlogPost.query.find( {'app_config_id': tmp_app._id}).sort('timestamp', 1) assert_equal(posts.count(), 4) posts = posts.all() assert_equal(posts[0].title, 'Test') assert_equal(posts[0].text, 'This is a test [link](http://example.com/)') assert_equal(posts[1].title, 'Default Title 2') assert_equal(posts[1].text, 'Test feed [link](http://example.com/)') assert_equal(posts[2].title, 'Default Title 3') assert_equal(posts[2].text, rendered_html_content) assert_equal(posts[3].title, 'Default Title 4') assert_equal(posts[3].text, rendered_html_content)
def external_feeds_list(self, new_external_feeds): globals = BM.Globals.query.get(app_config_id=self.config._id) if globals is not None: globals.external_feeds = new_external_feeds elif len(new_external_feeds) > 0: globals = BM.Globals(app_config_id=self.config._id, external_feeds=new_external_feeds) if globals is not None: session(globals).flush()
def test_pull_rss_feeds(parsefeed): parsefeed.return_value = _mock_feed( dict(title='Test', subtitle='test', summary='This is a test'), dict(content_type='text/plain', content='Test feed'), dict(content_type='text/html', content="<p>1. foo</p>\n" "\n" "<p>\n" "#foo bar <a href='baz'>baz</a>\n" "foo bar\n" "</p>\n" "\n" "<p>#foo bar <a href='baz'>\n" "baz\n" "</a></p>\n"), ) base_app = M.AppConfig.query.find().all()[0] tmp_app = M.AppConfig(tool_name=u'Blog', discussion_id=base_app.discussion_id, project_id=base_app.project_id, options={ u'ordinal': 0, u'show_right_bar': True, u'project_name': base_app.project.name, u'mount_point': u'blog', u'mount_label': u'Blog' }) new_external_feeds = ['http://example.com/news/feed/'] BM.Globals(app_config_id=tmp_app._id, external_feeds=new_external_feeds) ThreadLocalORMSession.flush_all() cmd = rssfeeds.RssFeedsCommand('pull-rss-feeds') cmd.run([test_config, '-a', tmp_app._id]) cmd.command() parsefeed.assert_called_with('http://example.com/news/feed/') posts = BM.BlogPost.query.find({ 'app_config_id': tmp_app._id }).sort('timestamp', 1) assert_equal(posts.count(), 3) posts = posts.all() assert_equal(posts[0].title, 'Test') assert_equal(posts[0].text, '[plain]This is a test[/plain] [link](http://example.com/)') assert_equal(posts[1].title, 'Default Title 2') assert_equal(posts[1].text, '[plain]Test feed[/plain] [link](http://example.com/)') assert_equal(posts[2].title, 'Default Title 3') assert_equal( posts[2].text, "[plain]1. foo[/plain]\n" "\n" "[plain]#foo bar [/plain][[plain]baz[/plain]](baz) " "[plain]foo bar[/plain] \n" "\n" "[plain]#foo bar [/plain][ [plain]baz[/plain] ](baz)\n " "[link](http://example.com/)")