Skip to content

Commit 93ca54f

Browse files
committed
Add precommit and run precommit on all files
1 parent 724695a commit 93ca54f

13 files changed

+102
-40
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
/build/
99

1010
/dist/
11+
/venv/

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- repo: https://github.com/pre-commit/pre-commit-hooks.git
2+
sha: v0.7.1
3+
hooks:
4+
- id: autopep8-wrapper
5+
- id: check-added-large-files
6+
- id: check-ast
7+
- id: check-byte-order-marker
8+
- id: check-case-conflict
9+
- id: check-docstring-first
10+
- id: check-json
11+
- id: check-merge-conflict
12+
- id: check-yaml
13+
- id: debug-statements
14+
- id: double-quote-string-fixer
15+
- id: end-of-file-fixer
16+
- id: flake8
17+
- id: fix-encoding-pragma
18+
- id: name-tests-test
19+
- id: pretty-format-json
20+
args: ['--autofix']
21+
- id: requirements-txt-fixer
22+
- id: trailing-whitespace
23+
- repo: https://github.com/asottile/pyupgrade
24+
sha: v1.0.4
25+
hooks:
26+
- id: pyupgrade
27+
- repo: https://github.com/asottile/reorder_python_imports
28+
sha: v0.3.2
29+
hooks:
30+
- id: reorder-python-imports

flask_graphql/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
from .blueprint import GraphQL
23
from .graphqlview import GraphQLView
34

flask_graphql/blueprint.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import warnings
23

34
from flask import Blueprint

flask_graphql/graphqlview.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
# -*- coding: utf-8 -*-
12
import json
23

34
import six
4-
from flask import Response, request
5+
from flask import request
6+
from flask import Response
57
from flask.views import View
6-
from werkzeug.exceptions import BadRequest, MethodNotAllowed
7-
8-
from graphql import Source, execute, parse, validate
8+
from graphql import execute
9+
from graphql import parse
10+
from graphql import Source
11+
from graphql import validate
912
from graphql.error import format_error as format_graphql_error
1013
from graphql.error import GraphQLError
1114
from graphql.execution import ExecutionResult
1215
from graphql.type.schema import GraphQLSchema
1316
from graphql.utils.get_operation_ast import get_operation_ast
17+
from werkzeug.exceptions import BadRequest
18+
from werkzeug.exceptions import MethodNotAllowed
1419

1520
from .render_graphiql import render_graphiql
1621

flask_graphql/render_graphiql.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
from flask import render_template_string
23

34

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pre-commit==0.13.3

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from setuptools import setup, find_packages
1+
# -*- coding: utf-8 -*-
2+
from setuptools import find_packages
3+
from setuptools import setup
24

35
required_packages = ['graphql-core>=1.0', 'flask>=0.7.0']
46

tests/app.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# -*- coding: utf-8 -*-
12
from flask import Flask
2-
from flask_graphql import GraphQLView
3+
34
from .schema import Schema
5+
from flask_graphql import GraphQLView
46

57

68
def create_app(path='/graphql', **kwargs):

tests/schema.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
1+
# -*- coding: utf-8 -*-
2+
from graphql.type.definition import GraphQLArgument
3+
from graphql.type.definition import GraphQLField
4+
from graphql.type.definition import GraphQLNonNull
5+
from graphql.type.definition import GraphQLObjectType
26
from graphql.type.scalars import GraphQLString
37
from graphql.type.schema import GraphQLSchema
48

59

610
def resolve_raises(*_):
7-
raise Exception("Throws!")
11+
raise Exception('Throws!')
812

913

1014
QueryRootType = GraphQLObjectType(

tests/test_graphiqlview.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# -*- coding: utf-8 -*-
12
import pytest
3+
from flask import url_for
24

35
from .app import create_app
4-
from flask import url_for
56

67

78
@pytest.fixture
@@ -23,6 +24,6 @@ def test_graphiql_renders_pretty(client):
2324
' "test": "Hello World"\n'
2425
' }\n'
2526
'}'
26-
).replace("\"","\\\"").replace("\n","\\n")
27+
).replace("\"", "\\\"").replace('\n', '\\n')
2728

2829
assert pretty_response in response.data.decode('utf-8')

tests/test_graphqlview.py

+40-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pytest
1+
# -*- coding: utf-8 -*-
22
import json
33

