mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 01:44:31 +02:00
WIP tests
This commit is contained in:
parent
2cfc29931d
commit
facec8df62
2 changed files with 31 additions and 0 deletions
22
tests/test_get.py
Normal file
22
tests/test_get.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from sqlite_utils.db import Database, RowNotFound
|
||||
import pytest
|
||||
|
||||
|
||||
def test_get_single_pk(fresh_db):
|
||||
cleo = {"id": 1, "name": "Cleo", "age": 4}
|
||||
table = fresh_db["dogs"].insert(cleo, pk="id")
|
||||
with pytest.raises(RowNotFound):
|
||||
table.get(2)
|
||||
with pytest.raises(RowNotFound):
|
||||
table.get(None)
|
||||
assert cleo == table.get(1)
|
||||
|
||||
|
||||
def test_get_compound_pk(fresh_db):
|
||||
cleo = {"id1": 1, "id2": 1, "name": "Cleo", "age": 4}
|
||||
table = fresh_db["dogs"].insert(cleo, pk=("id1", "id2"))
|
||||
with pytest.raises(RowNotFound):
|
||||
table.get(2)
|
||||
with pytest.raises(RowNotFound):
|
||||
table.get([2, 1])
|
||||
assert cleo == table.get([1, 1])
|
||||
9
tests/test_update.py
Normal file
9
tests/test_update.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from sqlite_utils.db import Database
|
||||
|
||||
|
||||
def test_update(fresh_db):
|
||||
cleo = {"id": 1, "name": "Cleo", "age": 4}
|
||||
fresh_db["dogs"].insert(cleo, pk="id")
|
||||
assert [cleo] == list(fresh_db["dogs"].rows)
|
||||
fresh_db["dogs"].update(1, {"age": 5})
|
||||
assert [{"id": 1, "name": "Cleo", "age": 5}] == list(fresh_db["dogs"].rows)
|
||||
Loading…
Add table
Add a link
Reference in a new issue