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 break_discussion(): """Emulate buggy 'ticket move' behavior""" project = M.Project.query.get(shortname='test') tracker = M.AppConfig.query.find({'options.mount_point': 'bugs'}).first() discussion = M.Discussion(name='fake discussion') app_config = M.AppConfig() app_config.tool_name = 'Tickets' app_config.project_id = project._id app_config.options = {'mount_point': 'fake'} session(app_config).flush(app_config) discussion.app_config_id = app_config._id session(discussion).flush(discussion) t = TM.Ticket.new() t.summary = 'ticket 1' # move disscusion somewhere t.discussion_thread.discussion.app_config_id = discussion.app_config_id session(t).flush(t) t = TM.Ticket.new() t.summary = 'ticket 2' # moved ticket attached to wrong discussion t.discussion_thread.discussion_id = discussion._id t.discussion_thread.add_post(text='comment 1') t.discussion_thread.add_post(text='comment 2') session(t).flush(t)
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/)")
def installable_tools_for(project): tools = [] for name, App in six.iteritems(g.entry_points['tool']): cfg = M.AppConfig(project_id=project._id, tool_name=name) if App._installable(name, project.neighborhood, project.app_configs): tools.append(dict(name=name, app=App)) # prevent from saving temporary config to db session(cfg).expunge(cfg) tools.sort(key=lambda t: (t['app'].status_int(), t['app'].ordinal or 0)) return [t for t in tools if t['app'].status in project.allowed_tool_status]