test(tradein): align yandex history tests с batch-executemany (unblock deploy) (#851)
All checks were successful
Deploy Trade-In / deploy (push) Successful in 37s
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / test (push) Successful in 24s
Deploy Trade-In / build-backend (push) Successful in 40s

Co-authored-by: bot-backend <bot-backend@gendsgn.local>
Co-committed-by: bot-backend <bot-backend@gendsgn.local>
This commit is contained in:
bot-backend 2026-05-31 06:16:45 +00:00 committed by bot-reviewer
parent da28a52067
commit 99c751f834

View file

@ -158,8 +158,11 @@ def test_save_history_items_inserts_each():
):
saved = _save_yandex_history_items(db, result)
assert saved == 2
# 2 INSERTs (one per item) + 1 commit
assert db.execute.call_count == 2
# 1 batch INSERT (executemany) + 1 commit
assert db.execute.call_count == 1
args = db.execute.call_args
rows = args.args[1]
assert isinstance(rows, list) and len(rows) == 2
db.commit.assert_called_once()
@ -194,10 +197,21 @@ def test_save_history_items_ext_id_stable_across_calls():
):
_save_yandex_history_items(db1, result)
_save_yandex_history_items(db2, result)
# Both got same call params (ext_id derived from same seed)
ext_ids_1 = [c.args[1]["ext_id"] for c in db1.execute.call_args_list]
ext_ids_2 = [c.args[1]["ext_id"] for c in db2.execute.call_args_list]
# Both calls pass a list-of-dicts (batch executemany); ext_id extracted from each row
ext_ids_1 = [
r["ext_id"]
for c in db1.execute.call_args_list
if isinstance(c.args[1], list)
for r in c.args[1]
]
ext_ids_2 = [
r["ext_id"]
for c in db2.execute.call_args_list
if isinstance(c.args[1], list)
for r in c.args[1]
]
assert ext_ids_1 == ext_ids_2
assert len(ext_ids_1) == 2
def test_save_history_items_db_error_rolls_back_batch():