Browse Source

[FIX] Fix partner_email_check conflict with portal, bump version

portal's tests set an invalid email address, `c@c`, that's rejected
by the current version of partner_email_check. If partner_email_check
is installed before portal's tests run then they fail.

To solve this, skip email validation if tests are running, unless a
key in the context is set to make the checks run anyway. That lets
tests in other addons opt in to the checks as well.

The previous update to partner_email_check didn't bump the version
number, so do that now.
12.0
Jan Verbeek 5 years ago
committed by Abraham Anes
parent
commit
932dd04f46
No known key found for this signature in database GPG Key ID: 1865EBA8F25B5188
  1. 2
      partner_email_check/__manifest__.py
  2. 4
      partner_email_check/models/res_partner.py
  3. 22
      partner_email_check/tests/test_partner_email_check.py

2
partner_email_check/__manifest__.py

@ -3,7 +3,7 @@
{ {
'name': 'Email Format Checker', 'name': 'Email Format Checker',
'version': '11.0.1.0.1',
'version': '11.0.1.1.0',
'summary': 'Validate email address field', 'summary': 'Validate email address field',
'author': "Komit, Odoo Community Association (OCA)", 'author': "Komit, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/partner-contact', 'website': 'https://github.com/OCA/partner-contact',

4
partner_email_check/models/res_partner.py

@ -4,6 +4,7 @@
import logging import logging
from odoo import api, models, _ from odoo import api, models, _
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tools import config
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -24,6 +25,9 @@ class ResPartner(models.Model):
@api.model @api.model
def email_check(self, emails): def email_check(self, emails):
if (config['test_enable'] and
not self.env.context.get('test_partner_email_check')):
return emails
return ','.join(self._normalize_email(email.strip()) return ','.join(self._normalize_email(email.strip())
for email in emails.split(',')) for email in emails.split(','))

22
partner_email_check/tests/test_partner_email_check.py

@ -11,7 +11,11 @@ from odoo.tools.misc import mute_logger
class TestPartnerEmailCheck(TransactionCase): class TestPartnerEmailCheck(TransactionCase):
def setUp(self): def setUp(self):
super(TestPartnerEmailCheck, self).setUp() super(TestPartnerEmailCheck, self).setUp()
self.test_partner = self.env['res.partner'].create({
# Checks are disabled during tests unless this key is set
self.res_partner = self.env['res.partner'].with_context(
test_partner_email_check=True
)
self.test_partner = self.res_partner.create({
'name': 'test', 'name': 'test',
}) })
self.wizard = self.env['res.config.settings'].create({}) self.wizard = self.env['res.config.settings'].create({})
@ -76,14 +80,14 @@ class TestPartnerEmailCheck(TransactionCase):
self.disallow_duplicates() self.disallow_duplicates()
self.test_partner.write({'email': 'email@domain.tld'}) self.test_partner.write({'email': 'email@domain.tld'})
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.env['res.partner'].create({
self.res_partner.create({
'name': 'alsotest', 'name': 'alsotest',
'email': 'email@domain.tld' 'email': 'email@domain.tld'
}) })
def test_duplicate_after_normalization_addresses_disallowed(self): def test_duplicate_after_normalization_addresses_disallowed(self):
self.disallow_duplicates() self.disallow_duplicates()
self.env['res.partner'].create({
self.res_partner.create({
'name': 'alsotest', 'name': 'alsotest',
'email': 'email@doMAIN.tld' 'email': 'email@doMAIN.tld'
}) })
@ -96,7 +100,7 @@ class TestPartnerEmailCheck(TransactionCase):
self.test_partner.email = 'foo@bar.org,email@domain.tld' self.test_partner.email = 'foo@bar.org,email@domain.tld'
def test_duplicate_addresses_allowed_by_default(self): def test_duplicate_addresses_allowed_by_default(self):
self.env['res.partner'].create({
self.res_partner.create({
'name': 'alsotest', 'name': 'alsotest',
'email': 'email@domain.tld', 'email': 'email@domain.tld',
}) })
@ -141,9 +145,17 @@ class TestPartnerEmailCheck(TransactionCase):
self.disallow_duplicates() self.disallow_duplicates()
with patch('odoo.addons.partner_email_check.models.res_partner.' with patch('odoo.addons.partner_email_check.models.res_partner.'
'validate_email', None): 'validate_email', None):
self.env['res.partner'].create({
self.res_partner.create({
'name': 'alsotest', 'name': 'alsotest',
'email': 'email@domain.tld' 'email': 'email@domain.tld'
}) })
with self.assertRaises(ValidationError): with self.assertRaises(ValidationError):
self.test_partner.email = 'email@domain.tld' self.test_partner.email = 'email@domain.tld'
def test_invalid_email_addresses_allowed_during_tests(self):
# Note: testing without test_partner_email_check in the context
new_partner = self.env['res.partner'].create({
'name': 'invalidly emailed',
'email': 'invalid'
})
self.assertEqual('invalid', new_partner.email)
Loading…
Cancel
Save