Skip to content

Commit

Permalink
Applied latest Black
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Oct 20, 2020
1 parent f9dc5c5 commit a013b7f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
6 changes: 5 additions & 1 deletion datasette_graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ async def view_graphql(request, datasette):
if not body and "text/html" in request.headers.get("accept", ""):
return Response.html(
await datasette.render_template(
"graphiql.html", {"database": database,}, request=request
"graphiql.html",
{
"database": database,
},
request=request,
),
headers=CORS_HEADERS if datasette.cors else {},
)
Expand Down
15 changes: 11 additions & 4 deletions datasette_graphql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ async def schema_for_database(datasette, database=None):
)

Query = type(
"Query", (graphene.ObjectType,), {key: value for key, value in to_add},
"Query",
(graphene.ObjectType,),
{key: value for key, value in to_add},
)
return graphene.Schema(
query=Query,
Expand Down Expand Up @@ -392,7 +394,12 @@ def make_table_node_class(
description=field_description
)
table_dict["resolve_{}".format(field_name)] = make_table_resolver(
datasette, db.name, fk.table, table_classes, table_metadata, related_fk=fk,
datasette,
db.name,
fk.table,
table_classes,
table_metadata,
related_fk=fk,
)

table_dict["from_row"] = classmethod(
Expand Down Expand Up @@ -563,8 +570,8 @@ def getter():


def path_from_row_pks(row, pks, use_rowid, quote=True):
""" Generate an optionally URL-quoted unique identifier
for a row from its primary keys."""
"""Generate an optionally URL-quoted unique identifier
for a row from its primary keys."""
if use_rowid:
bits = [row.rowid]
else:
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def build_database(db):
pk="id",
)
db["licenses"].insert_all(
[{"$key": "mit", "name": "MIT"}, {"$key": "apache2", "name": "Apache 2"},],
[
{"$key": "mit", "name": "MIT"},
{"$key": "apache2", "name": "Apache 2"},
],
pk="$key",
)
db["type_compound_key"].insert_all(
Expand Down
12 changes: 8 additions & 4 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def test_examples_link_to_live_demo(request, path):
args = {"query": query}
if variables:
args["variables"] = variables
expected_url = "https://datasette-graphql-demo.datasette.io/graphql{}?{}".format(
"" if is_readme else "/fixtures",
urllib.parse.urlencode(args, quote_via=urllib.parse.quote),
expected_url = (
"https://datasette-graphql-demo.datasette.io/graphql{}?{}".format(
"" if is_readme else "/fixtures",
urllib.parse.urlencode(args, quote_via=urllib.parse.quote),
)
)
fixed_fragment = "```graphql\n{}\n```\n[Try this query]({})\n".format(
query.strip(), expected_url
Expand All @@ -42,7 +44,9 @@ def test_examples_link_to_live_demo(request, path):
try_this_match = link_re.search(content, start)
if try_this_match is None or try_this_match.start() - end != 1:
if should_rewrite:
query_fix_re = re.compile(r"```graphql\n{}\n```\n".format(re.escape(query.strip())))
query_fix_re = re.compile(
r"```graphql\n{}\n```\n".format(re.escape(query.strip()))
)
ideal_content = query_fix_re.sub(fixed_fragment, ideal_content)
else:
assert (
Expand Down
10 changes: 8 additions & 2 deletions tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ async def test_graphql_examples(ds, path):
async with httpx.AsyncClient(app=ds.app()) as client:
response = await client.post(
"http://localhost/graphql",
json={"query": query, "variables": json.loads(variables),},
json={
"query": query,
"variables": json.loads(variables),
},
)
assert response.status_code == 200, response.json()
if response.json()["data"] != expected:
Expand Down Expand Up @@ -340,7 +343,10 @@ async def test_graphql_output_schema(ds):
@pytest.mark.asyncio
@pytest.mark.parametrize("cors_enabled", [True, False])
async def test_cors_headers(db_path, cors_enabled):
ds = Datasette([db_path], cors=cors_enabled,)
ds = Datasette(
[db_path],
cors=cors_enabled,
)
async with httpx.AsyncClient(app=ds.app()) as client:
response = await client.options("http://localhost/graphql")
assert response.status_code == 200
Expand Down

0 comments on commit a013b7f

Please sign in to comment.