summaryrefslogtreecommitdiffstats
path: root/askbot/tests
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-09-20 20:04:16 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2013-09-20 20:04:16 -0300
commite31a96bf760625649ec631e6e3194c26214a729a (patch)
treeb67af3c556a799f37b7a590b35da5579702959cd /askbot/tests
parentdce36af3a2003715e1f72bf482b9f31ea97b60c1 (diff)
parent99d007dbd063227ad1c21d475c2cbd34ad37a8fe (diff)
downloadaskbot-e31a96bf760625649ec631e6e3194c26214a729a.tar.gz
askbot-e31a96bf760625649ec631e6e3194c26214a729a.tar.bz2
askbot-e31a96bf760625649ec631e6e3194c26214a729a.zip
Merge branch 'user-questions-pagination' into temp
Diffstat (limited to 'askbot/tests')
-rw-r--r--askbot/tests/__init__.py1
-rw-r--r--askbot/tests/email_parsing_tests.py28
-rw-r--r--askbot/tests/jive_tests.py280
-rw-r--r--askbot/tests/utils_tests.py7
4 files changed, 312 insertions, 4 deletions
diff --git a/askbot/tests/__init__.py b/askbot/tests/__init__.py
index 5facdb7d..f913da21 100644
--- a/askbot/tests/__init__.py
+++ b/askbot/tests/__init__.py
@@ -24,4 +24,5 @@ from askbot.tests.user_views_tests import *
from askbot.tests.utils_tests import *
from askbot.tests.view_context_tests import *
from askbot.tests.api_v1_tests import *
+from askbot.tests.jive_tests import *
from askbot.tests.signal_handler_tests import *
diff --git a/askbot/tests/email_parsing_tests.py b/askbot/tests/email_parsing_tests.py
index dc1e82f2..b87bbebe 100644
--- a/askbot/tests/email_parsing_tests.py
+++ b/askbot/tests/email_parsing_tests.py
@@ -5,6 +5,7 @@ from django.template.loader import get_template
from askbot import mail
from askbot import models
from askbot.tests import utils
+from askbot.utils.html import get_text_from_html
class EmailParsingTests(utils.AskbotTestCase):
@@ -16,10 +17,6 @@ class EmailParsingTests(utils.AskbotTestCase):
self.rendered_template = template.render(Context(self.context))
self.expected_output = 'Welcome to askbot.com!\n\nImportant: Please reply to this message, without editing it. We need this to determine your email signature and that the email address is valid and was typed correctly.\n\nUntil we receive the response from you, you will not be able ask or answer questions on askbot.com by email.\n\nSincerely,askbot.com Administrator\n\nDwFwndQty'
- def test_clean_email_body(self):
- cleaned_body = mail.clean_html_email(self.rendered_template)
- self.assertEqual(self.expected_output, cleaned_body)
-
def test_gmail_rich_text_response_stripped(self):
text = u'\n\nthis is my reply!\n\nOn Wed, Oct 31, 2012 at 1:45 AM, <kp@kp-dev.askbot.com> wrote:\n\n> **\n> '
self.assertEqual(mail.extract_reply(text), 'this is my reply!')
@@ -65,3 +62,26 @@ Subject: "One more test question from email."
"""
self.assertEqual(mail.extract_reply(text), "some real text")
+
+ def test_blackberry(self):
+
+ text = """Lorem ipsum lorem ipsum
+blah blah blah
+
+some more text here
+
+Joe
+
+________________________________________
+From: forum@ask.askbot.com
+Sent: Thursday, August 15, 2013 1:58:21 AM
+To: Mister Joe
+Subject: Our forum: "some text in the subject line"
+"""
+ expected = """Lorem ipsum lorem ipsum
+blah blah blah
+
+some more text here
+
+Joe"""
+ self.assertEqual(mail.extract_reply(text), expected)
diff --git a/askbot/tests/jive_tests.py b/askbot/tests/jive_tests.py
new file mode 100644
index 00000000..f99be71e
--- /dev/null
+++ b/askbot/tests/jive_tests.py
@@ -0,0 +1,280 @@
+import unittest
+from askbot.utils.jive import JiveConverter
+from askbot.utils.jive import internal_link_re as link_re
+
+#class MockPost(object):
+# def __init__(self):
+# self.text = ''
+# def get_absolute_url(self):
+# return '/url'
+
+class JiveTests(unittest.TestCase):
+
+ def setUp(self):
+ self.converter = JiveConverter()
+
+ def convert(self, text):
+ return self.converter.convert(text)
+
+ def test_headings(self):
+ text = """
+h1. Heading1
+blah blah
+h2. Heading 2
+blah blah
+h3. Heading 3
+blah blah
+"""
+ expected = """<h1>Heading1</h1>
+<p>blah blah</p>
+<h2>Heading 2</h2>
+<p>blah blah</p>
+<h3>Heading 3</h3>
+<p>blah blah</p>"""
+ output = self.convert(text)
+ self.assertEqual(output, expected)
+
+ def test_horizontal_rules(self):
+ text = """
+-----
+some text
+"""
+ expected = '<hr/>\n<p>some text</p>'
+ self.assertEqual(self.convert(text), expected)
+
+ def test_list1(self):
+ text = """
+* one
+* two
+* three
+"""
+ expected = """<ul>
+<li>one</li>
+<li>two</li>
+<li>three</li>
+</ul>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_list2(self):
+ text = """
+# one
+# two
+# three
+"""
+ expected = """<ol>
+<li>one</li>
+<li>two</li>
+<li>three</li>
+</ol>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_list3(self):
+ text = """
+* one
+** two
+* three
+"""
+ expected = """<ul>
+<li>one</li>
+<li>
+<ul>
+<li>two</li>
+</ul>
+</li>
+<li>three</li>
+</ul>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bq1(self):
+ text = """
+bq. two plus two equals four
+"""
+ expected = """<blockquote><p>two plus two equals four</p></blockquote>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bq2(self):
+ text = """{quote}
+two plus two equals four
+{quote}
+"""
+ expected = """<blockquote><p>two plus two equals four</p></blockquote>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bq3(self):
+ text = """[quote=alex]
+two plus two equals four
+{quote}
+"""
+ expected = """<blockquote><span class="quote-header">alex wrote:</span><br/>
+<p>two plus two equals four</p></blockquote>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bq4(self):
+ text = """[quote=alex]
+two plus two equals four
+
+two plus two equals four
+{quote}
+"""
+ expected = """<blockquote><span class="quote-header">alex wrote:</span><br/>
+<p>two plus two equals four</p>
+<p>two plus two equals four</p></blockquote>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bq5(self):
+ text = """> {quote:title=alex wrote:}{quote}
+> two plus two equals four
+>
+> two plus two equals four
+"""
+ expected = """<blockquote><span class="quote-header">alex wrote:</span><br/>
+<p>two plus two equals four</p>
+<p>two plus two equals four</p></blockquote>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_code0(self):
+ text = """something {code}#comment _haha_ http://example.com {code}"""
+ expected = """<p>something</p>
+<pre><code>#comment _haha_ http://example.com </code></pre>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_code1(self):
+ text = """something {code:html}#comment _haha_ http://example.com {code}"""
+ expected = """<p>something</p>
+<pre><code>#comment _haha_ http://example.com </code></pre>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_links1(self):
+ text = """[url]http://example.com/2[/url] blah
+http://example.com/1 blah
+[link text3|http://example.com/3|tooltip text3] blah2
+[link text4|http://example.com/4|tooltip text4]
+!http://example.com/img.png!
+[email@example.com]
+[/some/file/]
+"""
+ expected = """<p><a href="http://example.com/2">http://example.com/2</a> blah<br/>
+<a href="http://example.com/1">http://example.com/1</a> blah<br/>
+<a href="http://example.com/3" title="tooltip text3">link text3</a> blah2 <br/>
+<a href="http://example.com/4" title="tooltip text4">link text4</a><br/>
+<img src="http://example.com/img.png"/><br/>
+<a href="mailto:email@example.com">email@example.com</a><br/>
+<a href="/some/file/">/some/file/</a></p>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_bold(self):
+ text = "*some text*"
+ self.assertEqual(
+ self.convert(text),
+ '<p><strong>some text</strong></p>'
+ )
+
+ def test_italics(self):
+ text = "+some text+"
+ self.assertEqual(
+ self.convert(text),
+ '<p><em>some text</em></p>'
+ )
+
+ def test_underline(self):
+ text = "_some text_"
+ self.assertEqual(
+ self.convert(text),
+ '<p><span class="underline">some text</span></p>'
+ )
+
+ def test_super(self):
+ text = "e = mc^2^"
+ self.assertEqual(
+ self.convert(text),
+ '<p>e = mc<sup>2</sup></p>'
+ )
+
+ def test_sub(self):
+ text = "e~1~"
+ self.assertEqual(
+ self.convert(text),
+ '<p>e<sub>1</sub></p>'
+ )
+
+ def test_strike(self):
+ text = "--A--"
+ self.assertEqual(
+ self.convert(text),
+ '<p><strike>A</strike></p>'
+ )
+
+ def test_leading_spaces(self):
+ """test lazy copy-pasted code"""
+ text = """
+function() {
+ alert('hi');
+}
+"""
+ expected = """<p>function() {<br/>
+&nbsp;&nbsp;&nbsp;&nbsp;alert('hi');<br/>
+}</p>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_fancy(self):
+ text = """
+h1. Once [upon|http://example.com] a *time*
+There was a queen who said:
+{quote}
+I _find_ *this* interesting
+
+{code}e = mc^2;{code}
+
+As you said:
+
+# one
+# two
+# *three*
+# [four|http://example.com/four|item four]
+# *five*, --six--, +seven+, _eight_
+{quote}
+h2. Another time
+Nothing happened.
+"""
+ expected = """<h1>Once <a href="http://example.com">upon</a> a <strong>time</strong></h1>
+<p>There was a queen who said:</p>
+<blockquote><p>I <span class="underline">find</span> <strong>this</strong> interesting</p>
+<pre><code>e = mc^2;</code></pre>
+<p>As you said:</p>
+<ol>
+<li>one</li>
+<li>two</li>
+<li><strong>three</strong></li>
+<li><a href="http://example.com/four" title="item four">four</a></li>
+<li><strong>five</strong>, <strike>six</strike>, <em>seven</em>, <span class="underline">eight</span></li>
+</ol></blockquote>
+<h2>Another time</h2>
+<p>Nothing happened.</p>"""
+ self.assertEqual(self.convert(text), expected)
+
+ def test_internal_link_re(self):
+ self.assertTrue(link_re.search('soasao /message.jspa?messageID=8477 a'))
+ self.assertTrue(link_re.search('/thread.jspa?messageID=10175&amp;#10175'))
+ self.assertTrue(link_re.search('/thread.jspa?messageID=10662#10662'))
+ self.assertTrue(link_re.search('/thread.jspa?messageID=11058'))
+ self.assertTrue(link_re.search('/thread.jspa?threadID=1888&amp;tstart=210'))
+ self.assertTrue(link_re.search('/thread.jspa?threadID=3087&amp;tstart=-258'))
+
+# def test_fix_internal_links1(self):
+# from askbot.management.commands.askbot_import_jive import fix_internal_links_in_post
+# post = MockPost()
+# post.text = """/message.jspa?messageID=8477 sometext
+#sometext /thread.jspa?messageID=10175&amp;#10175 sometext
+#[sometext|/thread.jspa?messageID=10662#10662] [/thread.jspa?messageID=11058]
+#[sometext|/thread.jspa?threadID=1888&amp;tstart=210|title]
+#/thread.jspa?threadID=3087&amp;tstart=-258"""
+# expected = """<a href="/url">/url</a> sometext<br/>
+#sometext <a href="/url">/url</a> sometext<br/>
+#<a href="/url">sometext</a> <a href="/url">/url</a><br/>
+#<a href="/url" title="title">sometext</a><br/>
+#<a href="/url">/url</a>"""
+# fix_internal_links_in_post(post)
+# self.assertEqual(post.text, expected)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/askbot/tests/utils_tests.py b/askbot/tests/utils_tests.py
index ed845f48..a04edd82 100644
--- a/askbot/tests/utils_tests.py
+++ b/askbot/tests/utils_tests.py
@@ -3,6 +3,7 @@ from askbot.tests.utils import with_settings
from askbot.utils.url_utils import urls_equal
from askbot.utils.html import absolutize_urls
from askbot.utils.html import replace_links_with_text
+from askbot.utils.html import get_text_from_html
from askbot.conf import settings as askbot_settings
class UrlUtilsTests(TestCase):
@@ -103,3 +104,9 @@ class HTMLUtilsTests(TestCase):
absolutize_urls(text),
'<a href="http://example.com/upfiles/13487909784287052.png"><img src="http://example.com/upfiles/13487909942351405.png" style="max-width:500px;" alt="" /></a><img src="http://i2.cdn.turner.com/cnn/dam/assets/120927033530-ryder-cup-captains-wall-4-tease.jpg" alt="" width="160" height="90" border="0" />and some text<br />aouaosutoaehut'
)
+
+ def test_get_text_from_html(self):
+ self.assertEqual(
+ get_text_from_html('ataoesa uau <a>link</a>aueaotuosu ao <a href="http://cnn.com">CNN!</a>\nnaouaouuau<img> <img src="http://cnn.com/1.png"/> <img src="http://cnn.com/2.png" alt="sometext">'),
+ u'ataoesa uau linkaueaotuosu ao http://cnn.com (CNN!)\n\nnaouaouuau http://cnn.com/1.png http://cnn.com/2.png (sometext)'
+ )