File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 11import types
22
33
4+ # Basic query tests
5+
46def test_query (fresh_db ):
57 fresh_db ["dogs" ].insert_all ([{"name" : "Cleo" }, {"name" : "Pancakes" }])
68 results = fresh_db .query ("select * from dogs order by name desc" )
@@ -15,3 +17,11 @@ def test_execute_returning_dicts(fresh_db):
1517 assert fresh_db .execute_returning_dicts ("select * from test" ) == [
1618 {"id" : 1 , "bar" : 2 }
1719 ]
20+
21+ def test_query_no_update (fresh_db ):
22+ """Test that a query that doesn't update the database:
23+ 1) Returns an empty list and 2) Doesn't change the database"""
24+ fresh_db ["message" ].insert ({"msg_type" : "greeting" , "content" : "hello" })
25+ results = fresh_db .query ("update message set msg_type='note' where msg_type='md'" )
26+ assert list (results ) == []
27+ assert list (fresh_db ["message" ].rows ) == [{"msg_type" : "greeting" , "content" : "hello" }]
Original file line number Diff line number Diff line change 66from sqlite_minutils .db import NotFoundError
77
88
9+ ## Updates where nothing changes
10+
11+ def test_update_no_change (fresh_db ):
12+ "Test updating a row with the same values it already has"
13+ table = fresh_db ["table" ]
14+ table .insert ({"foo" : "bar" })
15+ table .update (1 , {"foo" : "bar" })
16+ assert [{"foo" : "bar" }] == list (table .rows )
17+ table .update (1 , {})
18+ assert [{"foo" : "bar" }] == list (table .rows )
19+
20+ ## Updates where something changes
21+
922def test_update_rowid_table (fresh_db ):
23+ "Test updating a row that just got inserted, using the inserted row's last_pk as rowid"
1024 table = fresh_db ["table" ]
1125 rowid = table .insert ({"foo" : "bar" }).last_pk
1226 table .update (rowid , {"foo" : "baz" })
1327 assert [{"foo" : "baz" }] == list (table .rows )
1428
1529
1630def test_update_pk_table (fresh_db ):
31+ "Like test_update_rowid_table, but with a user-specified primary key"
1732 table = fresh_db ["table" ]
1833 pk = table .insert ({"foo" : "bar" , "id" : 5 }, pk = "id" ).last_pk
1934 assert 5 == pk
You can’t perform that action at this time.
0 commit comments