social/mass_mailing_partner/tests/test_mail_mass_mailing_contact.py

50 lines
2.1 KiB
Python
Raw Normal View History

2015-08-28 11:15:50 +02:00
# -*- coding: utf-8 -*-
# Copyright 2015 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2015 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# Copyright 2015 Javier Iniesta <javieria@antiun.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
2015-08-28 11:15:50 +02:00
from . import base
from ..hooks import post_init_hook
2015-08-28 11:15:50 +02:00
from psycopg2 import IntegrityError
class MailMassMailingContactCase(base.BaseCase):
def test_match_existing_contacts(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
post_init_hook(self.cr, self.registry)
2015-08-28 11:15:50 +02:00
self.assertEqual(contact.partner_id.id, self.partner.id)
def test_create_mass_mailing_contact(self):
contact = self.create_mailing_contact(
{'email': 'partner2@test.com', 'name': 'Partner test 2',
'list_id': self.mailing_list2.id})
self.check_mailing_contact_partner(contact)
with self.assertRaises(IntegrityError):
self.create_mailing_contact({'email': 'partner2@test.com',
'list_id': self.mailing_list2.id})
def test_write_mass_mailing_contact(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
contact.write({'partner_id': False})
self.check_mailing_contact_partner(contact)
contact2 = self.create_mailing_contact(
{'email': 'partner2@test.com', 'name': 'Partner test 2',
'list_id': self.mailing_list.id})
contact.write({'partner_id': False})
self.assertFalse(contact2.partner_id)
def test_onchange_partner(self):
contact = self.create_mailing_contact(
{'email': 'partner@test.com', 'list_id': self.mailing_list.id})
partner = self.create_partner(
{'name': 'Test partner', 'email': 'sample@test.com'})
with self.env.do_in_onchange():
contact.partner_id = partner
contact._onchange_partner()
self.assertEqual(contact.name, partner.name)
self.assertEqual(contact.email, partner.email)