diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-29 00:35:19 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2012-10-29 00:35:19 -0300 |
commit | c83d17e957ae1b725e9d2ea24e6eeba0e341409f (patch) | |
tree | 149810cf1941e77e1ab6abb0962eab0a44ff3dec /askbot/tests | |
parent | 6e4f4482853fd20f8f8301e96174da77c528e415 (diff) | |
download | askbot-c83d17e957ae1b725e9d2ea24e6eeba0e341409f.tar.gz askbot-c83d17e957ae1b725e9d2ea24e6eeba0e341409f.tar.bz2 askbot-c83d17e957ae1b725e9d2ea24e6eeba0e341409f.zip |
reimplemented the link insertion rep barrier
Diffstat (limited to 'askbot/tests')
-rw-r--r-- | askbot/tests/email_alert_tests.py | 6 | ||||
-rw-r--r-- | askbot/tests/utils_tests.py | 52 |
2 files changed, 55 insertions, 3 deletions
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py index f4ae052b..bdb361e5 100644 --- a/askbot/tests/email_alert_tests.py +++ b/askbot/tests/email_alert_tests.py @@ -1037,7 +1037,11 @@ class PostApprovalTests(utils.AskbotTestCase): class AbsolutizeUrlsInEmailsTests(utils.AskbotTestCase): - @with_settings(MIN_REP_TO_TRIGGER_EMAIL=1, APP_URL='http://example.com/') + @with_settings( + MIN_REP_TO_TRIGGER_EMAIL=1, + APP_URL='http://example.com/', + MIN_REP_TO_INSERT_LINK=1 + ) def test_urls_are_absolute(self): u1 = self.create_user('u1') max_email = models.EmailFeedSetting.MAX_EMAIL_SCHEDULE diff --git a/askbot/tests/utils_tests.py b/askbot/tests/utils_tests.py index c8526ad1..ed845f48 100644 --- a/askbot/tests/utils_tests.py +++ b/askbot/tests/utils_tests.py @@ -2,6 +2,7 @@ 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.utils.html import replace_links_with_text from askbot.conf import settings as askbot_settings class UrlUtilsTests(TestCase): @@ -17,11 +18,58 @@ 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 ReplaceLinksWithTextTests(TestCase): + """testing correctness of `askbot.utils.html.replace_links_with_text""" + + def test_local_link_not_replaced(self): + text = '<a href="/some-link">some link</a>' + self.assertEqual(replace_links_with_text(text), text) + + def test_link_without_url_replaced(self): + text = '<a>some link</a>' + self.assertEqual(replace_links_with_text(text), 'some link') + + def test_external_link_without_text_replaced(self): + text = '<a href="https://example.com/"></a>' + #in this case we delete the link + self.assertEqual(replace_links_with_text(text), '') + + def test_external_link_with_text_replaced(self): + text = '<a href="https://example.com/">some link</a>' + self.assertEqual( + replace_links_with_text(text), + 'https://example.com/ (some link)' + ) + + def test_local_image_not_replaced(self): + text = '<img src="/some-image.gif"/>' + self.assertEqual(replace_links_with_text(text), text) + + def test_local_url_with_hotlinked_image_replaced(self): + text = '<a href="/some-link"><img src="http://example.com/img.png" alt="picture""> some text</a>' + self.assertEqual( + replace_links_with_text(text), + '<a href="/some-link">http://example.com/img.png (picture) some text</a>' + ) + + def test_hotlinked_image_without_alt_replaced(self): + text = '<img src="https://example.com/some-image.gif"/>' + self.assertEqual( + replace_links_with_text(text), + 'https://example.com/some-image.gif' + ) + + def test_hotlinked_image_with_alt_replaced(self): + text = '<img src="https://example.com/some-image.gif" alt="picture"/>' + self.assertEqual( + replace_links_with_text(text), + 'https://example.com/some-image.gif (picture)' + ) 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'>""" |