Upgrade to Black 20.8b1, closes #958

This commit is contained in:
Simon Willison 2020-09-02 15:24:55 -07:00
commit a648bb82ba
22 changed files with 203 additions and 58 deletions

View file

@ -700,7 +700,9 @@ def assert_permissions_checked(datasette, actions):
], """Missing expected permission check: action={}, resource={}
Permission checks seen: {}
""".format(
action, resource, json.dumps(list(datasette._permission_checks), indent=4),
action,
resource,
json.dumps(list(datasette._permission_checks), indent=4),
)

View file

@ -56,7 +56,10 @@ def extra_css_urls(template, database, table, view_name, columns, request, datas
@hookimpl
def extra_js_urls():
return [
{"url": "https://plugin-example.com/jquery.js", "sri": "SRIHASH",},
{
"url": "https://plugin-example.com/jquery.js",
"sri": "SRIHASH",
},
"https://plugin-example.com/plugin1.js",
]
@ -73,7 +76,9 @@ def extra_body_script(
"database": database,
"table": table,
"config": datasette.plugin_config(
"name-of-plugin", database=database, table=table,
"name-of-plugin",
database=database,
table=table,
),
"view_name": view_name,
"request_path": request.path if request is not None else None,
@ -99,7 +104,9 @@ def render_cell(value, column, table, database, datasette):
"table": table,
"database": database,
"config": datasette.plugin_config(
"name-of-plugin", database=database, table=table,
"name-of-plugin",
database=database,
table=table,
),
}
)

View file

@ -7,7 +7,10 @@ import json
@hookimpl
def extra_js_urls():
return [
{"url": "https://plugin-example.com/jquery.js", "sri": "SRIHASH",},
{
"url": "https://plugin-example.com/jquery.js",
"sri": "SRIHASH",
},
"https://plugin-example.com/plugin2.js",
]

View file

@ -1786,7 +1786,11 @@ def test_null_foreign_keys_are_not_expanded(app_client):
"foreign_key_with_label": {"value": "1", "label": "hello"},
"foreign_key_with_no_label": {"value": "1", "label": "1"},
},
{"pk": "2", "foreign_key_with_label": None, "foreign_key_with_no_label": None,},
{
"pk": "2",
"foreign_key_with_label": None,
"foreign_key_with_no_label": None,
},
] == response.json

View file

@ -8,7 +8,10 @@ def test_auth_token(app_client):
"The /-/auth-token endpoint sets the correct cookie"
assert app_client.ds._root_token is not None
path = "/-/auth-token?token={}".format(app_client.ds._root_token)
response = app_client.get(path, allow_redirects=False,)
response = app_client.get(
path,
allow_redirects=False,
)
assert 302 == response.status
assert "/" == response.headers["Location"]
assert {"a": {"id": "root"}} == app_client.ds.unsign(
@ -16,7 +19,13 @@ def test_auth_token(app_client):
)
# Check that a second with same token fails
assert app_client.ds._root_token is None
assert 403 == app_client.get(path, allow_redirects=False,).status
assert (
403
== app_client.get(
path,
allow_redirects=False,
).status
)
def test_actor_cookie(app_client):
@ -38,7 +47,11 @@ def test_actor_cookie_invalid(app_client):
@pytest.mark.parametrize(
"offset,expected", [((24 * 60 * 60), {"id": "test"}), (-(24 * 60 * 60), None),]
"offset,expected",
[
((24 * 60 * 60), {"id": "test"}),
(-(24 * 60 * 60), None),
],
)
def test_actor_cookie_that_expires(app_client, offset, expected):
expires_at = int(time.time()) + offset

View file

