From 2002c4310762ca3f71057f4ffca4d81516cf05a1 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 3 Jan 2017 18:37:27 +0100 Subject: [PATCH] [IMP] mass_mailing_unique: Add tests --- mass_mailing_unique/README.rst | 1 + mass_mailing_unique/tests/__init__.py | 4 ++ .../tests/test_mass_mailing_unique.py | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 mass_mailing_unique/tests/__init__.py create mode 100644 mass_mailing_unique/tests/test_mass_mailing_unique.py diff --git a/mass_mailing_unique/README.rst b/mass_mailing_unique/README.rst index 22ddc251..e75c471b 100644 --- a/mass_mailing_unique/README.rst +++ b/mass_mailing_unique/README.rst @@ -47,6 +47,7 @@ Contributors * Jairo Llopis * Vicent Cubells +* Pedro M. Baeza Maintainer ---------- diff --git a/mass_mailing_unique/tests/__init__.py b/mass_mailing_unique/tests/__init__.py new file mode 100644 index 00000000..e876756a --- /dev/null +++ b/mass_mailing_unique/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_mass_mailing_unique diff --git a/mass_mailing_unique/tests/test_mass_mailing_unique.py b/mass_mailing_unique/tests/test_mass_mailing_unique.py new file mode 100644 index 00000000..0e962fd1 --- /dev/null +++ b/mass_mailing_unique/tests/test_mass_mailing_unique.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common +from openerp import exceptions +from ..hooks import pre_init_hook + + +class TestMassMailingUnique(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestMassMailingUnique, cls).setUpClass() + cls.list = cls.env['mail.mass_mailing.list'].create({ + 'name': 'Test list', + }) + cls.contact1 = cls.env['mail.mass_mailing.contact'].create({ + 'name': 'Contact 1', + 'email': 'email1@test.com', + }) + + def test_init_hook_list(self): + # Disable temporarily the constraint + self.env.cr.execute(""" + ALTER TABLE mail_mass_mailing_list + DROP CONSTRAINT mail_mass_mailing_list_unique_name + """) + self.env['mail.mass_mailing.list'].create({ + 'name': 'Test list', + }) + with self.assertRaises(exceptions.ValidationError): + pre_init_hook(self.env.cr) + + def test_init_hook_contact(self): + # Disable temporarily the constraint + self.env.cr.execute(""" + ALTER TABLE mail_mass_mailing_contact + DROP CONSTRAINT mail_mass_mailing_contact_unique_mail_per_list + """) + self.env['mail.mass_mailing.contact'].create({ + 'name': 'Contact 2', + 'email': 'email1@test.com', + }) + with self.assertRaises(exceptions.ValidationError): + pre_init_hook(self.env.cr)