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): def tests_urls_equal(self): e = urls_equal self.assertTrue(e('', '')) self.assertTrue(e('', '/', True)) self.assertTrue(e('http://cnn.com', 'http://cnn.com/', True)) self.assertFalse(e('https://cnn.com', 'http://cnn.com')) self.assertFalse(e('http://cnn.com:80', 'http://cnn.com:8000')) 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 = 'some link' self.assertEqual(replace_links_with_text(text), text) def test_link_without_url_replaced(self): text = 'some link' self.assertEqual(replace_links_with_text(text), 'some link') def test_external_link_without_text_replaced(self): text = '' #in this case we delete the link self.assertEqual(replace_links_with_text(text), '') def test_external_link_with_text_replaced(self): text = 'some link' self.assertEqual( replace_links_with_text(text), 'https://example.com/ (some link)' ) def test_local_image_not_replaced(self): text = '' self.assertEqual(replace_links_with_text(text), text) def test_local_url_with_hotlinked_image_replaced(self): text = 'picture some text' self.assertEqual( replace_links_with_text(text), 'http://example.com/img.png (picture) some text' ) def test_hotlinked_image_without_alt_replaced(self): text = '' self.assertEqual( replace_links_with_text(text), 'https://example.com/some-image.gif' ) def test_hotlinked_image_with_alt_replaced(self): text = '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 = """ """ #jinja register.filter decorator works in a weird way self.assertEqual( absolutize_urls(text), ' ' ) text = """link link""" #jinja register.filter decorator works in a weird way self.assertEqual( absolutize_urls(text), 'link link' ) text = '' self.assertEqual( absolutize_urls(text), '' ) text = 'ohaouhaosthoanstoahuaou
Evgeny4 gravatar image' self.assertEqual( absolutize_urls(text), 'ohaouhaosthoanstoahuaou
Evgeny4 gravatar image' ) text = 'and some text
aouaosutoaehut' self.assertEqual( absolutize_urls(text), 'and some text
aouaosutoaehut' )