summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-28 01:01:38 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-09-28 01:01:38 -0300
commit6d31e4c12de70f8b9ee5bd84aae45548a15ec0a9 (patch)
tree4e5e630026445bb7b4444f11079292385f67b249
parent3cad23a3791c4c464c3e85430a4c1ccac2a67689 (diff)
parent364633a40e2bfb820e8ddb48252eb614c2985753 (diff)
downloadaskbot-6d31e4c12de70f8b9ee5bd84aae45548a15ec0a9.tar.gz
askbot-6d31e4c12de70f8b9ee5bd84aae45548a15ec0a9.tar.bz2
askbot-6d31e4c12de70f8b9ee5bd84aae45548a15ec0a9.zip
Merge branch 'master' into kp-dev
-rw-r--r--askbot/mail/__init__.py3
-rw-r--r--askbot/templates/email/macros.html2
-rw-r--r--askbot/tests/email_alert_tests.py35
-rw-r--r--askbot/tests/utils_tests.py24
4 files changed, 58 insertions, 6 deletions
diff --git a/askbot/mail/__init__.py b/askbot/mail/__init__.py
index 2d314dbc..74aa27e9 100644
--- a/askbot/mail/__init__.py
+++ b/askbot/mail/__init__.py
@@ -17,6 +17,7 @@ from askbot import const
from askbot.conf import settings as askbot_settings
from askbot.utils import url_utils
from askbot.utils.file_utils import store_file
+from askbot.utils.html import absolutize_urls
from bs4 import BeautifulSoup
#todo: maybe send_mail functions belong to models
@@ -116,6 +117,7 @@ def send_mail(
if raise_on_failure is True, exceptions.EmailNotSent is raised
"""
+ body_text = absolutize_urls(body_text)
try:
assert(subject_line is not None)
subject_line = prefix_the_subject_line(subject_line)
@@ -143,6 +145,7 @@ def mail_moderators(
):
"""sends email to forum moderators and admins
"""
+ body_text = absolutize_urls(body_text)
from django.db.models import Q
from askbot.models import User
recipient_list = User.objects.filter(
diff --git a/askbot/templates/email/macros.html b/askbot/templates/email/macros.html
index f1b06fc8..125705e2 100644
--- a/askbot/templates/email/macros.html
+++ b/askbot/templates/email/macros.html
@@ -70,7 +70,7 @@
{% endif %}
</p>
{% endif %}
- {{ post.html|absolutize_urls }}
+ {{ post.html }}
{{ end_quote(quote_level) }}
{% endspaceless %}
{% endmacro %}
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index 2618cf9a..f4ae052b 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -1,6 +1,7 @@
+import bs4
+import copy
import datetime
import functools
-import copy
import time
from django.conf import settings as django_settings
from django.core import management
@@ -1035,6 +1036,38 @@ class PostApprovalTests(utils.AskbotTestCase):
#self.assertEquals(outbox[1].recipients(), [u1.email,])#approval
+class AbsolutizeUrlsInEmailsTests(utils.AskbotTestCase):
+ @with_settings(MIN_REP_TO_TRIGGER_EMAIL=1, APP_URL='http://example.com/')
+ def test_urls_are_absolute(self):
+ u1 = self.create_user('u1')
+ max_email = models.EmailFeedSetting.MAX_EMAIL_SCHEDULE
+ u2 = self.create_user('u2', notification_schedule=max_email)
+ text = '<a href="/index.html">home</a>' + \
+ '<img alt="an image" src=\'/img.png\'><a href="https://example.com"><img src="/img.png"/></a>'
+ question = self.post_question(user=u1, body_text=text)
+ outbox = django.core.mail.outbox
+ html_message = outbox[0].alternatives[0][0]
+ content_type = outbox[0].alternatives[0][1]
+ self.assertEqual(content_type, 'text/html')
+
+ soup = bs4.BeautifulSoup(html_message)
+ links = soup.find_all('a')
+ url_bits = {}
+ for link in links:
+ url_bits[link.attrs['href'][:4]] = 1
+
+ self.assertEqual(len(url_bits.keys()), 1)
+ self.assertEqual(url_bits.keys()[0], 'http')
+
+ images = soup.find_all('img')
+ url_bits = {}
+ for img in images:
+ url_bits[img.attrs['src'][:4]] = 1
+
+ self.assertEqual(len(url_bits.keys()), 1)
+ self.assertEqual(url_bits.keys()[0], 'http')
+
+
class MailMessagesTests(utils.AskbotTestCase):
def test_ask_for_signature(self):
from askbot.mail import messages
diff --git a/askbot/tests/utils_tests.py b/askbot/tests/utils_tests.py
index bc3bb0bb..c8526ad1 100644
--- a/askbot/tests/utils_tests.py
+++ b/askbot/tests/utils_tests.py
@@ -21,9 +21,9 @@ class UrlUtilsTests(TestCase):
class HTMLUtilsTests(TestCase):
"""tests for :mod:`askbot.utils.html` module"""
-
+
@with_settings(APP_URL='http://example.com')
- def test_absolutize_image_urls(self):
+ 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(
@@ -31,11 +31,27 @@ class HTMLUtilsTests(TestCase):
'<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;">'
)
- @with_settings(APP_URL='http://example.com')
- def test_absolutize_anchor_urls(self):
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'
+ )