'test the value of the one2many field when defined with a domain on a related field'

def test_onchange_one2many_with_domain_on_related_field(self):

    discussion = self.env.ref('test_new_api.discussion_0')
    demo = self.env.ref('base.user_demo')
    view_info = self.Discussion.fields_view_get(view_id=self.env.ref('test_new_api.discussion_form').id, view_type='form')
    field_onchange = self.Discussion._onchange_spec(view_info=view_info)
    self.assertEqual(field_onchange.get('messages'), '1')
    BODY = 'What    a    beautiful    day!'
    USER = self.env.user
    email = self.EmailMessage.create({'discussion': discussion.id, 'name': ('[%s]    %s' % ('', USER.name)), 'body': BODY, 'author': USER.id, 'important': False, 'email_to': demo.email})
    self.env.invalidate_all()
    self.assertIn(email, discussion.emails)
    self.assertNotIn(email, discussion.important_emails)
    email.important = True
    self.assertIn(email, discussion.important_emails)
    self.env.invalidate_all()
    self.assertEqual(len(discussion.messages), 4)
    values = {'name': 'Foo    Bar', 'moderator': demo.id, 'categories': [(4, cat.id) for cat in discussion.categories], 'messages': [(4, msg.id) for msg in discussion.messages], 'participants': [(4, usr.id) for usr in discussion.participants], 'message_changes': 0, 'important_messages': [(4, msg.id) for msg in discussion.important_messages], 'important_emails': [(4, eml.id) for eml in discussion.important_emails]}
    result = discussion.onchange(values, 'name', field_onchange)
    self.assertEqual(result['value']['important_messages'], ([(5,)] + [(4, msg.id) for msg in discussion.important_messages]))
    self.assertEqual(result['value']['important_emails'], [(5,), (1, email.id, {'name': (u'[Foo    Bar]    %s' % USER.name), 'body': email.body, 'author': USER.name_get()[0], 'important': True, 'email_to': demo.email, 'size': email.size})])
