diff --git a/addons/phone_validation/tests/__init__.py b/addons/phone_validation/tests/__init__.py index ce1b2168e3b..6ca0192f909 100644 --- a/addons/phone_validation/tests/__init__.py +++ b/addons/phone_validation/tests/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import test_phonenumbers from . import test_phonenumbers_patch diff --git a/addons/phone_validation/tests/test_phonenumbers.py b/addons/phone_validation/tests/test_phonenumbers.py new file mode 100644 index 00000000000..720291f099a --- /dev/null +++ b/addons/phone_validation/tests/test_phonenumbers.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.phone_validation.tools import phone_validation +from odoo.exceptions import UserError +from odoo.tests import tagged +from odoo.tests.common import BaseCase + + +@tagged('phone_validation') +class TestPhonenumbers(BaseCase): + + def test_country_code_falsy(self): + self.assertEqual( + phone_validation.phone_format('0456998877', 'BE', '32', force_format='E164'), + '+32456998877' + ) + # no country code -> UserError, no internal traceback + with self.assertRaises(UserError): + self.assertEqual( + phone_validation.phone_format('0456998877', None, '32', force_format='E164'), + '+32456998877' + ) diff --git a/addons/phone_validation/tools/phone_validation.py b/addons/phone_validation/tools/phone_validation.py index 813f0e4f513..e6744669557 100644 --- a/addons/phone_validation/tools/phone_validation.py +++ b/addons/phone_validation/tools/phone_validation.py @@ -15,7 +15,7 @@ try: def phone_parse(number, country_code): try: - phone_nbr = phonenumbers.parse(number, region=country_code, keep_raw_input=True) + phone_nbr = phonenumbers.parse(number, region=country_code or None, keep_raw_input=True) except phonenumbers.phonenumberutil.NumberParseException as e: raise UserError(_('Unable to parse %(phone)s: %(error)s', phone=number, error=str(e)))