mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-29 12:24:32 +02:00
Better validation for upsert --pk, closes #390
This commit is contained in:
parent
4c6023452c
commit
2b20957b18
3 changed files with 79 additions and 59 deletions
|
|
@ -922,6 +922,23 @@ def test_upsert(db_path, tmpdir):
|
|||
]
|
||||
|
||||
|
||||
def test_upsert_pk_required(db_path, tmpdir):
|
||||
json_path = str(tmpdir / "dogs.json")
|
||||
db = Database(db_path)
|
||||
insert_dogs = [
|
||||
{"id": 1, "name": "Cleo", "age": 4},
|
||||
{"id": 2, "name": "Nixie", "age": 4},
|
||||
]
|
||||
open(json_path, "w").write(json.dumps(insert_dogs))
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["upsert", db_path, "dogs", json_path],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
assert result.exit_code == 2
|
||||
assert "Error: Missing option '--pk'" in result.output
|
||||
|
||||
|
||||
def test_upsert_analyze(db_path, tmpdir):
|
||||
db = Database(db_path)
|
||||
db["rows"].insert({"id": 1, "foo": "x", "n": 3}, pk="id")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue