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
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>
44 lines
1.9 KiB
Python
44 lines
1.9 KiB
Python
"""The CNPJ registry lookup against a fake BrasilAPI. Runs where httpx is installed."""
|
|
import unittest
|
|
|
|
import httpx
|
|
|
|
from app import cnpj
|
|
|
|
|
|
def transport(status, body=None):
|
|
return httpx.MockTransport(lambda request: httpx.Response(status, json=body or {}))
|
|
|
|
|
|
class CnpjTests(unittest.TestCase):
|
|
def test_names_come_from_the_registry_tidied(self):
|
|
found = cnpj.fetch('11222333000181', transport(200, {
|
|
'razao_social': 'LOJA TESTE COMERCIO LTDA ', 'nome_fantasia': 'Loja Teste'}))
|
|
self.assertEqual(found, {'legal_name': 'LOJA TESTE COMERCIO LTDA', 'trade_name': 'Loja Teste'})
|
|
self.assertEqual(cnpj.fetch('11222333000181', transport(200, {'razao_social': 'X LTDA', 'nome_fantasia': ''})),
|
|
{'legal_name': 'X LTDA', 'trade_name': None})
|
|
|
|
def test_an_unknown_cnpj_has_no_names_and_an_outage_is_an_error(self):
|
|
self.assertEqual(cnpj.fetch('00000000000000', transport(404)), {'legal_name': None, 'trade_name': None})
|
|
with self.assertRaises(httpx.HTTPError):
|
|
cnpj.fetch('11222333000181', transport(503))
|
|
|
|
def test_a_cpf_is_never_looked_up(self):
|
|
def refuse():
|
|
raise AssertionError('a CPF reached the database')
|
|
self.assertIsNone(cnpj.company('529.982.247-25', connect=refuse, transport=transport(500)))
|
|
|
|
def test_new_tiny_contacts_are_named_after_the_company(self):
|
|
from app.tiny import contact_payload
|
|
order = {'customer': {'cnpj': '11222333000181', 'mail': 'loja@example.test', 'zap': '16999999999'},
|
|
'destination': None}
|
|
named = contact_payload(order, {'legal': 'LOJA TESTE LTDA', 'trade': 'Loja Teste'})
|
|
self.assertEqual((named['nome'], named['fantasia']), ('LOJA TESTE LTDA', 'Loja Teste'))
|
|
plain = contact_payload(order)
|
|
self.assertEqual(plain['nome'], 'loja@example.test')
|
|
self.assertNotIn('fantasia', plain)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|