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.

48 lines
1.8 KiB

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. from odoo.tests.common import TransactionCase
  3. from odoo.addons.mail.models.mail_activity import MailActivity
  4. from datetime import date
  5. from ..hooks import pre_init_hook, post_load_hook
  6. class TestMailActivityDoneMethods(TransactionCase):
  7. def setUp(self):
  8. super(TestMailActivityDoneMethods, self).setUp()
  9. self.employee = self.env['res.users'].create({
  10. 'company_id': self.env.ref("base.main_company").id,
  11. 'name': "Test User",
  12. 'login': "testuser",
  13. 'groups_id': [(6, 0, [self.env.ref('base.group_user').id])]
  14. })
  15. activity_type = self.env['mail.activity.type'].search(
  16. [('name', '=', 'Meeting')], limit=1)
  17. self.act1 = self.env['mail.activity'].create({
  18. 'activity_type_id': activity_type.id,
  19. 'res_id': self.env.ref("base.res_partner_1").id,
  20. 'res_model_id': self.env['ir.model']._get('res.partner').id,
  21. 'user_id': self.employee.id,
  22. 'date_deadline': date.today(),
  23. })
  24. def test_pre_init_hook(self):
  25. pre_init_hook(self.env.cr)
  26. self.env.cr.execute("""
  27. SELECT * FROM mail_activity WHERE done=True
  28. """)
  29. self.assertEquals(self.env.cr.fetchone(), None)
  30. def test_post_load_hook(self):
  31. post_load_hook()
  32. self.assertTrue(hasattr(MailActivity, 'action_feedback_original'))
  33. def test_mail_activity_done(self):
  34. self.act1.done = True
  35. self.assertEquals(self.act1.state, 'done')
  36. def test_activity_user_count(self):
  37. act_count = self.employee.sudo(self.employee).activity_user_count()
  38. self.assertEqual(len(act_count), 1,
  39. "Number of activities should be equal to one")