From 2771ab96e750ab946a74bda81a514c755c5b8a06 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 25 Oct 2020 20:05:56 -0700 Subject: [PATCH] Test showing stdin inserts work --- tests/test_cli.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 9bc112b..062f319 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -554,6 +554,19 @@ def test_insert_simple(tmpdir): assert [] == db["dogs"].indexes +def test_insert_from_stdin(tmpdir): + db_path = str(tmpdir / "dogs.db") + result = CliRunner().invoke( + cli.cli, + ["insert", db_path, "dogs", "-"], + input=json.dumps({"name": "Cleo", "age": 4}), + ) + assert 0 == result.exit_code + assert [{"age": 4, "name": "Cleo"}] == Database(db_path).execute_returning_dicts( + "select * from dogs" + ) + + def test_insert_with_primary_key(db_path, tmpdir): json_path = str(tmpdir / "dog.json") open(json_path, "w").write(json.dumps({"id": 1, "name": "Cleo", "age": 4}))