test(tradein): align yandex history tests с batch-executemany (unblock deploy) #851
1 changed files with 19 additions and 5 deletions
|
|
@ -158,8 +158,11 @@ def test_save_history_items_inserts_each():
|
||||||
):
|
):
|
||||||
saved = _save_yandex_history_items(db, result)
|
saved = _save_yandex_history_items(db, result)
|
||||||
assert saved == 2
|
assert saved == 2
|
||||||
# 2 INSERTs (one per item) + 1 commit
|
# 1 batch INSERT (executemany) + 1 commit
|
||||||
assert db.execute.call_count == 2
|
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()
|
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(db1, result)
|
||||||
_save_yandex_history_items(db2, result)
|
_save_yandex_history_items(db2, result)
|
||||||
# Both got same call params (ext_id derived from same seed)
|
# Both calls pass a list-of-dicts (batch executemany); ext_id extracted from each row
|
||||||
ext_ids_1 = [c.args[1]["ext_id"] for c in db1.execute.call_args_list]
|
ext_ids_1 = [
|
||||||
ext_ids_2 = [c.args[1]["ext_id"] for c in db2.execute.call_args_list]
|
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 ext_ids_1 == ext_ids_2
|
||||||
|
assert len(ext_ids_1) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_save_history_items_db_error_rolls_back_batch():
|
def test_save_history_items_db_error_rolls_back_batch():
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue