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.

40 lines
1.4 KiB

  1. # Copyright 2016 Tecnativa - Pedro M. Baeza
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. from odoo import exceptions
  5. from ..hooks import pre_init_hook
  6. class TestMassMailingUnique(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestMassMailingUnique, cls).setUpClass()
  10. cls.list = cls.env['mail.mass_mailing.list'].create({
  11. 'name': 'Test list',
  12. })
  13. cls.contact1 = cls.env['mail.mass_mailing.contact'].create({
  14. 'name': 'Contact 1',
  15. 'email': 'email1@test.com',
  16. 'list_ids': [(6, 0, [cls.list.id])]
  17. })
  18. def test_init_hook_list(self):
  19. # Disable temporarily the constraint
  20. self.env.cr.execute("""
  21. ALTER TABLE mail_mass_mailing_list
  22. DROP CONSTRAINT mail_mass_mailing_list_unique_name
  23. """)
  24. self.env['mail.mass_mailing.list'].create({
  25. 'name': 'Test list',
  26. })
  27. with self.assertRaises(exceptions.ValidationError):
  28. pre_init_hook(self.env.cr)
  29. def test_init_hook_contact(self):
  30. with self.assertRaises(exceptions.ValidationError):
  31. self.env['mail.mass_mailing.contact'].create({
  32. 'name': 'Contact 2',
  33. 'email': 'email1@test.com',
  34. 'list_ids': [(6, 0, [self.list.id])]
  35. })