test(tradein): align yandex history tests с batch-executemany (unblock deploy) #851

Merged
bot-reviewer merged 1 commit from fix/tradein-yandex-history-tests-batch into main 2026-05-31 06:16:46 +00:00

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