def test_delete_rollback(mocker, session, user_table, delete_api_test_setup): conds = [{"product_id": 10}] cond_list_1 = _get_conditions_list(user_table, conds) with mocker.patch("savage.api.data._get_conditions_list", side_effect=[cond_list_1, Exception()]): with pytest.raises(Exception): delete(user_table, session, conds=conds) version_col_names = user_table.version_columns and_clause = sa.and_(*[ getattr(user_table.ArchiveTable, col_name) == conds[0][col_name] for col_name in version_col_names ]) res = session.execute( sa.select([func.count(user_table.ArchiveTable.archive_id) ]).where(and_clause)) assert res.scalar() == 4 and_clause = sa.and_(*[ getattr(user_table, col_name) == conds[0][col_name] for col_name in version_col_names ]) res = session.execute( sa.select([func.count(user_table.id)]).where(and_clause)) assert res.scalar() == 1
def test_delete_multi_row(session, user_table, delete_api_test_setup): conds = [ { "product_id_1": 11, "product_id_2": "bar" }, { "product_id_1": 11, "product_id_2": "foo" }, ] delete(user_table, session, conds=conds) for c in conds: verify_deleted(c, session, user_table=user_table)
def test_delete_single_row(session, user_table, delete_api_test_setup): conds = [{"product_id_1": 11, "product_id_2": "foo"}] delete(user_table, session, conds=conds) verify_deleted(conds[0], session, user_table=user_table)
def test_delete_multi_row(session, user_table, delete_api_test_setup): conds = [{"product_id": 11}, {"product_id": 10}] delete(user_table, session, conds=conds) for c in conds: verify_deleted(c, session)
def test_delete_single_row(session, user_table, delete_api_test_setup): conds = [{"product_id": 10}] delete(user_table, session, conds=conds) verify_deleted(conds[0], session)