'test the value of the one2many field inside the onchange'

def test_onchange_one2many_value(self):

    discussion = self.env.ref('test_new_api.discussion_0')
    demo = self.env.ref('base.user_demo')
    field_onchange = self.Discussion._onchange_spec()
    self.assertEqual(field_onchange.get('messages'), '1')
    self.assertEqual(len(discussion.messages), 3)
    messages = [(4, msg.id) for msg in discussion.messages]
    messages[0] = (1, messages[0][1], {'body': 'test    onchange'})
    values = {'name': discussion.name, 'moderator': demo.id, 'categories': [(4, cat.id) for cat in discussion.categories], 'messages': messages, 'participants': [(4, usr.id) for usr in discussion.participants], 'message_concat': False}
    result = discussion.onchange(values, 'messages', field_onchange)
    self.assertIn('message_concat', result['value'])
    self.assertEqual(result['value']['message_concat'], '\n'.join([('%s:%s' % (m.name, m.body)) for m in discussion.messages]))
