You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  4. # Copyright 2015 Javier Iniesta <javieria@antiun.com>
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from . import base
  7. from ..hooks import post_init_hook
  8. from psycopg2 import IntegrityError
  9. class MailMassMailingContactCase(base.BaseCase):
  10. def test_match_existing_contacts(self):
  11. contact = self.create_mailing_contact(
  12. {'email': 'partner@test.com', 'list_id': self.mailing_list.id})
  13. post_init_hook(self.cr, self.registry)
  14. self.assertEqual(contact.partner_id.id, self.partner.id)
  15. def test_create_mass_mailing_contact(self):
  16. contact = self.create_mailing_contact(
  17. {'email': 'partner2@test.com', 'name': 'Partner test 2',
  18. 'list_id': self.mailing_list2.id})
  19. self.check_mailing_contact_partner(contact)
  20. with self.assertRaises(IntegrityError):
  21. self.create_mailing_contact({'email': 'partner2@test.com',
  22. 'list_id': self.mailing_list2.id})
  23. def test_write_mass_mailing_contact(self):
  24. contact = self.create_mailing_contact(
  25. {'email': 'partner@test.com', 'list_id': self.mailing_list.id})
  26. contact.write({'partner_id': False})
  27. self.check_mailing_contact_partner(contact)
  28. contact2 = self.create_mailing_contact(
  29. {'email': 'partner2@test.com', 'name': 'Partner test 2',
  30. 'list_id': self.mailing_list.id})
  31. contact.write({'partner_id': False})
  32. self.assertFalse(contact2.partner_id)
  33. def test_onchange_partner(self):
  34. contact = self.create_mailing_contact(
  35. {'email': 'partner@test.com', 'list_id': self.mailing_list.id})
  36. partner = self.create_partner(
  37. {'name': 'Test partner', 'email': 'sample@test.com'})
  38. with self.env.do_in_onchange():
  39. contact.partner_id = partner
  40. contact._onchange_partner()
  41. self.assertEqual(contact.name, partner.name)
  42. self.assertEqual(contact.email, partner.email)