4+
import pytest
5+
46
try:
57
from StringIO import StringIO
68
except ImportError:
@@ -19,6 +21,7 @@
1921
def app():
2022
return create_app()
2123

24+
2225
def url_string(**url_params):
2326
string = url_for('graphql')
2427

@@ -41,19 +44,19 @@ def test_allows_get_with_query_param(client):
4144

4245
assert response.status_code == 200
4346
assert response_json(response) == {
44-
'data': {'test': "Hello World"}
47+
'data': {'test': 'Hello World'}
4548
}
4649

4750

4851
def test_allows_get_with_variable_values(client):
4952
response = client.get(url_string(
5053
query='query helloWho($who: String){ test(who: $who) }',
51-
variables=json.dumps({'who': "Dolly"})
54+
variables=json.dumps({'who': 'Dolly'})
5255
))
5356

5457
assert response.status_code == 200
5558
assert response_json(response) == {
56-
'data': {'test': "Hello Dolly"}
59+
'data': {'test': 'Hello Dolly'}
5760
}
5861

5962

@@ -163,7 +166,7 @@ def test_allows_mutation_to_exist_within_a_get(client):
163166

164167
assert response.status_code == 200
165168
assert response_json(response) == {
166-
'data': {'test': "Hello World"}
169+
'data': {'test': 'Hello World'}
167170
}
168171

169172

@@ -172,12 +175,16 @@ def test_allows_post_with_json_encoding(client):
172175

173176
assert response.status_code == 200
174177
assert response_json(response) == {
175-
'data': {'test': "Hello World"}
178+
'data': {'test': 'Hello World'}
176179
}
177180

178181

179182
def test_allows_sending_a_mutation_via_post(client):
180-
response = client.post(url_string(), data=j(query='mutation TestMutation { writeTest { test } }'), content_type='application/json')
183+
response = client.post(
184+
url_string(),
185+
data=j(query='mutation TestMutation { writeTest { test } }'),
186+
content_type='application/json'
187+
)
181188

