From da53b68aafc2229ce7bb6de9417a8204427cfca9 Mon Sep 17 00:00:00 2001 From: lekss361 Date: Sun, 31 May 2026 09:12:13 +0300 Subject: [PATCH] =?UTF-8?q?test(tradein):=20align=20yandex=20history=20tes?= =?UTF-8?q?ts=20=D1=81=20batch-executemany=20=5Fsave=5Fyandex=5Fhistory=5F?= =?UTF-8?q?items=20(unblock=20deploy)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test_estimator_yandex_integration.py | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tradein-mvp/backend/tests/test_estimator_yandex_integration.py b/tradein-mvp/backend/tests/test_estimator_yandex_integration.py index 7540e567..f95aadb4 100644 --- a/tradein-mvp/backend/tests/test_estimator_yandex_integration.py +++ b/tradein-mvp/backend/tests/test_estimator_yandex_integration.py @@ -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():