You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/11/20 15:17:28 UTC
[3/7] allura git commit: [#4771] ticket:672 Add tests for edge cases
[#4771] ticket:672 Add tests for edge cases
1. Included page contains <pre> and no headers
2. Included page contains <pre> and headers, e.g. included page includes a file
from a repo itself
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/9984568e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/9984568e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/9984568e
Branch: refs/heads/ib/4771a
Commit: 9984568e65d299d96174ce7ba037a6e314d539b4
Parents: 950c9c1
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 23 10:51:04 2014 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Nov 20 10:51:03 2014 +0000
----------------------------------------------------------------------
Allura/allura/tests/test_globals.py | 67 ++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/9984568e/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index e5f877c..9bec12b 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -24,6 +24,7 @@ import allura
import unittest
import hashlib
from mock import patch, Mock
+from BeautifulSoup import BeautifulSoup
from bson import ObjectId
from nose.tools import with_setup, assert_equal, assert_in, assert_not_in
@@ -532,6 +533,72 @@ More text
u'another heading for included page</a></li>', result)
+@td.with_wiki
+def test_toc_generation_for_included_page_pre_without_headers():
+ '''Check that formatting inside <pre> tags is preserved
+ when TOC is present and included page does not contain headers.'''
+ parent_text = u'[TOC]\n\n# heading\n\n[[include ref=included]]'
+ included_text = u'''
+<pre>one
+two
+three</pre>
+
+Another pre:
+
+<pre>one two three
+four five six</pre>
+'''
+ p_nbhd = M.Neighborhood.query.get(name='Projects')
+ p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+ wiki = p_test.app_instance('wiki')
+ with h.push_context(p_test._id, app_config_id=wiki.config._id):
+ p = WM.Page.upsert(title='included')
+ p.text = included_text
+ p.commit()
+ ThreadLocalORMSession.flush_all()
+
+ result = g.markdown.convert(parent_text)
+ assert_in(u'<li><a href="#heading">heading</a></li>', result)
+ pre1, pre2 = BeautifulSoup(result).findAll('pre')
+ assert_equal(pre1.getText(), 'one\ntwo\nthree')
+ assert_equal(pre2.getText(), 'one two three\nfour five six')
+
+
+@td.with_wiki
+def test_toc_generation_for_included_page_pre_with_headers():
+ '''Check that formatting inside <pre> tags is preserved
+ when TOC is present and included page contains headers.'''
+ parent_text = u'[TOC]\n\n# heading\n\n[[include ref=included]]'
+ included_text = u'''
+#heading for included page
+
+<pre>one
+two
+three</pre>
+
+Another pre:
+
+<pre>one two three
+four five six</pre>
+'''
+ p_nbhd = M.Neighborhood.query.get(name='Projects')
+ p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+ wiki = p_test.app_instance('wiki')
+ with h.push_context(p_test._id, app_config_id=wiki.config._id):
+ p = WM.Page.upsert(title='included')
+ p.text = included_text
+ p.commit()
+ ThreadLocalORMSession.flush_all()
+
+ result = g.markdown.convert(parent_text)
+ assert_in(u'<li><a href="#heading">heading</a></li>', result)
+ assert_in(u'<li><a href="#heading-for-included-page">'
+ u'heading for included page</a></li>', result)
+ pre1, pre2 = BeautifulSoup(result).findAll('pre')
+ assert_equal(pre1.getText(), 'one\ntwo\nthree')
+ assert_equal(pre2.getText(), 'one two three\nfour five six')
+
+
def test_macro_nbhd_feeds():
with h.push_context('--init--', 'wiki', neighborhood='Projects'):
r = g.markdown_wiki.convert('[[neighborhood_feeds tool_name=wiki]]')