@ -72,7 +72,11 @@ def test_insert(canned_write_client):
@pytest.mark.parametrize(
"query_name,expect_csrf_hidden_field",
[("canned_read", False), ("add_name_specify_id", True), ("add_name", True),],
[
("canned_read", False),
("add_name_specify_id", True),
("add_name", True),
],
)
def test_canned_query_form_csrf_hidden_field(
canned_write_client, query_name, expect_csrf_hidden_field

View file

@ -16,7 +16,8 @@ def custom_pages_client(tmp_path_factory):
"utf-8",
)
(pages_dir / "atom.html").write_text(
'{{ custom_header("content-type", "application/xml") }}<?xml ...>', "utf-8",
'{{ custom_header("content-type", "application/xml") }}<?xml ...>',
"utf-8",
)
(pages_dir / "redirect.html").write_text(
'{{ custom_redirect("/example") }}', "utf-8"

View file

@ -33,7 +33,11 @@ import pytest
["2%2", "3%3"],
),
# notlike:
((("foo__notlike", "2%2"),), ['"foo" not like :p0'], ["2%2"],),
(
(("foo__notlike", "2%2"),),
['"foo" not like :p0'],
["2%2"],
),
(
(("foo__isnull", "1"), ("baz__isnull", "1"), ("bar__gt", "10")),
['"bar" > :p0', '"baz" is null', '"foo" is null'],

View file

@ -149,7 +149,8 @@ async def test_execute_write_block_true(db):
@pytest.mark.asyncio
async def test_execute_write_block_false(db):
await db.execute_write(
"update roadside_attractions set name = ? where pk = ?", ["Mystery!", 1],
"update roadside_attractions set name = ? where pk = ?",
["Mystery!", 1],
)
time.sleep(0.1)
rows = await db.execute("select name from roadside_attractions where pk = 1")

View file

@ -7,7 +7,11 @@ import urllib
@pytest.mark.parametrize(
"allow,expected_anon,expected_auth",
[(None, 200, 200), ({}, 403, 403), ({"id": "root"}, 403, 200),],
[
(None, 200, 200),
({}, 403, 403),
({"id": "root"}, 403, 200),
],
)
def test_view_instance(allow, expected_anon, expected_auth):
with make_app_client(metadata={"allow": allow}) as client:
@ -23,7 +27,8 @@ def test_view_instance(allow, expected_anon, expected_auth):
# Should be no padlock
assert "<h1>Datasette 🔒</h1>" not in anon_response.text
auth_response = client.get(
path, cookies={"ds_actor": client.actor_cookie({"id": "root"})},
path,
cookies={"ds_actor": client.actor_cookie({"id": "root"})},
)
assert expected_auth == auth_response.status
# Check for the padlock
@ -33,7 +38,11 @@ def test_view_instance(allow, expected_anon, expected_auth):
@pytest.mark.parametrize(
"allow,expected_anon,expected_auth",
[(None, 200, 200), ({}, 403, 403), ({"id": "root"}, 403, 200),],
[
(None, 200, 200),
({}, 403, 403),
({"id": "root"}, 403, 200),
],
)
def test_view_database(allow, expected_anon, expected_auth):
with make_app_client(
@ -50,7 +59,8 @@ def test_view_database(allow, expected_anon, expected_auth):
# Should be no padlock
assert ">fixtures 🔒</h1>" not in anon_response.text
auth_response = client.get(
path, cookies={"ds_actor": client.actor_cookie({"id": "root"})},
path,
cookies={"ds_actor": client.actor_cookie({"id": "root"})},
)
assert expected_auth == auth_response.status
if (
@ -71,7 +81,8 @@ def test_database_list_respects_view_database():
assert '<a href="/data">data</a></h2>' in anon_response.text
assert '<a href="/fixtures">fixtures</a>' not in anon_response.text
auth_response = client.get(
"/", cookies={"ds_actor": client.actor_cookie({"id": "root"})},
"/",
cookies={"ds_actor": client.actor_cookie({"id": "root"})},
)
assert '<a href="/data">data</a></h2>' in auth_response.text
assert '<a href="/fixtures">fixtures</a> 🔒</h2>' in auth_response.text
@ -102,7 +113,8 @@ def test_database_list_respects_view_table():
for html_fragment in html_fragments:
assert html_fragment not in anon_response_text
auth_response_text = client.get(
"/", cookies={"ds_actor": client.actor_cookie({"id": "root"})},
"/",
cookies={"ds_actor": client.actor_cookie({"id": "root"})},
).text
for html_fragment in html_fragments:
assert html_fragment in auth_response_text
@ -110,7 +122,11 @@ def test_database_list_respects_view_table():
@pytest.mark.parametrize(
"allow,expected_anon,expected_auth",
[(None, 200, 200), ({}, 403, 403), ({"id": "root"}, 403, 200),],
[
(None, 200, 200),
({}, 403, 403),
({"id": "root"}, 403, 200),
],
)
def test_view_table(allow, expected_anon, expected_auth):
with make_app_client(
@ -166,7 +182,11 @@ def test_table_list_respects_view_table():
@pytest.mark.parametrize(
"allow,expected_anon,expected_auth",
[(None, 200, 200), ({}, 403, 403), ({"id": "root"}, 403, 200),],
[
(None, 200, 200),
({}, 403, 403),
({"id": "root"}, 403, 200),
],
)
def test_view_query(allow, expected_anon, expected_auth):
with make_app_client(
@ -332,7 +352,10 @@ def test_allow_debug(app_client, actor, allow, expected_fragment):
@pytest.mark.parametrize(
"allow,expected",
[({"id": "root"}, 403), ({"id": "root", "unauthenticated": True}, 200),],
[
({"id": "root"}, 403),
({"id": "root", "unauthenticated": True}, 200),
],
)
def test_allow_unauthenticated(allow, expected):
with make_app_client(metadata={"allow": allow}) as client:
@ -420,7 +443,8 @@ def test_permissions_cascade(cascade_app_client, path, expected_status, permissi
] = (allow if "query" in permissions else deny)
cascade_app_client.ds._metadata = updated_metadata
response = cascade_app_client.get(
path, cookies={"ds_actor": cascade_app_client.actor_cookie({"id": "test"})},
path,
cookies={"ds_actor": cascade_app_client.actor_cookie({"id": "test"})},
)
assert expected_status == response.status
finally:

View file

@ -737,7 +737,9 @@ def test_hook_register_magic_parameters(restore_working_directory):
"sql": "insert into logs (line) values (:_request_http_version)",
"write": True,
},
"get_uuid": {"sql": "select :_uuid_new",},
"get_uuid": {
"sql": "select :_uuid_new",
},
}
}
}

View file

@ -105,7 +105,13 @@ def test_publish_cloudrun(mock_call, mock_output, mock_which):
@mock.patch("datasette.publish.cloudrun.check_call")
@pytest.mark.parametrize(
"memory,should_fail",
[["1Gi", False], ["2G", False], ["256Mi", False], ["4", True], ["GB", True],],
[
["1Gi", False],
["2G", False],
["256Mi", False],
["4", True],
["GB", True],
],
)
def test_publish_cloudrun_memory(
mock_call, mock_output, mock_which, memory, should_fail

View file

@ -59,7 +59,15 @@ def test_publish_heroku(mock_call, mock_check_output, mock_which):
assert 0 == result.exit_code, result.output
mock_call.assert_has_calls(
[
mock.call(["heroku", "config:set", "-a", "f", "WEB_CONCURRENCY=1",]),
mock.call(
[
"heroku",
"config:set",
"-a",
"f",
"WEB_CONCURRENCY=1",
]
),
mock.call(
["heroku", "builds:create", "-a", "f", "--include-vcs-ignore"]
),