mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix bug where -s could reset settings to defaults, closes #2389
This commit is contained in:
parent
f6bd2bf8b0
commit
bf953628bb
4 changed files with 70 additions and 1 deletions
|
|
@ -240,6 +240,31 @@ def test_setting(args):
|
|||
assert settings["default_page_size"] == 5
|
||||
|
||||
|
||||
def test_setting_compatible_with_config(tmp_path):
|
||||
# https://github.com/simonw/datasette/issues/2389
|
||||
runner = CliRunner()
|
||||
config_path = tmp_path / "config.json"
|
||||
config_path.write_text(
|
||||
'{"settings": {"default_page_size": 5, "sql_time_limit_ms": 50}}', "utf-8"
|
||||
)
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"--get",
|
||||
"/-/settings.json",
|
||||
"--config",
|
||||
str(config_path),
|
||||
"--setting",
|
||||
"default_page_size",
|
||||
"10",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0, result.output
|
||||
settings = json.loads(result.output)
|
||||
assert settings["default_page_size"] == 10
|
||||
assert settings["sql_time_limit_ms"] == 50
|
||||
|
||||
|
||||
def test_plugin_s_overwrite():
|
||||
runner = CliRunner()
|
||||
plugins_dir = str(pathlib.Path(__file__).parent / "plugins")
|
||||
|
|
|
|||
|
|
@ -722,3 +722,35 @@ async def test_calculate_etag(tmp_path):
|
|||
utils._etag_cache[path] = "hash"
|
||||
assert "hash" == await utils.calculate_etag(path)
|
||||
utils._etag_cache.clear()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"dict1,dict2,expected",
|
||||
[
|
||||
# Basic update
|
||||
({"a": 1, "b": 2}, {"b": 3, "c": 4}, {"a": 1, "b": 3, "c": 4}),
|
||||
# Nested dictionary update
|
||||
(
|
||||
{"a": 1, "b": {"x": 10, "y": 20}},
|
||||
{"b": {"y": 30, "z": 40}},
|
||||
{"a": 1, "b": {"x": 10, "y": 30, "z": 40}},
|
||||
),
|
||||
# Deep nested update
|
||||
(
|
||||
{"a": {"b": {"c": 1}}},
|
||||
{"a": {"b": {"d": 2}}},
|
||||
{"a": {"b": {"c": 1, "d": 2}}},
|
||||
),
|
||||
# Update with mixed types
|
||||
(
|
||||
{"a": 1, "b": {"x": 10}},
|
||||
{"b": {"y": 20}, "c": [1, 2, 3]},
|
||||
{"a": 1, "b": {"x": 10, "y": 20}, "c": [1, 2, 3]},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_deep_dict_update(dict1, dict2, expected):
|
||||
result = utils.deep_dict_update(dict1, dict2)
|
||||
assert result == expected
|
||||
# Check that the original dict1 was modified
|
||||
assert dict1 == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue