test update and fix
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Feb 2010 21:47:39 +0100
changeset 158 465f38875f92
parent 157 5ebb8152c714
child 159 b44f273f311f
test update and fix
test/unittest_blog.py
--- a/test/unittest_blog.py	Mon Feb 08 21:29:24 2010 +0100
+++ b/test/unittest_blog.py	Mon Feb 08 21:47:39 2010 +0100
@@ -2,7 +2,7 @@
 import re
 
 from logilab.common.testlib import unittest_main, mock_object
-from cubicweb.devtools.testlib import CubicWebTC
+from cubicweb.devtools.testlib import CubicWebTC, MAILBOX
 
 from email.Header import decode_header
 from cubicweb.sobjects.notification import RenderAndSendNotificationView
@@ -13,21 +13,19 @@
     """test blog specific behaviours"""
 
     def test_notifications(self):
-        cubicweb_blog = self.request().create_entity('Blog', title=u'cubicweb', description=u"cubicweb c'est beau")
-        blog_entry_1 = self.request().create_entity('BlogEntry', title=u"hop", content=u"cubicweb hop")
+        req = self.request()
+        cubicweb_blog = req.create_entity('Blog', title=u'cubicweb', description=u"cubicweb c'est beau")
+        blog_entry_1 = req.create_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.request().create_entity('BlogEntry', title=u"yes",  content=u"cubicweb yes")
+        blog_entry_2 = req.create_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'])
+        self.assertEquals(len(MAILBOX), 0)
+        self.commit()
+        self.assertEquals(len(MAILBOX), 2)
+        mail = MAILBOX[0]
+        self.assertEquals(mail.subject, '[data] hop')
+        mail = MAILBOX[1]
+        self.assertEquals(mail.subject, '[data] yes')
 
 
 if __name__ == '__main__':