test: a unique CNPJ in the search and the reset output (0.11)

This commit is contained in:
Cauê Faleiros
2026-11-06 11:19:41 -03:00
parent 2bcdb060fd
commit 3d1293a3af
2 changed files with 9 additions and 8 deletions

View File

@@ -47,7 +47,8 @@ def session_upload(client, name):
def run():
tag = secrets.token_hex(4)
mail = f'kanban-{tag}@example.test'
cnpj = '11.222.333/0001-81'
cnpj_digits = '11222333' + f'{int(tag, 16) % 1000000:06d}'
cnpj = f'{cnpj_digits[:2]}.{cnpj_digits[2:5]}.{cnpj_digits[5:8]}/{cnpj_digits[8:12]}-{cnpj_digits[12:]}'
customer = {'mail': mail, 'cnpj': cnpj, 'zap': '(16) 98765-' + str(4000 + int(tag[:3], 16) % 1000)}
client = Client()
client.call('/session')
@@ -183,20 +184,20 @@ def run():
# The company's name from the registry: on the board, and found by the search.
from app import cnpj as registry
# Even after a failed try (the worker may have had no internet), a lookup stores the names.
registry.company('11222333000181', db.connect, transport=httpx.MockTransport(lambda request: httpx.Response(
registry.company(cnpj_digits, db.connect, transport=httpx.MockTransport(lambda request: httpx.Response(
200, json={'razao_social': f'KANBAN {tag} COMERCIO LTDA', 'nome_fantasia': f'Loja {tag}'})))
board = client.call('/operator/board', operator=True)
assert board['names']['11222333000181'] == {'legal': f'KANBAN {tag} COMERCIO LTDA', 'trade': f'Loja {tag}'}
assert board['names'][cnpj_digits] == {'legal': f'KANBAN {tag} COMERCIO LTDA', 'trade': f'Loja {tag}'}
found = client.call('/operator/search?' + urlencode({'q': f'loja {tag}'}), operator=True)
assert str(order_id) in {o['id'] for o in found['orders']}, found
# A failed lookup is kept and not repeated within the day.
with db.connect() as c:
c.execute("DELETE FROM dtf_local.cnpj_names WHERE cnpj='11222333000181'")
c.execute('DELETE FROM dtf_local.cnpj_names WHERE cnpj=%s', (cnpj_digits,))
registry.resolve(db.connect, limit=200, transport=httpx.MockTransport(lambda request: httpx.Response(503)))
with db.connect() as c:
row = c.execute("SELECT fetched_at,failed_at FROM dtf_local.cnpj_names WHERE cnpj='11222333000181'").fetchone()
row = c.execute('SELECT fetched_at,failed_at FROM dtf_local.cnpj_names WHERE cnpj=%s', (cnpj_digits,)).fetchone()
assert row['fetched_at'] is None and row['failed_at'] is not None
assert '11222333000181' not in registry.pending(c, 500)
assert cnpj_digits not in registry.pending(c, 500)
Client().call('/operator/stats', expected=401)
# "Fazer backup agora": recorded for the backup service, shown as asked.
with db.connect() as c:
@@ -216,7 +217,7 @@ def run():
c.execute('DELETE FROM dtf_local.quotes WHERE id=ANY(%s)', ([pending, approved, paid],))
c.execute('DELETE FROM dtf_local.upload_thumbnails WHERE upload_id=%s', (uid,))
c.execute('DELETE FROM dtf_local.uploads WHERE id=%s', (uid,))
c.execute("DELETE FROM dtf_local.cnpj_names WHERE cnpj='11222333000181'")
c.execute('DELETE FROM dtf_local.cnpj_names WHERE cnpj=%s', (cnpj_digits,))
if __name__ == '__main__':

View File

@@ -49,7 +49,7 @@ def run():
assert not c.execute('''SELECT 1 FROM dtf_local.uploads WHERE purged_at IS NULL
AND expires_at>now()''').fetchone()
assert c.execute('SELECT count(*) AS n FROM dtf_local.operators').fetchone()['n'] >= 1
assert 'Apagado.' in lines and 'continua de onde parou' in lines[-1], lines
assert any('Apagado.' in line for line in lines) and 'continua de onde parou' in lines[-1], lines
# The numbering is not reset: DTF-1…DTF-15 already exist in Tiny.
with db.connect() as c:
quote = uuid4()