Skip to content

Commit

Permalink
[IMP] l10n_br_base: add test units for resource pix
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniospneto committed Sep 11, 2022
1 parent f48e3b6 commit 5900857
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_base/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from . import test_valid_createid
from . import test_base_onchange
from . import test_other_ie
from . import test_valid_pix
97 changes: 97 additions & 0 deletions l10n_br_base/tests/test_valid_pix.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 5900857

Please sign in to comment.