Files
enterprise-addons/test_mail_enterprise/tests/test_activity.py
T

85 lines
3.5 KiB
Python

from odoo.addons.sms.tests.common import SMSCommon
from odoo.addons.test_mail_sms.tests.common import TestSMSRecipients
from odoo.tests.common import users
from odoo.tests import tagged
from odoo.tools import mute_logger
@tagged('mail_activity')
class TestActivity(SMSCommon, TestSMSRecipients):
@classmethod
def setUpClass(cls):
super(TestActivity, cls).setUpClass()
cls.test_record_voip = cls.env['mail.test.activity.bl.sms.voip'].create({
'name': 'Test Record',
'customer_id': cls.partner_1.id,
'email_from': cls.partner_1.email,
'phone_nbr': '0456999999',
})
cls.phonecall_activity = cls.env.ref('mail.mail_activity_data_call')
cls.phonecall_activity.write({
'default_user_id': cls.user_admin.id,
'default_note': 'Test Default Note',
'summary': 'Test Default Summary',
})
# clean db to ease tests
cls.env['mail.activity.type'].search([
('category', '=', 'phonecall'),
('id', '!=', cls.phonecall_activity.id),
]).unlink()
def test_activity_data(self):
""" Ensure initial data for tests """
self.assertEqual(self.partner_1.phone, '0456001122')
self.assertTrue(self.phonecall_activity)
self.assertEqual(self.phonecall_activity.category, 'phonecall')
@users('employee')
@mute_logger('odoo.addons.voip.models.voip_queue_mixin')
def test_create_call_activity(self):
record = self.test_record_voip.with_env(self.env)
activity = record.create_call_activity()
self.assertEqual(activity.activity_type_id, self.phonecall_activity)
self.assertEqual(activity.phone, self.partner_1.phone)
self.assertFalse(activity.note)
self.assertFalse(activity.summary)
phonecall_activities = self.env['mail.activity'].sudo().search([
('activity_type_id', '=', self.phonecall_activity.id),
])
phonecall_activities.write({'activity_type_id': False})
phonecall_activities.flush_recordset()
# it is now protected, but before protection it was possible to have removed
# 'Call' activity type (aka you can't do self.phonecall_activity.unlink()
# but you may have already removed it)
self.env.cr.execute("DELETE FROM mail_activity_type WHERE id IN %s", (tuple(self.phonecall_activity.ids),))
self.env['ir.model.data'].sudo().search([('name', '=', 'mail_activity_data_call'), ('module', '=', 'mail')]).unlink()
# no more phonecall activity -> will be dynamically created
self.assertFalse(self.env['mail.activity.type'].search([('category', '=', 'phonecall')]))
activity = record.create_call_activity()
new_activity_type = self.env['mail.activity.type'].search([('category', '=', 'phonecall')])
self.assertTrue(bool(new_activity_type))
@users('employee')
def test_type_phonecall(self):
activities = self.env['mail.activity'].create([
{
'activity_type_id': self.phonecall_activity.id,
'phone': '+32455001122',
'user_id': self.user_employee.id,
},
{
'activity_type_id': self.phonecall_activity.id,
'phone': '+32455334455',
'user_id': self.user_employee.id,
},
])
stored_free = self.env['mail.activity'].get_today_call_activities().get('mail.activity')
self.assertEqual(len(stored_free), len(activities), 'Should have one entry / activity')