summaryrefslogtreecommitdiff
path: root/addons/website_blog/tests
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2014-12-02 16:18:08 +0100
committerChristophe Simonis <chs@odoo.com>2014-12-02 16:18:08 +0100
commit1d3f8eba879f02da7fc0bb46c9801029eccbc8c8 (patch)
tree10ef917de1be8ef9755cba4f3c9ac951af176b18 /addons/website_blog/tests
parent7878b2fd0cb42827b71bd00a1fd8199e73269fe4 (diff)
parent591e329bb0efe4997677a0bee2e6f3b558e35df8 (diff)
[MERGE] forward port of branch 8.0 up to 591e329
Diffstat (limited to 'addons/website_blog/tests')
-rw-r--r--addons/website_blog/tests/__init__.py24
-rw-r--r--addons/website_blog/tests/common.py38
-rw-r--r--addons/website_blog/tests/test_website_blog_flow.py60
3 files changed, 100 insertions, 22 deletions
diff --git a/addons/website_blog/tests/__init__.py b/addons/website_blog/tests/__init__.py
index 157f4549988..3d2b61f96b2 100644
--- a/addons/website_blog/tests/__init__.py
+++ b/addons/website_blog/tests/__init__.py
@@ -1,24 +1,4 @@
# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Business Applications
-# Copyright (c) 20123TODAY OpenERP S.A. <http://www.openerp.com>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-import test_ui
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+from openerp.addons.website_blog.tests import test_ui
+from openerp.addons.website_blog.tests import test_website_blog_flow
diff --git a/addons/website_blog/tests/common.py b/addons/website_blog/tests/common.py
new file mode 100644
index 00000000000..9147d2a3739
--- /dev/null
+++ b/addons/website_blog/tests/common.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+from openerp.tests import common
+
+
+class TestWebsiteBlogCommon(common.TransactionCase):
+ def setUp(self):
+ super(TestWebsiteBlogCommon, self).setUp()
+
+ Users = self.env['res.users']
+
+ group_blog_manager_id = self.ref('base.group_document_user')
+ group_employee_id = self.ref('base.group_user')
+ group_public_id = self.ref('base.group_public')
+
+ self.user_employee = Users.with_context({'no_reset_password': True}).create({
+ 'name': 'Armande Employee',
+ 'login': 'armande',
+ 'alias_name': 'armande',
+ 'email': 'armande.employee@example.com',
+ 'notify_email': 'none',
+ 'groups_id': [(6, 0, [group_employee_id])]
+ })
+ self.user_blogmanager = Users.with_context({'no_reset_password': True}).create({
+ 'name': 'Bastien BlogManager',
+ 'login': 'bastien',
+ 'alias_name': 'bastien',
+ 'email': 'bastien.blogmanager@example.com',
+ 'notify_email': 'none',
+ 'groups_id': [(6, 0, [group_blog_manager_id, group_employee_id])]
+ })
+ self.user_public = Users.with_context({'no_reset_password': True}).create({
+ 'name': 'Cedric Public',
+ 'login': 'cedric',
+ 'alias_name': 'cedric',
+ 'email': 'cedric.public@example.com',
+ 'notify_email': 'none',
+ 'groups_id': [(6, 0, [group_public_id])]
+ })
diff --git a/addons/website_blog/tests/test_website_blog_flow.py b/addons/website_blog/tests/test_website_blog_flow.py
new file mode 100644
index 00000000000..05c2420e59a
--- /dev/null
+++ b/addons/website_blog/tests/test_website_blog_flow.py
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+
+from openerp.addons.website_blog.tests.common import TestWebsiteBlogCommon
+
+
+class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
+
+ def test_website_blog_followers(self):
+ """ Test the flow of followers and notifications for blogs. Intended
+ flow :
+
+ - people subscribe to a blog
+ - when creating a new post, nobody except the creator follows it
+ - people subscribed to the blog does not receive comments on posts
+ - when published, a notification is sent to all blog followers
+ - if someone subscribe to the post or comment it, it become follower
+ and receive notification for future comments. """
+
+ # Create a new blog, subscribe the employee to the blog
+ test_blog = self.env['blog.blog'].sudo(self.user_blogmanager).create({
+ 'name': 'New Blog',
+ 'description': 'Presentation of new Odoo features'
+ })
+ self.assertIn(
+ self.user_blogmanager.partner_id, test_blog.message_follower_ids,
+ 'website_blog: blog create should be in the blog followers')
+ test_blog.message_subscribe([self.user_employee.partner_id.id, self.user_public.partner_id.id])
+
+ # Create a new post, blog followers should not follow the post
+ test_blog_post = self.env['blog.post'].sudo(self.user_blogmanager).create({
+ 'name': 'New Post',
+ 'blog_id': test_blog.id,
+ })
+ self.assertNotIn(
+ self.user_employee.partner_id, test_blog_post.message_follower_ids,
+ 'website_blog: subscribing to a blog should not subscribe to its posts')
+ self.assertNotIn(
+ self.user_public.partner_id, test_blog_post.message_follower_ids,
+ 'website_blog: subscribing to a blog should not subscribe to its posts')
+
+ # Publish the blog
+ test_blog_post.write({'website_published': True})
+
+ # Check publish message has been sent to blog followers
+ publish_message = next((m for m in test_blog_post.blog_id.message_ids if m.subtype_id.id == self.ref('website_blog.mt_blog_blog_published')), None)
+ self.assertEqual(
+ set(publish_message.notified_partner_ids._ids),
+ set([self.user_employee.partner_id.id, self.user_public.partner_id.id]),
+ 'website_blog: peuple following a blog should be notified of a published post')
+
+ # Armand posts a message -> becomes follower
+ test_blog_post.sudo().message_post(
+ body='Armande BlogUser Commented',
+ type='comment',
+ author_id=self.user_employee.partner_id.id,
+ subtype='mt_comment',
+ )
+ self.assertIn(
+ self.user_employee.partner_id, test_blog_post.message_follower_ids,
+ 'website_blog: people commenting a post should follow it afterwards')