'test the effect of onchange() on one2many fields'

def test_onchange_one2many(self):

    BODY = 'What    a    beautiful    day!'
    USER = self.env.user
    message = self.Message.create({'body': BODY})
    self.assertEqual(message.name, ('[%s]    %s' % ('', USER.name)))
    field_onchange = self.Discussion._onchange_spec()
    self.assertEqual(field_onchange.get('name'), '1')
    self.assertEqual(field_onchange.get('messages'), '1')
    self.assertItemsEqual(strip_prefix('messages.', field_onchange), ['author', 'body', 'name', 'size', 'important'])
    values = {'name': 'Foo', 'categories': [], 'moderator': False, 'participants': [], 'messages': [(4, message.id), (0, 0, {'name': ('[%s]    %s' % ('', USER.name)), 'body': BODY, 'author': USER.id, 'size': len(BODY), 'important': False})]}
    self.env.invalidate_all()
    result = self.Discussion.onchange(values, 'name', field_onchange)
    self.assertIn('messages', result['value'])
    self.assertItemsEqual(result['value']['messages'], [(5,), (1, message.id, {'name': ('[%s]    %s' % ('Foo', USER.name)), 'body': message.body, 'author': message.author.name_get()[0], 'size': message.size, 'important': message.important}), (0, 0, {'name': ('[%s]    %s' % ('Foo', USER.name)), 'body': BODY, 'author': USER.name_get()[0], 'size': len(BODY), 'important': False})])
