From 590085737b22f0d71ee13a3742a308085769e01b Mon Sep 17 00:00:00 2001 From: Neto Date: Sun, 11 Sep 2022 16:25:08 -0300 Subject: [PATCH] [IMP] l10n_br_base: add test units for resource pix --- l10n_br_base/tests/__init__.py | 1 + l10n_br_base/tests/test_valid_pix.py | 97 ++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 l10n_br_base/tests/test_valid_pix.py diff --git a/l10n_br_base/tests/__init__.py b/l10n_br_base/tests/__init__.py index 175dbac74bf8..cccbda90b8de 100644 --- a/l10n_br_base/tests/__init__.py +++ b/l10n_br_base/tests/__init__.py @@ -8,3 +8,4 @@ from . import test_valid_createid from . import test_base_onchange from . import test_other_ie +from . import test_valid_pix diff --git a/l10n_br_base/tests/test_valid_pix.py b/l10n_br_base/tests/test_valid_pix.py new file mode 100644 index 000000000000..aab986f96638 --- /dev/null +++ b/l10n_br_base/tests/test_valid_pix.py @@ -0,0 +1,97 @@ +from odoo.exceptions import ValidationError +from odoo.tests import TransactionCase + + +class ValidCreatePIXTest(TransactionCase): + """Test if ValidationError is raised well during create({})""" + + def setUp(self): + super().setUp() + self.partner_id = self.env.ref("l10n_br_base.res_partner_amd") + + def test_invalid_pix_cnpj_too_big(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "cnpj_cpf", + "key": "0296089500013199", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_cnpj_too_less(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "cnpj_cpf", + "key": "950001319", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_cnpj_wrong_value(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "cnpj_cpf", + "key": "12345897560234", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_phone_wrong_value(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "phone", + "key": "1103252020", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_phone_wrong_country_code(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "phone", + "key": "0119991123456789", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_email_wrong_value(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "email", + "key": "teste#teste.com", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_email_too_long(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "email", + "key": "toooooooolooooooooooongemaaaaaailllllll@teeeeeeeee" + "eeeeeeeeeeeeeeeeeeeest.com.br", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_EVP_wrong_value(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "evp", + "key": "nmmnaasa-qwhjwqhjk-2112", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_EVP_wrong_blocks(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "evp", + "key": "123e4567-e12b-12d1-a456-426655-40000", + } + self.check_validation_error_on_create(pix_vals) + + def test_invalid_pix_EVP_wrong_hex(self): + pix_vals = { + "partner_id": self.partner_id.id, + "key_type": "evp", + "key": "123*4567-e12b-12d1-a456-426655440000", + } + self.check_validation_error_on_create(pix_vals) + + def check_validation_error_on_create(self, pix_vals): + with self.assertRaises(ValidationError): + self.env["res.partner.pix"].with_context(tracking_disable=True).create( + pix_vals + )