"""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()