mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-13 12:04:09 +02:00
Fix for use_old_upsert branch
Refs https://github.com/simonw/sqlite-utils/pull/653#issuecomment-2864951112
This commit is contained in:
parent
efeba1f18c
commit
41497c3210
3 changed files with 52 additions and 44 deletions
|
|
@ -173,14 +173,16 @@ def test_create_table_from_example_with_compound_primary_keys(fresh_db):
|
|||
@pytest.mark.parametrize(
|
||||
"method_name", ("insert", "upsert", "insert_all", "upsert_all")
|
||||
)
|
||||
def test_create_table_with_custom_columns(fresh_db, method_name):
|
||||
table = fresh_db["dogs"]
|
||||
@pytest.mark.parametrize("use_old_upsert", (False, True))
|
||||
def test_create_table_with_custom_columns(method_name, use_old_upsert):
|
||||
db = Database(memory=True, use_old_upsert=use_old_upsert)
|
||||
table = db["dogs"]
|
||||
method = getattr(table, method_name)
|
||||
record = {"id": 1, "name": "Cleo", "age": "5"}
|
||||
if method_name.endswith("_all"):
|
||||
record = [record]
|
||||
method(record, pk="id", columns={"age": int, "weight": float})
|
||||
assert ["dogs"] == fresh_db.table_names()
|
||||
assert ["dogs"] == db.table_names()
|
||||
expected_columns = [
|
||||
{"name": "id", "type": "INTEGER"},
|
||||
{"name": "name", "type": "TEXT"},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
from sqlite_utils.db import PrimaryKeyRequired
|
||||
from sqlite_utils import Database
|
||||
import pytest
|
||||
|
||||
|
||||
def test_upsert(fresh_db):
|
||||
table = fresh_db["table"]
|
||||
@pytest.mark.parametrize("use_old_upsert", (False, True))
|
||||
def test_upsert(use_old_upsert):
|
||||
db = Database(memory=True, use_old_upsert=use_old_upsert)
|
||||
table = db["table"]
|
||||
table.insert({"id": 1, "name": "Cleo"}, pk="id")
|
||||
table.upsert({"id": 1, "age": 5}, pk="id", alter=True)
|
||||
assert list(table.rows) == [{"id": 1, "name": "Cleo", "age": 5}]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue