mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 10:04:10 +02:00
Improved foreign_keys= argument, closes #17
This commit is contained in:
parent
f8d3b7cfe5
commit
557dc3f9a7
3 changed files with 57 additions and 6 deletions
|
|
@ -96,10 +96,7 @@ def test_create_table_works_for_m2m_with_only_foreign_keys(fresh_db):
|
|||
fresh_db["two"].insert({"id": 1}, pk="id")
|
||||
fresh_db["m2m"].insert(
|
||||
{"one_id": 1, "two_id": 1},
|
||||
foreign_keys=(
|
||||
("one_id", "INTEGER", "one", "id"),
|
||||
("two_id", "INTEGER", "two", "id"),
|
||||
),
|
||||
foreign_keys=(("one_id", "one", "id"), ("two_id", "two", "id")),
|
||||
)
|
||||
assert [
|
||||
{"name": "one_id", "type": "INTEGER"},
|
||||
|
|
@ -124,6 +121,15 @@ def test_create_table_works_for_m2m_with_only_foreign_keys(fresh_db):
|
|||
)
|
||||
|
||||
|
||||
def test_create_error_if_invalid_foreign_keys(fresh_db):
|
||||
with pytest.raises(AlterError):
|
||||
fresh_db["one"].insert(
|
||||
{"id": 1, "ref_id": 3},
|
||||
pk="id",
|
||||
foreign_keys=(("ref_id", "bad_table", "bad_column"),),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"col_name,col_type,expected_schema",
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue