• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

allura


Commit MetaInfo

Revisión6b404c226f19a34f8a782ebb3e0737bffbc7b1f6 (tree)
Tiempo2012-06-22 23:34:39
AutorCory Johns <johnsca@geek...>
CommiterCory Johns

Log Message

[#4345] Fixed / expanded tests, re-enabled text/html feed processing

Signed-off-by: Cory Johns <johnsca@geek.net>

Cambiar Resumen

Diferencia incremental

--- a/ForgeBlog/forgeblog/command/rssfeeds.py
+++ b/ForgeBlog/forgeblog/command/rssfeeds.py
@@ -175,15 +175,10 @@ class RssFeedsCommand(base.BlogCommand):
175175 if ct.type != 'text/html':
176176 content += '[plain]%s[/plain]' % ct.value
177177 else:
178- if False:
179- # FIXME: disabled until https://sourceforge.net/p/allura/tickets/4345
180- # because the bad formatting from [plain] is worse than bad formatting from unintentional markdown syntax
181- parser = MDHTMLParser()
182- parser.feed(ct.value)
183- parser.close() # must be before using the result_doc
184- markdown_content = html2text.html2text(parser.result_doc, baseurl=e.link)
185- else:
186- markdown_content = html2text.html2text(ct.value, baseurl=e.link)
178+ parser = MDHTMLParser()
179+ parser.feed(ct.value)
180+ parser.close() # must be before using the result_doc
181+ markdown_content = html2text.html2text(parser.result_doc, baseurl=e.link)
187182
188183 content += markdown_content
189184 else:
--- a/ForgeBlog/forgeblog/tests/test_commands.py
+++ b/ForgeBlog/forgeblog/tests/test_commands.py
@@ -1,9 +1,12 @@
1+from datetime import datetime, timedelta
12 import pylons
23 pylons.c = pylons.tmpl_context
34 pylons.g = pylons.app_globals
45 from pylons import c, g
56 from nose.tools import assert_equal
67
8+from html2text import html2text
9+
710 from ming.orm.ormsession import ThreadLocalORMSession
811
912 from alluratest.controller import setup_basic_test, setup_global_objects
@@ -13,13 +16,60 @@ from allura.lib import helpers as h
1316 from forgeblog import model as BM
1417 from forgeblog.command import rssfeeds
1518
19+import mock
20+
21+
1622 test_config = 'test.ini#main'
1723
1824 def setUp():
1925 setup_basic_test()
2026 setup_global_objects()
2127
22-def test_pull_rss_feeds():
28+def _mock_feed(*entries):
29+ class attrdict(dict):
30+ def __getattr__(self, name):
31+ return self[name]
32+
33+ feed = mock.Mock()
34+ feed.bozo = False
35+ feed.entries = []
36+ for e in entries:
37+ _mock_feed.i += 1
38+ entry = attrdict(
39+ content_type='text/plain',
40+ title='Default Title %d' % _mock_feed.i,
41+ subtitle='',
42+ summary='',
43+ link='http://example.com/',
44+ updated=datetime.now()+timedelta(days=_mock_feed.i - 100))
45+ entry.update(e)
46+ entry['updated_parsed'] = entry['updated'].timetuple()
47+ if 'content' in entry:
48+ entry['content'] = [attrdict(type=entry['content_type'], value=entry['content'])]
49+ feed.entries.append(entry)
50+
51+ return feed
52+_mock_feed.i = 0
53+
54+@mock.patch.object(rssfeeds.feedparser, 'parse')
55+def test_pull_rss_feeds(parsefeed):
56+ parsefeed.return_value = _mock_feed(
57+ dict(title='Test', subtitle='test', summary='This is a test'),
58+ dict(content_type='text/plain', content='Test feed'),
59+ dict(content_type='text/html', content=
60+ "<p>1. foo</p>\n"
61+ "\n"
62+ "<p>\n"
63+ "#foo bar <a href='baz'>baz</a>\n"
64+ "foo bar\n"
65+ "</p>\n"
66+ "\n"
67+ "<p>#foo bar <a href='baz'>\n"
68+ "baz\n"
69+ "</a></p>\n"
70+ ),
71+ )
72+
2373 base_app = M.AppConfig.query.find().all()[0]
2474 tmp_app = M.AppConfig(tool_name=u'Blog', discussion_id=base_app.discussion_id,
2575 project_id=base_app.project_id,
@@ -27,14 +77,31 @@ def test_pull_rss_feeds():
2777 u'project_name': base_app.project.name,
2878 u'mount_point': u'blog',
2979 u'mount_label': u'Blog'})
30- new_external_feeds = ['http://wordpress.org/news/feed/']
80+ new_external_feeds = ['http://example.com/news/feed/']
3181 BM.Globals(app_config_id=tmp_app._id, external_feeds=new_external_feeds)
3282 ThreadLocalORMSession.flush_all()
3383
3484 cmd = rssfeeds.RssFeedsCommand('pull-rss-feeds')
3585 cmd.run([test_config, '-a', tmp_app._id])
3686 cmd.command()
37- assert len(BM.BlogPost.query.find({'app_config_id': tmp_app._id}).all()) > 0
87+ parsefeed.assert_called_with('http://example.com/news/feed/')
88+ posts = BM.BlogPost.query.find({'app_config_id': tmp_app._id}).sort('timestamp', 1)
89+ assert_equal(posts.count(), 3)
90+ posts = posts.all()
91+ assert_equal(posts[0].title, 'Test')
92+ assert_equal(posts[0].text, '[plain]This is a test[/plain] [link](http://example.com/)')
93+ assert_equal(posts[1].title, 'Default Title 2')
94+ assert_equal(posts[1].text, '[plain]Test feed[/plain] [link](http://example.com/)')
95+ assert_equal(posts[2].title, 'Default Title 3')
96+ assert_equal(posts[2].text,
97+ "[plain]1. foo[/plain]\n"
98+ "\n"
99+ "[plain]#foo bar [/plain][[plain]baz[/plain]](baz) "
100+ "[plain]foo bar[/plain] \n"
101+ "\n"
102+ "[plain]#foo bar [/plain][ [plain]baz[/plain] ](baz)\n "
103+ "[link](http://example.com/)"
104+ )
38105
39106 def test_plaintext_parser():
40107 parser = rssfeeds.MDHTMLParser()
@@ -89,7 +156,7 @@ def test_plaintext_parser_wrapped():
89156 )
90157
91158 def test_plaintext_preprocessor():
92- html = g.markdown.convert(
159+ text = html2text(
93160 "[plain]1. foo[/plain]\n"
94161 "\n"
95162 "[plain]#foo bar [/plain]<a href='baz'>[plain]baz[/plain]</a>\n"
@@ -99,22 +166,15 @@ def test_plaintext_preprocessor():
99166 "[plain]baz[/plain]\n"
100167 "</a>\n"
101168 )
169+ html = g.markdown.convert(text)
102170 assert_equal(html,
103- '<div class="markdown_content">'
104- '1. foo\n'
105- '\n'
106- '<p>'
107- '#foo bar <a href="../baz">baz</a><br />'
108- 'foo bar'
109- '</p><p>'
110- '#foo bar <a href="../baz"><br />'
111- 'baz<br />'
112- '</a>'
113- '</p></div>'
171+ '<div class="markdown_content"><p>1. foo '
172+ '#foo bar <a href="../baz">baz</a> foo bar '
173+ '#foo bar <a href="../baz"> baz </a></p></div>'
114174 )
115175
116176 def test_plaintext_preprocessor_wrapped():
117- html = g.markdown.convert(
177+ text = html2text(
118178 "<p>[plain]1. foo[/plain]</p>\n"
119179 "\n"
120180 "<p>\n"
@@ -126,16 +186,10 @@ def test_plaintext_preprocessor_wrapped():
126186 "[plain]baz[/plain]\n"
127187 "</a></p>\n"
128188 )
189+ html = g.markdown.convert(text)
129190 assert_equal(html,
130- '<div class="markdown_content">'
131- '<p>1. foo</p>\n'
191+ '<div class="markdown_content">1. foo\n'
132192 '\n'
133- '<p>\n'
134- '#foo bar <a href="../baz">baz</a>\n'
135- 'foo bar\n'
136- '</p>\n'
137- '<p>#foo bar <a href="../baz">\n'
138- 'baz\n'
139- '</a></p>\n'
140- '</div>'
193+ '<p>#foo bar <a href="../baz">baz</a> foo bar </p>\n'
194+ '<p>#foo bar <a href="../baz"> baz </a></p></div>'
141195 )