Files
dtf-system/tests/test_customer_document.py
Cauê Faleiros b83e60ef0c
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s
feat: customers buy with a CPF or a CNPJ
The cart and the account signup take either document, each with its own
mask and check digits. Tiny gets a person (F) for a CPF, Mercado Pago the
matching identification type, and only CNPJs go to the company registry.
The Kanban, the account page and the alerts show which one it is.

Also pins the Correios test's clock: its fake token expired today, so the
suite failed from Oct 16 on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 13:33:50 -03:00

29 lines
1.1 KiB
Python

"""The customer's document: a CPF (a person) or a CNPJ (a company), with its
check digits. Runs where pydantic is installed."""
import unittest
from pydantic import ValidationError
from app.core.models import Customer
def customer(document):
return Customer(cnpj=document, zap='16999999999', mail='loja@example.test')
class CustomerDocumentTest(unittest.TestCase):
def test_a_cpf_or_a_cnpj_is_kept_as_digits(self):
self.assertEqual(customer('529.982.247-25').cnpj, '52998224725')
self.assertEqual(customer('11.222.333/0001-81').cnpj, '11222333000181')
self.assertEqual(customer('55786635000158').cnpj, '55786635000158')
def test_wrong_check_digits_repeated_digits_and_other_lengths_are_refused(self):
for document in ('529.982.247-24', '111.111.111-11', '11.222.333/0001-82', '00000000000000',
'5299822472', '529982247250', '١١٢٢٢٣٣٣٠٠٠١٨١'):
with self.subTest(document=document), self.assertRaises(ValidationError):
customer(document)
if __name__ == '__main__':
unittest.main()