summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-03-21 21:30:56 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-03-21 21:30:56 -0400
commit1dfdf5207ae6ea7c3b181c52e4939e742922eab0 (patch)
tree142603f70126b3856f52a49244842279316a5558
parent95bd090f0f1bbcdd05e1fcbee81d2a5c2569cdc8 (diff)
downloadaskbot-1dfdf5207ae6ea7c3b181c52e4939e742922eab0.tar.gz
askbot-1dfdf5207ae6ea7c3b181c52e4939e742922eab0.tar.bz2
askbot-1dfdf5207ae6ea7c3b181c52e4939e742922eab0.zip
fixed bugs so that test cases pass
-rw-r--r--askbot/const/__init__.py2
-rw-r--r--askbot/lamson_handlers.py4
-rw-r--r--askbot/models/__init__.py1
-rw-r--r--askbot/skins/default/templates/instant_notification_reply_by_email.html5
-rw-r--r--askbot/tests/reply_by_email_tests.py46
-rw-r--r--askbot/utils/mail.py20
6 files changed, 54 insertions, 24 deletions
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index 66e20dae..ecd6df68 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -51,6 +51,8 @@ POST_SORT_METHODS = (
('relevance-desc', _('relevance')),
)
+REPLY_SEPARATOR = '======= Reply above this line. ====-=-='
+
ANSWER_SORT_METHODS = (#no translations needed here
'latest', 'oldest', 'votes'
)
diff --git a/askbot/lamson_handlers.py b/askbot/lamson_handlers.py
index 7e036644..36ee03af 100644
--- a/askbot/lamson_handlers.py
+++ b/askbot/lamson_handlers.py
@@ -83,7 +83,7 @@ def get_part_type(part):
return 'body'
elif is_attachment(part):
return 'attachment'
- elif is_inline_attacment(part):
+ elif is_inline_attachment(part):
return 'inline'
def get_parts(message):
@@ -104,7 +104,7 @@ def get_parts(message):
part_content = part.body
if part_type in ('attachment', 'inline'):
part_content = format_attachment(part)
- parts.append(part_type, part_content)
+ parts.append((part_type, part_content))
return parts
def get_body(message):
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 7ad46619..08153396 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -2400,6 +2400,7 @@ def format_instant_notification_email(
'post_url': strip_path(site_url) + post.get_absolute_url(),
'origin_post_title': origin_post.thread.title,
'user_subscriptions_url': user_subscriptions_url,
+ 'reply_separator': const.REPLY_SEPARATOR
}
subject_line = _('"%(title)s"') % {'title': origin_post.thread.title}
return subject_line, template.render(Context(update_data))
diff --git a/askbot/skins/default/templates/instant_notification_reply_by_email.html b/askbot/skins/default/templates/instant_notification_reply_by_email.html
index ffb43110..015a259d 100644
--- a/askbot/skins/default/templates/instant_notification_reply_by_email.html
+++ b/askbot/skins/default/templates/instant_notification_reply_by_email.html
@@ -1,8 +1,7 @@
{% if can_reply %}
{% trans %}
-{# Don't change the following line in the template. #}
-======= Reply above this line. ====-=-=
+{{ reply_separator }}
{% endtrans %}
{% else %}
{% trans %}
@@ -11,4 +10,4 @@ you need {{reply_by_email_karma_threshold}} karma, you have {{receiving_user_kar
{% endtrans %}
{% endif %}
-{% include 'instant_notification.html' %} \ No newline at end of file
+{% include 'instant_notification.html' %}
diff --git a/askbot/tests/reply_by_email_tests.py b/askbot/tests/reply_by_email_tests.py
index 5128c9e7..14ea359f 100644
--- a/askbot/tests/reply_by_email_tests.py
+++ b/askbot/tests/reply_by_email_tests.py
@@ -1,15 +1,31 @@
from django.utils.translation import ugettext as _
from askbot.models import ReplyAddress
from askbot.lamson_handlers import PROCESS
+from askbot import const
from askbot.tests.utils import AskbotTestCase
from askbot.models import Post, PostRevision
+TEST_CONTENT = 'Test content'
+TEST_EMAIL_PARTS = (
+ ('body', TEST_CONTENT),
+)
+TEST_LONG_CONTENT = 'Test content' * 10
+TEST_LONG_EMAIL_PARTS = (
+ ('body', TEST_LONG_CONTENT),
+)
+
+class MockPart(object):
+ def __init__(self, body):
+ self.body = body
+ self.content_encoding = {'Content-Type':('text/plain',)}
+
class MockMessage(object):
def __init__(self, body, from_email):
self._body = body
+ self._part = MockPart(body)
self.From= from_email
def body(self):
@@ -17,7 +33,7 @@ class MockMessage(object):
def walk(self):
"""todo: add real file attachment"""
- return list()
+ return [self._part]
class EmailProcessingTests(AskbotTestCase):
@@ -46,9 +62,11 @@ class EmailProcessingTests(AskbotTestCase):
def test_process_correct_answer_comment(self):
addr = ReplyAddress.objects.create_new( self.answer, self.u1).address
- separator = _("======= Reply above this line. ====-=-=")
- msg = MockMessage("This is a test reply \n\nOn such and such someone\
- wrote something \n\n%s\nlorem ipsum "%(separator), "user1@domain.com")
+ msg = MockMessage(
+ "This is a test reply \n\nOn such and such someone"
+ "wrote something \n\n%s\nlorem ipsum " % (const.REPLY_SEPARATOR),
+ "user1@domain.com"
+ )
PROCESS(msg, addr, '')
self.assertEquals(self.answer.comments.count(), 2)
self.assertEquals(self.answer.comments.all().order_by('-pk')[0].text.strip(), "This is a test reply")
@@ -86,31 +104,27 @@ class ReplyAddressModelTests(AskbotTestCase):
def test_create_answer_reply(self):
result = ReplyAddress.objects.create_new( self.answer, self.u1)
- post = result.create_reply("A test post")
+ post = result.create_reply(TEST_EMAIL_PARTS)
self.assertEquals(post.post_type, "comment")
- self.assertEquals(post.text, "A test post")
+ self.assertEquals(post.text, TEST_CONTENT)
self.assertEquals(self.answer.comments.count(), 2)
def test_create_comment_reply(self):
result = ReplyAddress.objects.create_new( self.comment, self.u1)
- post = result.create_reply("A test reply")
+ post = result.create_reply(TEST_EMAIL_PARTS)
self.assertEquals(post.post_type, "comment")
- self.assertEquals(post.text, "A test reply")
+ self.assertEquals(post.text, TEST_CONTENT)
self.assertEquals(self.answer.comments.count(), 2)
def test_create_question_comment_reply(self):
result = ReplyAddress.objects.create_new( self.question, self.u3)
- post = result.create_reply("A test post")
+ post = result.create_reply(TEST_EMAIL_PARTS)
self.assertEquals(post.post_type, "comment")
- self.assertEquals(post.text, "A test post")
+ self.assertEquals(post.text, TEST_CONTENT)
def test_create_question_answer_reply(self):
result = ReplyAddress.objects.create_new( self.question, self.u3)
- post = result.create_reply("A test post "* 10)
+ post = result.create_reply(TEST_LONG_EMAIL_PARTS)
self.assertEquals(post.post_type, "answer")
- self.assertEquals(post.text, "A test post "* 10)
-
-
-
-
+ self.assertEquals(post.text, TEST_LONG_CONTENT)
diff --git a/askbot/utils/mail.py b/askbot/utils/mail.py
index 8ea45394..db09ce6a 100644
--- a/askbot/utils/mail.py
+++ b/askbot/utils/mail.py
@@ -198,6 +198,15 @@ def bounce_email(email, subject, reason = None, body_text = None):
body_text = error_message
)
+def extract_reply(text):
+ """take the part above the separator
+ and discard the last line above the separator"""
+ if const.REPLY_SEPARATOR in text:
+ text = text.split(const.REPLY_SEPARATOR)[0]
+ return '\n'.join(text.splitlines(True)[:-3])
+ else:
+ return text
+
def process_attachment(attachment):
"""will save a single
attachment and return
@@ -222,19 +231,24 @@ def process_parts(parts):
body_markdown = ''
stored_files = list()
attachments_markdown = ''
- for part_type, content in parts:
+ for (part_type, content) in parts:
if part_type == 'attachment':
markdown, stored_file = process_attachment(content)
stored_files.append(stored_file)
attachments_markdown += '\n\n' + markdown
elif part_type == 'body':
- body_markdown += + '\n\n' + content
+ body_markdown += '\n\n' + content
elif part_type == 'inline':
markdown, stored_file = process_attachment(content)
stored_files.append(stored_file)
body_markdown += markdown
- return body_markdown + attachments_markdown, stored_files
+ #if the response separator is present -
+ #split the body with it, and discard the "so and so wrote:" part
+ body_markdown = extract_reply(body_markdown)
+
+ body_markdown += attachments_markdown
+ return body_markdown.strip(), stored_files
def process_emailed_question(from_address, subject, parts):