'test the effect of onchange()'

def test_onchange(self):

    discussion = self.env.ref('test_new_api.discussion_0')
    BODY = 'What    a    beautiful    day!'
    USER = self.env.user
    field_onchange = self.Message._onchange_spec()
    self.assertEqual(field_onchange.get('author'), '1')
    self.assertEqual(field_onchange.get('body'), '1')
    self.assertEqual(field_onchange.get('discussion'), '1')
    values = {'discussion': discussion.id, 'name': ('[%s]    %s' % ('', USER.name)), 'body': False, 'author': USER.id, 'size': 0}
    self.env.invalidate_all()
    result = self.Message.onchange(values, 'discussion', field_onchange)
    self.assertIn('name', result['value'])
    self.assertEqual(result['value']['name'], ('[%s]    %s' % (discussion.name, USER.name)))
    values = {'discussion': discussion.id, 'name': ('[%s]    %s' % (discussion.name, USER.name)), 'body': BODY, 'author': USER.id, 'size': 0}
    self.env.invalidate_all()
    result = self.Message.onchange(values, 'body', field_onchange)
    self.assertIn('size', result['value'])
    self.assertEqual(result['value']['size'], len(BODY))
    values = {'discussion': discussion.id, 'name': False, 'body': BODY, 'author': USER.id, 'size': 0}
    self.env.invalidate_all()
    result = self.Message.onchange(values, 'body', field_onchange)
    self.assertNotIn('name', result['value'])
