[WIP] mail: tests: WIP about comments and tests about message_read. Will be continued later.
bzr revid: tde@openerp.com-20121019140439-u64d06em0z7eax0m
This commit is contained in:
parent
583f26d691
commit
1fbee6cb3c
|
@ -240,7 +240,7 @@ class mail_message(osv.Model):
|
|||
'to_read': message['to_read'],
|
||||
}
|
||||
|
||||
def _message_read_expandable(self, cr, uid, message_list, read_messages,
|
||||
def _message_read_add_expandables(self, cr, uid, message_list, read_messages,
|
||||
message_loaded_ids=[], domain=[], context=None, parent_id=False, limit=None):
|
||||
""" Create the expandable message for all parent message read
|
||||
this function is used by message_read
|
||||
|
@ -331,23 +331,30 @@ class mail_message(osv.Model):
|
|||
except (orm.except_orm, osv.except_osv):
|
||||
return False
|
||||
|
||||
def message_read(self, cr, uid, ids=False, domain=[], message_loaded_ids=[], context=None, parent_id=False, limit=None):
|
||||
""" Read messages from mail.message, and get back a structured tree
|
||||
of messages to be displayed as discussion threads. If IDs is set,
|
||||
def message_read(self, cr, uid, ids=False, domain=[], message_unload_ids=[], context=None, parent_id=False, limit=None):
|
||||
""" Read messages from mail.message, and get back a list of structured
|
||||
messages to be displayed as discussion threads. If IDs is set,
|
||||
fetch these records. Otherwise use the domain to fetch messages.
|
||||
After having fetch messages, their parents & child will be added to obtain
|
||||
well formed threads.
|
||||
After having fetch messages, their ancestors will be added to obtain
|
||||
well formed threads, if uid has access to them.
|
||||
|
||||
TDE note: update this comment after final method implementation
|
||||
After reading the messages, expandables messages are added in the
|
||||
message list (see ``_message_read_add_expandables``). It consists
|
||||
in messages holding the 'read more' data: number of messages to
|
||||
read, domain to apply.
|
||||
|
||||
:param domain: optional domain for searching ids
|
||||
:param limit: number of messages to fetch
|
||||
:param parent_id: if parent_id reached, stop searching for
|
||||
further parents
|
||||
:return list: list of trees of messages
|
||||
:param list ids: optional IDs to fetch
|
||||
:param list domain: optional domain for searching ids if ids not set
|
||||
:param list message_unload_ids: optional ids we do not want to fetch,
|
||||
because i.e. they are already displayed somewhere
|
||||
:param int parent_id: if parent_id reached when adding ancestors,
|
||||
stop going further in the ancestor search
|
||||
:param int limit: number of messages to fetch, before adding the
|
||||
ancestors and expandables
|
||||
:return list: list of message structure for the Chatter widget
|
||||
"""
|
||||
if message_loaded_ids:
|
||||
domain += [('id', 'not in', message_loaded_ids)]
|
||||
if message_unload_ids:
|
||||
domain += [('id', 'not in', message_unload_ids)]
|
||||
limit = limit or self._message_read_limit
|
||||
read_messages = {}
|
||||
message_list = []
|
||||
|
@ -364,22 +371,22 @@ class mail_message(osv.Model):
|
|||
ids = self.search(cr, uid, domain, context=context, limit=limit)
|
||||
for message in self.read(cr, uid, ids, self._message_read_fields, context=context):
|
||||
# if not in tree and not in message_loded list
|
||||
if not read_messages.get(message.get('id')) and message.get('id') not in message_loaded_ids:
|
||||
if not read_messages.get(message.get('id')) and message.get('id') not in message_unload_ids:
|
||||
read_messages[message.get('id')] = message
|
||||
message_list.append(self._message_get_dict(cr, uid, message, context=context))
|
||||
|
||||
# get all parented message if the user have the access
|
||||
parent = self._get_parent(cr, uid, message, context=context)
|
||||
while parent and parent.get('id') != parent_id:
|
||||
if not read_messages.get(parent.get('id')) and parent.get('id') not in message_loaded_ids:
|
||||
if not read_messages.get(parent.get('id')) and parent.get('id') not in message_unload_ids:
|
||||
read_messages[parent.get('id')] = parent
|
||||
message_list.append(self._message_get_dict(cr, uid, parent, context=context))
|
||||
parent = self._get_parent(cr, uid, parent, context=context)
|
||||
|
||||
# get the child expandable messages for the tree
|
||||
message_list = sorted(message_list, key=lambda k: k['id'])
|
||||
message_list = self._message_read_expandable(cr, uid, message_list, read_messages,
|
||||
message_loaded_ids=message_loaded_ids, domain=domain, context=context, parent_id=parent_id, limit=limit)
|
||||
message_list = self._message_read_add_expandables(cr, uid, message_list, read_messages,
|
||||
message_loaded_ids=message_unload_ids, domain=domain, context=context, parent_id=parent_id, limit=limit)
|
||||
|
||||
# message_list = sorted(message_list, key=lambda k: k['id'])
|
||||
return message_list
|
||||
|
|
|
@ -522,7 +522,22 @@ class test_mail(TestMailMockups):
|
|||
|
||||
def test_30_message_read(self):
|
||||
""" Tests for message_read and expandables. """
|
||||
self.assertTrue(1 == 1, 'Test not implemented, do not replace by return True')
|
||||
cr, uid, user_admin, group_pigs = self.cr, self.uid, self.user_admin, self.group_pigs
|
||||
|
||||
# Data: create a discussion in Pigs
|
||||
msg_ids = []
|
||||
for dummy in range(5):
|
||||
msg_ids.append(self.group_pigs.message_post(body='My Body', subtype='mt_comment'))
|
||||
|
||||
# Test: read some specific ids
|
||||
read_msg_list = self.mail_message.message_read(cr, uid, ids=msg_ids[1:3], domain=[('body', 'like', 'dummy')])
|
||||
read_msg_ids = [msg.get('id') for msg in read_msg_list]
|
||||
self.assertEqual(msg_ids[1:3], read_msg_ids, 'message_read with direct ids should read only the requested ids')
|
||||
|
||||
# Test: read messages of Pigs through a domain
|
||||
read_msg_list = self.mail_message.message_read(cr, uid, domain=[('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], limit=200)
|
||||
read_msg_ids = [msg.get('id') for msg in read_msg_list]
|
||||
self.assertEqual(msg_ids, read_msg_ids, 'message_read with domain on Pigs should equal all messages of Pigs')
|
||||
|
||||
def test_40_needaction(self):
|
||||
""" Tests for mail.message needaction. """
|
||||
|
@ -584,7 +599,7 @@ class test_mail(TestMailMockups):
|
|||
# TDE note: temp various asserts because of the random bug about msg1.child_ids
|
||||
msg_ids = self.mail_message.search(cr, uid, [('model', '=', 'mail.group'), ('res_id', '=', self.group_pigs_id)], limit=1)
|
||||
new_msg = self.mail_message.browse(cr, uid, msg_ids[0])
|
||||
self.assertEqual(new_msg.parent_id, msg1, 'Newly processed mail_message (%d) should have msg1 as parent' % (new_msg.id))
|
||||
self.assertEqual(new_msg.parent_id, msg1, 'Newly processed mail_message (%d) should have msg1 as parent (msg2 is %d)' % (new_msg.id, msg2.id))
|
||||
|
||||
# 2. References header
|
||||
reply_msg2 = MAIL_TEMPLATE.format(to='Pretty Pigs <group+pigs@example.com>, other@gmail.com', subject='Re: Re: 1',
|
||||
|
|
Loading…
Reference in New Issue