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.

120 lines
3.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from mock import patch
  5. from .bus_setup import BusSetup
  6. from ..status_constants import ONLINE, AWAY, OFFLINE
  7. AWAY_TIMER = 'odoo.addons.bus_presence_override.models.' \
  8. 'bus_presence.AWAY_TIMER'
  9. DISCONNECTION_TIMER = 'odoo.addons.bus_presence_override.models.' \
  10. 'bus_presence.DISCONNECTION_TIMER'
  11. class TestBusPresence(BusSetup):
  12. @patch(AWAY_TIMER, 10000000)
  13. @patch(DISCONNECTION_TIMER, 10000000)
  14. def test_compute_status_realtime_online(self):
  15. """ It should be computed to online """
  16. self.assertEquals(
  17. self.pres_admin.status_realtime,
  18. ONLINE,
  19. )
  20. @patch(AWAY_TIMER, 10000000)
  21. @patch(DISCONNECTION_TIMER, 0)
  22. def test_compute_status_realtime_offline(self):
  23. """ It should be computed to offline """
  24. self.assertEquals(
  25. self.pres_admin.status_realtime,
  26. OFFLINE,
  27. )
  28. @patch(AWAY_TIMER, 0)
  29. @patch(DISCONNECTION_TIMER, 10000000)
  30. def test_compute_status_realtime_away(self):
  31. """ It should be computed to away """
  32. self.assertEquals(
  33. self.pres_admin.status_realtime,
  34. AWAY,
  35. )
  36. @patch(AWAY_TIMER, 0)
  37. @patch(DISCONNECTION_TIMER, 0)
  38. def test_compute_status_realtime_both(self):
  39. """ It should be computed to offline even though away as well """
  40. self.assertEquals(
  41. self.pres_admin.status_realtime,
  42. OFFLINE,
  43. )
  44. @patch(AWAY_TIMER, 0)
  45. @patch(DISCONNECTION_TIMER, 0)
  46. def test_status_check_timers_offline(self):
  47. """ It should be changed to offline from online """
  48. self.pres_admin.status = ONLINE
  49. self.assertEquals(
  50. self.pres_admin.status,
  51. ONLINE,
  52. )
  53. self.pres_admin._status_check_disconnection_and_away_timers()
  54. self.assertEquals(
  55. self.pres_admin.status,
  56. OFFLINE,
  57. )
  58. @patch(AWAY_TIMER, 0)
  59. @patch(DISCONNECTION_TIMER, 10000000)
  60. def test_status_check_timers_away(self):
  61. """ It should be changed to away from online """
  62. self.pres_admin.status = ONLINE
  63. self.assertEquals(
  64. self.pres_admin.status,
  65. ONLINE,
  66. )
  67. self.pres_admin._status_check_disconnection_and_away_timers()
  68. self.assertEquals(
  69. self.pres_admin.status,
  70. AWAY,
  71. )
  72. @patch(AWAY_TIMER, 0)
  73. @patch(DISCONNECTION_TIMER, 10000000)
  74. def test_status_check_timers_unchanged(self):
  75. """ It should remain at offline even if status_realtime away """
  76. self.pres_admin.status = OFFLINE
  77. self.assertEquals(
  78. self.pres_admin.status,
  79. OFFLINE,
  80. )
  81. self.pres_admin._status_check_disconnection_and_away_timers()
  82. self.assertEquals(
  83. self.pres_admin.status,
  84. OFFLINE,
  85. )
  86. def test_get_partners_im_statuses(self):
  87. """ It should include demo and admin partner statuses """
  88. recs = self.env['bus.presence'].search([(
  89. 'partner_id', 'in', [self.p_admin.id, self.p_demo.id])]
  90. )
  91. statuses = recs._get_partners_statuses()
  92. self.assertIn(
  93. self.p_admin.id,
  94. statuses,
  95. )
  96. def test_get_users_im_statuses(self):
  97. """ It should include demo and admin user statuses """
  98. recs = self.env['bus.presence'].search([(
  99. 'user_id', 'in', [self.u_admin.id, self.u_demo.id])]
  100. )
  101. statuses = recs._get_users_statuses()
  102. self.assertIn(
  103. self.u_admin.id,
  104. statuses,
  105. )