Skip to content
Snippets Groups Projects
Commit f79c5314a68f authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

#342714: add [appid] and blog title to the mail'subject'

parent 0576c4b660e1
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,8 @@
"""get notified from new blogs"""
accepts = ('BlogEntry',)
content_attr = 'content'
def subject(self):
entity = self.entity(0)
return '[%s] %s' % (self.config.appid, entity.dc_title())
"""Blog unit tests"""
import re
from logilab.common.testlib import unittest_main, mock_object
from cubicweb.devtools.apptest import ControllerTC
from cubicweb.devtools.testlib import WebTest
from email.Header import decode_header
from cubicweb.sobjects.notification import RenderAndSendNotificationView
from cubicweb.server.hookhelper import SendMailOp
class BlogTests(ControllerTC):
"""test blog specific behaviours"""
def test_notifications(self):
cubicweb_blog = self.add_entity('Blog', title=u'cubicweb', description=u"cubicweb c'est beau")
blog_entry_1 = self.add_entity('BlogEntry', title=u"hop", content=u"cubicweb hop")
self.execute('SET E entry_of B WHERE B eid %(beid)s, E eid %(eeid)s' % {'beid' :cubicweb_blog.eid, 'eeid' : blog_entry_1.eid})
blog_entry_2 = self.add_entity('BlogEntry', title=u"yes", content=u"cubicweb yes")
self.execute('SET E entry_of B WHERE B eid %(beid)s, E eid %(eeid)s' % {'beid' :cubicweb_blog.eid, 'eeid' : blog_entry_2.eid})
session = self.session()
for op in session.pending_operations:
if isinstance(op, RenderAndSendNotificationView):
op.precommit_event()
sendmailops = [op for op in session.pending_operations if isinstance(op, SendMailOp)]
self.assertEquals(len(sendmailops), 1)
sendmailop = sendmailops[0]
sent = [re.sub('#\d+', '#EID', decode_header(msg['subject'].encode())[0][0])
for msg, recipients in op.to_send]
self.assertListEquals(sent, ['[data] hop', '[data] yes'])
if __name__ == '__main__':
unittest_main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment