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.

70 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Specialty Medical Drugstore, LLC.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
  4. from openerp.tests.common import TransactionCase
  5. class TestMailChannel(TransactionCase):
  6. def setUp(self):
  7. super(TestMailChannel, self).setUp()
  8. self.operator = self.env.ref(
  9. 'website_livechat_firstname.res_partner_1'
  10. )
  11. self.customer_name = 'Billy Joe'
  12. self.channel_vals = {
  13. 'name': '%s, %s' % (self.customer_name, self.operator.name),
  14. 'public': 'public',
  15. }
  16. self.mail_mod = self.env['mail.channel']
  17. self.test_context = {
  18. 'im_livechat_operator_partner_id': self.operator.id,
  19. }
  20. def test_channel_info_operator_pid_full_name(self):
  21. """ Test get operator name correct when full name """
  22. channel = self.mail_mod.create(self.channel_vals)
  23. res = channel.with_context(self.test_context).channel_info()
  24. self.assertEquals(
  25. res[0]['operator_pid'],
  26. (self.operator.id, u'%s' % self.operator.firstname),
  27. )
  28. def test_channel_info_operator_pid_last_name_only(self):
  29. """ Test get operator name correct if only lastname """
  30. self.operator.firstname = None
  31. channel = self.mail_mod.create(self.channel_vals)
  32. res = channel.with_context(self.test_context).channel_info()
  33. self.assertEquals(
  34. res[0]['operator_pid'],
  35. (self.operator.id, u'%s' % self.operator.name),
  36. )
  37. def test_channel_info_name(self):
  38. """ Test operator name shortened correctly in channel name """
  39. channel = self.mail_mod.create(self.channel_vals)
  40. res = channel.with_context(self.test_context).channel_info()
  41. self.assertEquals(
  42. res[0]['name'],
  43. '%s, %s' % (self.customer_name, self.operator.firstname),
  44. )
  45. def test_channel_info_no_context(self):
  46. """ Test channel_name same if no context passsed """
  47. channel = self.mail_mod.create(self.channel_vals)
  48. res = channel.channel_info()
  49. self.assertEquals(
  50. res[0]['name'],
  51. '%s, %s' % (self.customer_name, self.operator.name),
  52. )
  53. def test_channel_info_not_public(self):
  54. """ Test channel info unchanged if not public channel """
  55. self.channel_vals['public'] = 'private'
  56. channel = self.mail_mod.create(self.channel_vals)
  57. res = channel.with_context(self.test_context).channel_info()
  58. self.assertEquals(
  59. res[0]['name'],
  60. '%s, %s' % (self.customer_name, self.operator.name),
  61. )