All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 3m21s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m1s
Orders carry site, dropflow or atendimento, required and with no default, limited to the three. The Site's orders are marked site where they are created; older orders became site. The Kanban shows the origin on each card and in the order panel, filters by it, and Numeros has a Por origem table: orders, metres, money and time from payment to Finalizado per way in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.5 KiB
Python
66 lines
3.5 KiB
Python
"""The launch cleanup removes test orders and refuses when real money was paid.
|
|
|
|
It empties the order tables, so it runs last. Run inside the API container:
|
|
python -m tests.launch_reset_test
|
|
"""
|
|
from uuid import uuid4
|
|
|
|
from psycopg.types.json import Jsonb
|
|
|
|
from app.core import db
|
|
from ops import launch_reset
|
|
|
|
|
|
def run():
|
|
quote, order, owner = uuid4(), uuid4(), uuid4()
|
|
with db.connect() as c:
|
|
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
|
|
VALUES(%s,%s,%s,'reset-fixture',%s,%s,now())''',
|
|
(quote, owner, uuid4(), Jsonb({'customer': {}, 'items': []}), Jsonb({'items': [], 'total_cents': 1490})))
|
|
c.execute("INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin) VALUES(%s,%s,%s,%s,%s,'site')",
|
|
(order, quote, owner, Jsonb({'items': [], 'total_cents': 1490}), Jsonb({'provider': 'teste'})))
|
|
live = c.execute('''INSERT INTO dtf_local.payment_intents(id,quote_id,provider,provider_payment_id,method,
|
|
status,amount_cents,response) VALUES(%s,%s,'mercadopago',%s,'card','approved',1490,%s) RETURNING id''',
|
|
(uuid4(), quote, str(uuid4()), Jsonb({'live_mode': True}))).fetchone()['id']
|
|
|
|
lines = []
|
|
# Real money paid: nothing happens, even when confirmed.
|
|
assert launch_reset.main(['--confirmar', 'APAGAR'], out=lines.append) == 1
|
|
assert 'dinheiro real' in lines[-1]
|
|
with db.connect() as c:
|
|
c.execute("UPDATE dtf_local.payment_intents SET response='{\"live_mode\": false}' WHERE id=%s", (live,))
|
|
|
|
# Without the word, it only counts.
|
|
lines.clear()
|
|
assert launch_reset.main([], out=lines.append) == 0
|
|
assert 'Nada foi apagado' in lines[-1]
|
|
with db.connect() as c:
|
|
assert c.execute('SELECT 1 FROM dtf_local.orders WHERE id=%s', (order,)).fetchone()
|
|
|
|
lines.clear()
|
|
assert launch_reset.main(['--confirmar', 'APAGAR'], out=lines.append) == 0, lines
|
|
with db.connect() as c:
|
|
for table in ('orders', 'quotes', 'payment_intents', 'movements', 'outbox'):
|
|
assert c.execute(f'SELECT count(*) AS n FROM dtf_local.{table}').fetchone()['n'] == 0, table
|
|
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 'A numeração dos pedidos recomeça em #1.' in lines, lines
|
|
# The worker's own role restarts the numbers: the next order is #1.
|
|
with db.connect() as c:
|
|
quote = uuid4()
|
|
c.execute('''INSERT INTO dtf_local.quotes(id,owner,request_key,request_hash,draft,approved,approved_at)
|
|
VALUES(%s,%s,%s,'reset-fixture',%s,%s,now())''',
|
|
(quote, owner, uuid4(), Jsonb({'customer': {}, 'items': []}), Jsonb({'items': [], 'total_cents': 1490})))
|
|
first = c.execute('''INSERT INTO dtf_local.orders(id,quote_id,owner,snapshot,payment,origin)
|
|
VALUES(%s,%s,%s,%s,%s,'site') RETURNING number''', (uuid4(), quote, owner, Jsonb({'items': []}),
|
|
Jsonb({'provider': 'teste'}))).fetchone()['number']
|
|
assert first == 1, first
|
|
c.execute('DELETE FROM dtf_local.orders WHERE quote_id=%s', (quote,))
|
|
c.execute('DELETE FROM dtf_local.quotes WHERE id=%s', (quote,))
|
|
print('PASS: launch cleanup refuses real payments, counts first, then removes test orders and quotes')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run()
|