From e5d7a2ba3d585303c8e1c861a09e8761ba63678f Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 22 Jun 2021 10:43:49 -0700 Subject: [PATCH] Tests for db.query() method, refs #290 --- tests/test_query.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/test_query.py diff --git a/tests/test_query.py b/tests/test_query.py new file mode 100644 index 0000000..fe79cc0 --- /dev/null +++ b/tests/test_query.py @@ -0,0 +1,17 @@ +import types + + +def test_query(fresh_db): + fresh_db["dogs"].insert_all([{"name": "Cleo"}, {"name": "Pancakes"}]) + results = fresh_db.query("select * from dogs order by name desc") + assert isinstance(results, types.GeneratorType) + assert list(results) == [{"name": "Pancakes"}, {"name": "Cleo"}] + + +def test_execute_returning_dicts(fresh_db): + # Like db.query() but returns a list, included for backwards compatibility + # see https://github.com/simonw/sqlite-utils/issues/290 + fresh_db["test"].insert({"id": 1, "bar": 2}, pk="id") + assert fresh_db.execute_returning_dicts("select * from test") == [ + {"id": 1, "bar": 2} + ]