diff --git a/hooks.py b/hooks.py index 0576c4b660e1bf2563678b85e08cf603660274d4_aG9va3MucHk=..f79c5314a68fb3576839867145d58d9d7ff9b6cd_aG9va3MucHk= 100644 --- a/hooks.py +++ b/hooks.py @@ -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()) + diff --git a/test/unittest_blog.py b/test/unittest_blog.py new file mode 100644 index 0000000000000000000000000000000000000000..f79c5314a68fb3576839867145d58d9d7ff9b6cd_dGVzdC91bml0dGVzdF9ibG9nLnB5 --- /dev/null +++ b/test/unittest_blog.py @@ -0,0 +1,35 @@ +"""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()