You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests.common import TransactionCase
  5. class TestMailFollowerCustomNotification(TransactionCase):
  6. def test_mail_follower_custom_notification(self):
  7. self.env['mail.thread']._register_hook()
  8. followed_partner = self.env['res.partner'].create({
  9. 'name': 'I\'m followed',
  10. })
  11. demo_user = self.env.ref('base.user_demo')
  12. followed_partner_demo = followed_partner.sudo(demo_user.id)
  13. followed_partner_demo.message_subscribe_users()
  14. # see if default subscriptions return default custom settings
  15. subscription_data = followed_partner_demo._get_subscription_data(
  16. None, None)
  17. self.assertEqual(
  18. subscription_data[followed_partner.id]['message_subtype_data']
  19. ['Discussions']['force_mail'],
  20. 'default')
  21. self.assertEqual(
  22. subscription_data[followed_partner.id]['message_subtype_data']
  23. ['Discussions']['force_own'],
  24. False)
  25. # set custom settings
  26. mt_comment = self.env.ref('mail.mt_comment')
  27. followed_partner_demo.message_custom_notification_update_user({
  28. str(demo_user.id): {
  29. str(mt_comment.id): {
  30. 'force_mail': 'force_yes',
  31. 'force_own': '1',
  32. },
  33. },
  34. })
  35. # see if we can read them back
  36. subscription_data = followed_partner_demo._get_subscription_data(
  37. None, None)
  38. self.assertEqual(
  39. subscription_data[followed_partner.id]['message_subtype_data']
  40. ['Discussions']['force_mail'],
  41. 'force_yes')
  42. self.assertEqual(
  43. subscription_data[followed_partner.id]['message_subtype_data']
  44. ['Discussions']['force_own'],
  45. True)
  46. # post a message and see if we successfully forced a notification to
  47. # ourselves
  48. followed_partner_demo.message_post('hello world', subtype='mt_comment')
  49. self.assertEqual(
  50. followed_partner_demo.message_ids[:-1].notification_ids.partner_id,
  51. demo_user.partner_id)
  52. # assign default values on message subtype and apply them to all
  53. # followers
  54. mt_comment.custom_notification_model_ids = self.env['ir.model']\
  55. .search([('model', '=', 'res.partner')])
  56. wizard = self.env['mail.subtype.assign.custom.notifications']\
  57. .with_context(active_ids=mt_comment.ids)\
  58. .create({})
  59. wizard.button_apply()
  60. subscription_data = followed_partner_demo._get_subscription_data(
  61. None, None)
  62. self.assertEqual(
  63. subscription_data[followed_partner.id]['message_subtype_data']
  64. ['Discussions']['force_mail'],
  65. 'default')
  66. self.assertEqual(
  67. subscription_data[followed_partner.id]['message_subtype_data']
  68. ['Discussions']['force_own'],
  69. False)