From 6153003b76a7d133dc98ce391b39c94e4c55e15a Mon Sep 17 00:00:00 2001 From: Frank Bessou Date: Thu, 18 Aug 2022 12:26:42 +0200 Subject: [PATCH 1/2] test(notification): Test notification using SMTP mock and not using the view render --- test/unittest_hooks.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/test/unittest_hooks.py b/test/unittest_hooks.py index 55b0efd..9c09dd7 100644 --- a/test/unittest_hooks.py +++ b/test/unittest_hooks.py @@ -1,31 +1,40 @@ from cubicweb.devtools import BASE_URL -from cubicweb.devtools.testlib import CubicWebTC +from cubicweb.devtools.testlib import CubicWebTC, MAILBOX class CommentViewsTC(CubicWebTC): - def setup_database(self): with self.admin_access.repo_cnx() as cnx: - self.blog = cnx.create_entity('BlogEntry', title=u"une news !", content=u"cubicweb c'est beau").eid - cnx.create_entity('Comment', content=u"Yo !") - cnx.execute('SET C comments B WHERE B title "une news !", C content "Yo !"') + self.set_option("default-dest-addrs", "john.doe@example.com") + self.blogentry = cnx.create_entity( + "BlogEntry", title="une news !", content="cubicweb c'est beau" + ) cnx.commit() def test_notif_after_add_relation_comments(self): with self.admin_access.web_request() as req: - c = req.execute('Comment X').get_entity(0, 0) - v = self.vreg['views'].select('notif_after_add_relation_comments', req, - rset=c.cw_rset, row=0) - content = v.render(row=0) - self.assertMultiLineEqual(content, - f'''Yo ! + comment = req.create_entity("Comment", content="Yo !") + req.execute( + f"SET C comments B WHERE B eid {self.blogentry.eid}, C eid" + f" {comment.eid}" + ) + self.assertEqual(len(MAILBOX), 0) + req.cnx.commit() + self.assertEqual(len(MAILBOX), 1) + email = MAILBOX[0] + self.assertEqual(email.subject, "new comment for BlogEntry une news !") + self.assertMultiLineEqual( + email.content, + f"""Yo ! i18n_by_author_field: admin -url: {BASE_URL}blogentry/%s''' % c.comments[0].eid) - self.assertEqual(v.subject(), 'new comment for BlogEntry une news !') +url: {BASE_URL}blogentry/%s""" + % self.blogentry.eid, + ) -if __name__ == '__main__': +if __name__ == "__main__": import unittest + unittest.main() -- GitLab From 9f9d78d6fc368c0bc1e89fb0b32f1da760537ed9 Mon Sep 17 00:00:00 2001 From: Frank Bessou Date: Fri, 19 Aug 2022 09:58:59 +0200 Subject: [PATCH 2/2] feat(notification): move rendering logic of NotificationView to `render` method The extraction of cubicweb web will change the way a NotificationView renders as it no longer inherits from View. NotificationView uses a single `render` method which must return a string. This change is compatible with both cubicweb 3.x and cubicweb without cubicweb web. --- cubicweb_comment/hooks.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cubicweb_comment/hooks.py b/cubicweb_comment/hooks.py index e28c361..8248d34 100644 --- a/cubicweb_comment/hooks.py +++ b/cubicweb_comment/hooks.py @@ -23,11 +23,10 @@ class CommentAddedView(notification.NotificationView): root.dc_type(), root.dc_title()) - def cell_call(self, row, col=0, **kwargs): - self.cw_row, self.cw_col = row, col + def render(self, **kwargs): try: view = self._cw.vreg['views'].select('fullthreadtext', self._cw, - rset=self.cw_rset, row=row, col=col) + rset=self.cw_rset) except RegistryException: return - return view.render(row=row, col=col, w=self.w, **kwargs) + return view.render() -- GitLab