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.

61 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo.tests import common
  5. from odoo.addons.bus.models.bus import json_dump
  6. import mock
  7. class TestResUsers(common.TransactionCase):
  8. def test_notify_info(self):
  9. bus_bus = self.env['bus.bus']
  10. domain = [
  11. ('channel', '=',
  12. json_dump(self.env.user.notify_info_channel_name))
  13. ]
  14. existing = bus_bus.search(domain)
  15. self.env.user.notify_info(
  16. message='message', title='title', sticky=True)
  17. news = bus_bus.search(domain) - existing
  18. self.assertEqual(1, len(news))
  19. self.assertEqual(
  20. '{"message":"message","sticky":true,"title":"title"}',
  21. news.message)
  22. def test_notify_warning(self):
  23. bus_bus = self.env['bus.bus']
  24. domain = [
  25. ('channel', '=',
  26. json_dump(self.env.user.notify_warning_channel_name))
  27. ]
  28. existing = bus_bus.search(domain)
  29. self.env.user.notify_warning(
  30. message='message', title='title', sticky=True)
  31. news = bus_bus.search(domain) - existing
  32. self.assertEqual(1, len(news))
  33. self.assertEqual(
  34. '{"message":"message","sticky":true,"title":"title"}',
  35. news.message)
  36. def test_notify_many(self):
  37. # check that the notification of a list of users is done with
  38. # a single call to the bus
  39. with mock.patch('odoo.addons.bus.models.bus.ImBus.sendmany'
  40. ) as mockedSendMany:
  41. users = self.env.user.search([(1, "=", 1)])
  42. self.assertTrue(len(users) > 1)
  43. users.notify_warning('message')
  44. self.assertEqual(1, mockedSendMany.call_count)
  45. # call_args is a tuple with args (tuple) & kwargs (dict). We check
  46. # positional arguments (args), hence the [0].
  47. pos_call_args = mockedSendMany.call_args[0]
  48. # Ensure the first positional argument is a list with as many
  49. # elements as we had users.
  50. first_pos_call_args = pos_call_args[0]
  51. self.assertIsInstance(first_pos_call_args, list)
  52. self.assertEqual(len(users), len(first_pos_call_args))