Rename config= to settings=, refs #1432

This commit is contained in:
Simon Willison 2021-08-12 18:10:36 -07:00
commit ca4f83dc7b
10 changed files with 35 additions and 33 deletions

View file

@ -99,7 +99,7 @@ def make_app_client(
max_returned_rows=None,
cors=False,
memory=False,
config=None,
settings=None,
filename="fixtures.db",
is_immutable=False,
extra_databases=None,
@ -129,7 +129,7 @@ def make_app_client(
# Insert at start to help test /-/databases ordering:
files.insert(0, extra_filepath)
os.chdir(os.path.dirname(filepath))
config = config or {}
settings = settings or {}
for key, value in {
"default_page_size": 50,
"max_returned_rows": max_returned_rows or 100,
@ -138,8 +138,8 @@ def make_app_client(
# errors when running the full test suite:
"num_sql_threads": 1,
}.items():
if key not in config:
config[key] = value
if key not in settings:
settings[key] = value
ds = Datasette(
files,
immutables=immutables,
@ -147,7 +147,7 @@ def make_app_client(
cors=cors,
metadata=metadata or METADATA,
plugins_dir=PLUGINS_DIR,
config=config,
settings=settings,
inspect_data=inspect_data,
static_mounts=static_mounts,
template_dir=template_dir,
@ -171,7 +171,7 @@ def app_client_no_files():
@pytest.fixture(scope="session")
def app_client_base_url_prefix():
with make_app_client(config={"base_url": "/prefix/"}) as client:
with make_app_client(settings={"base_url": "/prefix/"}) as client:
yield client
@ -210,13 +210,13 @@ def app_client_two_attached_databases_one_immutable():
@pytest.fixture(scope="session")
def app_client_with_hash():
with make_app_client(config={"hash_urls": True}, is_immutable=True) as client:
with make_app_client(settings={"hash_urls": True}, is_immutable=True) as client:
yield client
@pytest.fixture(scope="session")
def app_client_with_trace():
with make_app_client(config={"trace_debug": True}, is_immutable=True) as client:
with make_app_client(settings={"trace_debug": True}, is_immutable=True) as client:
yield client
@ -234,13 +234,13 @@ def app_client_returned_rows_matches_page_size():
@pytest.fixture(scope="session")
def app_client_larger_cache_size():
with make_app_client(config={"cache_size_kb": 2500}) as client:
with make_app_client(settings={"cache_size_kb": 2500}) as client:
yield client
@pytest.fixture(scope="session")
def app_client_csv_max_mb_one():
with make_app_client(config={"max_csv_mb": 1}) as client:
with make_app_client(settings={"max_csv_mb": 1}) as client:
yield client

View file

@ -1711,14 +1711,14 @@ def test_suggested_facets(app_client):
def test_allow_facet_off():
with make_app_client(config={"allow_facet": False}) as client:
with make_app_client(settings={"allow_facet": False}) as client:
assert 400 == client.get("/fixtures/facetable.json?_facet=planet_int").status
# Should not suggest any facets either:
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
def test_suggest_facets_off():
with make_app_client(config={"suggest_facets": False}) as client:
with make_app_client(settings={"suggest_facets": False}) as client:
# Now suggested_facets should be []
assert [] == client.get("/fixtures/facetable.json").json["suggested_facets"]
@ -1883,7 +1883,7 @@ def test_config_cache_size(app_client_larger_cache_size):
def test_config_force_https_urls():
with make_app_client(config={"force_https_urls": True}) as client:
with make_app_client(settings={"force_https_urls": True}) as client:
response = client.get("/fixtures/facetable.json?_size=3&_facet=state")
assert response.json["next_url"].startswith("https://")
assert response.json["facet_results"]["state"]["results"][0][
@ -1921,7 +1921,7 @@ def test_custom_query_with_unicode_characters(app_client):
@pytest.mark.parametrize("trace_debug", (True, False))
def test_trace(trace_debug):
with make_app_client(config={"trace_debug": trace_debug}) as client:
with make_app_client(settings={"trace_debug": trace_debug}) as client:
response = client.get("/fixtures/simple_primary_key.json?_trace=1")
assert response.status == 200

View file

@ -14,7 +14,7 @@ def custom_pages_client():
@pytest.fixture(scope="session")
def custom_pages_client_with_base_url():
with make_app_client(
template_dir=TEST_TEMPLATE_DIRS, config={"base_url": "/prefix/"}
template_dir=TEST_TEMPLATE_DIRS, settings={"base_url": "/prefix/"}
) as client:
yield client

View file

@ -351,7 +351,7 @@ async def test_json_array_with_blanks_and_nulls():
@pytest.mark.asyncio
async def test_facet_size():
ds = Datasette([], memory=True, config={"max_returned_rows": 50})
ds = Datasette([], memory=True, settings={"max_returned_rows": 50})
db = ds.add_database(Database(ds, memory_name="test_facet_size"))
await db.execute_write(
"create table neighbourhoods(city text, neighbourhood text)", block=True

View file

@ -214,7 +214,7 @@ def test_definition_sql(path, expected_definition_sql, app_client):
def test_table_cell_truncation():
with make_app_client(config={"truncate_cells_html": 5}) as client:
with make_app_client(settings={"truncate_cells_html": 5}) as client:
response = client.get("/fixtures/facetable")
assert response.status == 200
table = Soup(response.body, "html.parser").find("table")
@ -239,7 +239,7 @@ def test_table_cell_truncation():
def test_row_page_does_not_truncate():
with make_app_client(config={"truncate_cells_html": 5}) as client:
with make_app_client(settings={"truncate_cells_html": 5}) as client:
response = client.get("/fixtures/facetable/1")
assert response.status == 200
table = Soup(response.body, "html.parser").find("table")
@ -1072,7 +1072,9 @@ def test_database_download_disallowed_for_memory():
def test_allow_download_off():
with make_app_client(is_immutable=True, config={"allow_download": False}) as client:
with make_app_client(
is_immutable=True, settings={"allow_download": False}
) as client:
response = client.get("/fixtures")
soup = Soup(response.body, "html.parser")
assert not len(soup.findAll("a", {"href": re.compile(r"\.db$")}))
@ -1486,7 +1488,7 @@ def test_query_error(app_client):
def test_config_template_debug_on():
with make_app_client(config={"template_debug": True}) as client:
with make_app_client(settings={"template_debug": True}) as client:
response = client.get("/fixtures/facetable?_context=1")
assert response.status == 200
assert response.text.startswith("<pre>{")
@ -1500,7 +1502,7 @@ def test_config_template_debug_off(app_client):
def test_debug_context_includes_extra_template_vars():
# https://github.com/simonw/datasette/issues/693
with make_app_client(config={"template_debug": True}) as client:
with make_app_client(settings={"template_debug": True}) as client:
response = client.get("/fixtures/facetable?_context=1")
# scope_path is added by PLUGIN1
assert "scope_path" in response.text
@ -1744,7 +1746,7 @@ def test_facet_more_links(
expected_ellipses_url,
):
with make_app_client(
config={"max_returned_rows": max_returned_rows, "default_facet_size": 2}
settings={"max_returned_rows": max_returned_rows, "default_facet_size": 2}
) as client:
response = client.get(path)
soup = Soup(response.body, "html.parser")