test_website_blog_flow.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. from openerp.addons.website_blog.tests.common import TestWebsiteBlogCommon
  3. class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
  4. def test_website_blog_followers(self):
  5. """ Test the flow of followers and notifications for blogs. Intended
  6. flow :
  7. - people subscribe to a blog
  8. - when creating a new post, nobody except the creator follows it
  9. - people subscribed to the blog does not receive comments on posts
  10. - when published, a notification is sent to all blog followers
  11. - if someone subscribe to the post or comment it, it become follower
  12. and receive notification for future comments. """
  13. # Create a new blog, subscribe the employee to the blog
  14. test_blog = self.env['blog.blog'].sudo(self.user_blogmanager).create({
  15. 'name': 'New Blog',
  16. 'description': 'Presentation of new Odoo features'
  17. })
  18. self.assertIn(
  19. self.user_blogmanager.partner_id, test_blog.message_follower_ids,
  20. 'website_blog: blog create should be in the blog followers')
  21. test_blog.message_subscribe([self.user_employee.partner_id.id, self.user_public.partner_id.id])
  22. # Create a new post, blog followers should not follow the post
  23. test_blog_post = self.env['blog.post'].sudo(self.user_blogmanager).create({
  24. 'name': 'New Post',
  25. 'blog_id': test_blog.id,
  26. })
  27. self.assertNotIn(
  28. self.user_employee.partner_id, test_blog_post.message_follower_ids,
  29. 'website_blog: subscribing to a blog should not subscribe to its posts')
  30. self.assertNotIn(
  31. self.user_public.partner_id, test_blog_post.message_follower_ids,
  32. 'website_blog: subscribing to a blog should not subscribe to its posts')
  33. # Publish the blog
  34. test_blog_post.write({'website_published': True})
  35. # Check publish message has been sent to blog followers
  36. 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)
  37. self.assertEqual(
  38. set(publish_message.notified_partner_ids._ids),
  39. set([self.user_employee.partner_id.id, self.user_public.partner_id.id]),
  40. 'website_blog: peuple following a blog should be notified of a published post')
  41. # Armand posts a message -> becomes follower
  42. test_blog_post.sudo().message_post(
  43. body='Armande BlogUser Commented',
  44. type='comment',
  45. author_id=self.user_employee.partner_id.id,
  46. subtype='mt_comment',
  47. )
  48. self.assertIn(
  49. self.user_employee.partner_id, test_blog_post.message_follower_ids,
  50. 'website_blog: people commenting a post should follow it afterwards')