summaryrefslogtreecommitdiffstats
path: root/askbot/tests/utils_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'askbot/tests/utils_tests.py')
-rw-r--r--askbot/tests/utils_tests.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/askbot/tests/utils_tests.py b/askbot/tests/utils_tests.py
index 7f252b69..c8526ad1 100644
--- a/askbot/tests/utils_tests.py
+++ b/askbot/tests/utils_tests.py
@@ -1,5 +1,8 @@
from django.test import TestCase
+from askbot.tests.utils import with_settings
from askbot.utils.url_utils import urls_equal
+from askbot.utils.html import absolutize_urls
+from askbot.conf import settings as askbot_settings
class UrlUtilsTests(TestCase):
@@ -15,3 +18,40 @@ class UrlUtilsTests(TestCase):
self.assertTrue(e('http://cnn.com/path', 'http://cnn.com/path/', True))
self.assertFalse(e('http://cnn.com/path', 'http://cnn.com/path/'))
+
+class HTMLUtilsTests(TestCase):
+ """tests for :mod:`askbot.utils.html` module"""
+
+ @with_settings(APP_URL='http://example.com')
+ def test_absolutize_urls(self):
+ text = """<img class="junk" src="/some.gif"> <img class="junk" src="/cat.gif"> <IMG SRC='/some.png'>"""
+ #jinja register.filter decorator works in a weird way
+ self.assertEqual(
+ absolutize_urls(text),
+ '<img class="junk" src="http://example.com/some.gif" style="max-width:500px;"> <img class="junk" src="http://example.com/cat.gif" style="max-width:500px;"> <IMG SRC="http://example.com/some.png" style="max-width:500px;">'
+ )
+
+ text = """<a class="junk" href="/something">link</a> <A HREF='/something'>link</A>"""
+ #jinja register.filter decorator works in a weird way
+ self.assertEqual(
+ absolutize_urls(text),
+ '<a class="junk" href="http://example.com/something">link</a> <A HREF="http://example.com/something">link</A>'
+ )
+
+ text = '<img src="/upfiles/13487900323638005.png" alt="" />'
+ self.assertEqual(
+ absolutize_urls(text),
+ '<img src="http://example.com/upfiles/13487900323638005.png" style="max-width:500px;" alt="" />'
+ )
+
+ text = 'ohaouhaosthoanstoahuaou<br /><img src="/upfiles/13487906221942257.png" alt="" /><img class="gravatar" title="Evgeny4" src="http://kp-dev.askbot.com/avatar/render_primary/5/32/" alt="Evgeny4 gravatar image" width="32" height="32" />'
+ self.assertEqual(
+ absolutize_urls(text),
+ 'ohaouhaosthoanstoahuaou<br /><img src="http://example.com/upfiles/13487906221942257.png" style="max-width:500px;" alt="" /><img class="gravatar" title="Evgeny4" src="http://kp-dev.askbot.com/avatar/render_primary/5/32/" alt="Evgeny4 gravatar image" width="32" height="32" />'
+ )
+
+ text = '<a href="/upfiles/13487909784287052.png"><img src="/upfiles/13487909942351405.png" 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'
+ self.assertEqual(
+ 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'
+ )