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.

45 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Tecnativa - Pedro M. Baeza
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. from odoo import exceptions
  6. from ..hooks import pre_init_hook
  7. class TestMassMailingUnique(common.SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestMassMailingUnique, cls).setUpClass()
  11. cls.list = cls.env['mail.mass_mailing.list'].create({
  12. 'name': 'Test list',
  13. })
  14. cls.contact1 = cls.env['mail.mass_mailing.contact'].create({
  15. 'name': 'Contact 1',
  16. 'email': 'email1@test.com',
  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. # Disable temporarily the constraint
  31. self.env.cr.execute("""
  32. ALTER TABLE mail_mass_mailing_contact
  33. DROP CONSTRAINT mail_mass_mailing_contact_unique_mail_per_list
  34. """)
  35. self.env['mail.mass_mailing.contact'].create({
  36. 'name': 'Contact 2',
  37. 'email': 'email1@test.com',
  38. })
  39. with self.assertRaises(exceptions.ValidationError):
  40. pre_init_hook(self.env.cr)