182189
assert response.status_code == 200
183190
assert response_json(response) == {
@@ -186,87 +193,91 @@ def test_allows_sending_a_mutation_via_post(client):
186193

187194

188195
def test_allows_post_with_url_encoding(client):
189-
response = client.post(url_string(), data=urlencode(dict(query='{test}')), content_type='application/x-www-form-urlencoded')
196+
response = client.post(
197+
url_string(),
198+
data=urlencode(dict(query='{test}')),
199+
content_type='application/x-www-form-urlencoded'
200+
)
190201

191202
assert response.status_code == 200
192203
assert response_json(response) == {
193-
'data': {'test': "Hello World"}
204+
'data': {'test': 'Hello World'}
194205
}
195206

196207

197208
def test_supports_post_json_query_with_string_variables(client):
198209
response = client.post(url_string(), data=j(
199210
query='query helloWho($who: String){ test(who: $who) }',
200-
variables=json.dumps({'who': "Dolly"})
211+
variables=json.dumps({'who': 'Dolly'})
201212
), content_type='application/json')
202213

203214
assert response.status_code == 200
204215
assert response_json(response) == {
205-
'data': {'test': "Hello Dolly"}
216+
'data': {'test': 'Hello Dolly'}
206217
}
207218

208219

209220
def test_supports_post_json_query_with_json_variables(client):
210221
response = client.post(url_string(), data=j(
211222
query='query helloWho($who: String){ test(who: $who) }',
212-
variables={'who': "Dolly"}
223+
variables={'who': 'Dolly'}
213224
), content_type='application/json')
214225

215226
assert response.status_code == 200
216227
assert response_json(response) == {
217-
'data': {'test': "Hello Dolly"}
228+
'data': {'test': 'Hello Dolly'}
218229
}
219230

220231

221232
def test_supports_post_url_encoded_query_with_string_variables(client):
222233
response = client.post(url_string(), data=urlencode(dict(
223234
query='query helloWho($who: String){ test(who: $who) }',
224-
variables=json.dumps({'who': "Dolly"})
235+
variables=json.dumps({'who': 'Dolly'})
225236
)), content_type='application/x-www-form-urlencoded')
226237

227238
assert response.status_code == 200
228239
assert response_json(response) == {
229-
'data': {'test': "Hello Dolly"}
240+
'data': {'test': 'Hello Dolly'}
230241
}
231242

232243

233244
def test_supports_post_json_quey_with_get_variable_values(client):
234245
response = client.post(url_string(
235-
variables=json.dumps({'who': "Dolly"})
246+
variables=json.dumps({'who': 'Dolly'})
236247
), data=j(
237248
query='query helloWho($who: String){ test(who: $who) }',
238249
), content_type='application/json')
239250

240251
assert response.status_code == 200
241252
assert response_json(response) == {
242-
'data': {'test': "Hello Dolly"}
253+
'data': {'test': 'Hello Dolly'}
243254
}
244255

245256

246257
def test_post_url_encoded_query_with_get_variable_values(client):
247258
response = client.post(url_string(
248-
variables=json.dumps({'who': "Dolly"})
259+
variables=json.dumps({'who': 'Dolly'})
249260
), data=urlencode(dict(
250261
query='query helloWho($who: String){ test(who: $who) }',
251262
)), content_type='application/x-www-form-urlencoded')
252263

253264
assert response.status_code == 200
254265
assert response_json(response) == {
255-
'data': {'test': "Hello Dolly"}
266+
'data': {'test': 'Hello Dolly'}
256267
}
257268

258269

259270
def test_supports_post_raw_text_query_with_get_variable_values(client):
260271
response = client.post(url_string(
261-
variables=json.dumps({'who': "Dolly"})
272+
variables=json.dumps({'who': 'Dolly'})
262273
),
263274
data='query helloWho($who: String){ test(who: $who) }',
264275
content_type='application/graphql'
265276
)
266277

267278
assert response.status_code == 200
268279
assert response_json(response) == {
269-
'data': {'test': "Hello Dolly"}
280+
'data': {'test': 'Hello Dolly'}
270281
}
271282

272283

@@ -396,7 +407,7 @@ def test_handles_incomplete_json_bodies(client):
396407

397408
def test_handles_plain_post_text(client):
398409
response = client.post(url_string(
399-
variables=json.dumps({'who': "Dolly"})
410+
variables=json.dumps({'who': 'Dolly'})
400411
),
401412
data='query helloWho($who: String){ test(who: $who) }',
402413
content_type='text/plain'
@@ -438,11 +449,10 @@ def test_passes_request_into_request_context(client):
438449
}
439450

440451

441-
@pytest.mark.parametrize('app', [create_app(context="CUSTOM CONTEXT")])
452+
@pytest.mark.parametrize('app', [create_app(context='CUSTOM CONTEXT')])
442453
def test_supports_pretty_printing(client):
443454
response = client.get(url_string(query='{context}'))
444455

445-
446456
assert response.status_code == 200
447457
assert response_json(response) == {
448458
'data': {
@@ -455,7 +465,7 @@ def test_post_multipart_data(client):
455465
query = 'mutation TestMutation { writeTest { test } }'
456466
response = client.post(
457467
url_string(),
458-
data= {
468+
data={
459469
'query': query,
460470
'file': (StringIO(), 'text1.txt'),
461471
},
@@ -477,7 +487,7 @@ def test_batch_allows_post_with_json_encoding(client):
477487
assert response.status_code == 200
478488
assert response_json(response) == [{
479489
'id': 1,
480-
'payload': { 'data': {'test': "Hello World"} },
490+
'payload': {'data': {'test': 'Hello World'}},
481491
'status': 200,
482492
}]
483493

@@ -489,19 +499,19 @@ def test_batch_supports_post_json_query_with_json_variables(client):
489499
data=jl(
490500
id=1,
491501
query='query helloWho($who: String){ test(who: $who) }',
492-
variables={'who': "Dolly"}
502+
variables={'who': 'Dolly'}
493503
),
494504
content_type='application/json'
495505
)
496506

497507
assert response.status_code == 200
498508
assert response_json(response) == [{
499509
'id': 1,
500-
'payload': { 'data': {'test': "Hello Dolly"} },
510+
'payload': {'data': {'test': 'Hello Dolly'}},
501511
'status': 200,
502512
}]
503-
504-
513+
514+
505515
@pytest.mark.parametrize('app', [create_app(batch=True)])
506516
def test_batch_allows_post_with_operation_name(client):
507517
response = client.post(

tox.ini

+3
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ deps =
2828
Flask>=0.10.0
2929
commands =
3030
isort --check-only flask_graphql/ -rc
31+
32+
[pep8]
33+
max-line-length=120

0 commit comments

Comments
 (0)