.upsert() and upsert_all() require pk=, closes #73

This commit is contained in:
Simon Willison 2020-01-05 09:20:11 -08:00
commit 489eda92bc
2 changed files with 18 additions and 3 deletions

View file

@ -1,3 +1,7 @@
from sqlite_utils.db import PrimaryKeyRequired
import pytest
def test_upsert(fresh_db):
table = fresh_db["table"]
table.insert({"id": 1, "name": "Cleo"}, pk="id")
@ -16,6 +20,14 @@ def test_upsert_all(fresh_db):
assert 2 == table.last_pk
def test_upsert_error_if_no_pk(fresh_db):
table = fresh_db["table"]
with pytest.raises(PrimaryKeyRequired):
table.upsert_all([{"id": 1, "name": "Cleo"}])
with pytest.raises(PrimaryKeyRequired):
table.upsert({"id": 1, "name": "Cleo"})
def test_upsert_compound_primary_key(fresh_db):
table = fresh_db["table"]
table.upsert_all(