Skip to content

Commit e845156

Browse files
committed
chore: contributing docs and tox config
1 parent 0137ca1 commit e845156

10 files changed

+226
-110
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[report]
2+
omit = */tests/*

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
language: python
2-
sudo: false
2+
cache: pip
3+
dist: xenial
4+
5+
install:
6+
- pip install tox tox-travis
7+
8+
script:
9+
- tox
10+
11+
after_success:
12+
- pip install coveralls
13+
- coveralls
14+
315
matrix:
416
include:
517
- python: pypy
@@ -12,16 +24,7 @@ matrix:
1224
env: TOX_ENV=py36
1325
- python: '3.6'
1426
env: TOX_ENV=import-order,flake8
15-
cache:
16-
directories:
17-
- $HOME/.cache/pip
18-
- $TRAVIS_BUILD_DIR/.tox
19-
install:
20-
- pip install tox coveralls
21-
script:
22-
- tox -e $TOX_ENV -- --cov=flask_graphql
23-
after_success:
24-
- coveralls
27+
2528
deploy:
2629
provider: pypi
2730
user: syrusakbary

CONTRIBUTING.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Contributing
2+
3+
Thanks for helping to make flask-graphql awesome!
4+
5+
We welcome all kinds of contributions:
6+
7+
- Bug fixes
8+
- Documentation improvements
9+
- New features
10+
- Refactoring & tidying
11+
12+
13+
## Getting started
14+
15+
If you have a specific contribution in mind, be sure to check the [issues](https://github.com/graphql-python/flask-graphql/issues) and [projects](https://github.com/graphql-python/flask-graphql/projects) in progress - someone could already be working on something similar and you can help out.
16+
17+
18+
## Project setup
19+
20+
After cloning this repo, ensure dependencies are installed by running:
21+
22+
```sh
23+
make dev-setup
24+
```
25+
26+
## Running tests
27+
28+
After developing, the full test suite can be evaluated by running:
29+
30+
```sh
31+
make tests
32+
```
33+
34+
## Development on Conda
35+
36+
In order to run `tox` command on conda, you must create a new env (e.g. `flask-grapqhl-dev`) with the following command:
37+
38+
```sh
39+
conda create -n flask-grapqhl-dev python=3.8
40+
```
41+
42+
Then activate the environment with `conda activate flask-grapqhl-dev` and install [tox-conda](https://github.com/tox-dev/tox-conda):
43+
44+
```sh
45+
conda install -c conda-forge tox-conda
46+
```
47+
48+
Uncomment the `requires = tox-conda` line on `tox.ini` file and that's it! Run `tox` and you will see all the environments being created and all passing tests. :rocket:
49+

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dev-setup:
2+
python pip install -e ".[test]"
3+
4+
tests:
5+
py.test tests --cov=flask_graphql -vv

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ class UserRootValue(GraphQLView):
3939
return request.user
4040

4141
```
42+
43+
## Contributing
44+
See [CONTRIBUTING.md](contributing.md)

flask_graphql/graphqlview.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, **kwargs):
3838
def get_root_value(self):
3939
return self.root_value
4040

41-
def get_context(self):
41+
def get_context_value(self):
4242
return request
4343

4444
def get_middleware(self):
@@ -89,8 +89,8 @@ def dispatch_request(self):
8989
backend=self.get_backend(),
9090

9191
# Execute options
92-
root=self.get_root_value(),
93-
context=self.get_context(),
92+
root_value=self.get_root_value(),
93+
context_value=self.get_context_value(),
9494
middleware=self.get_middleware(),
9595
**extra_options
9696
)

setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
from setuptools import setup, find_packages
22

3-
required_packages = ["graphql-core>=2.1,<3", "flask>=0.7.0", "graphql-server-core>=1.1,<2"]
3+
install_requires = ["graphql-core>=2.1,<3", "flask>=0.7.0", "graphql-server-core>=1.1,<2"]
4+
5+
tests_requires = [
6+
'pytest >=2.7.2',
7+
'pytest-flask >=0.10.0',
8+
'graphql-core >=2.1,<3',
9+
'graphql-server-core >=1.1,<2',
10+
'Flask >=0.10.0',
11+
]
12+
13+
dev_requires = [
14+
'flake8==3.7.9',
15+
'isort <4.0.0'
16+
] + tests_require
417

518
setup(
619
name="Flask-GraphQL",
720
version="2.0.1",
821
description="Adds GraphQL support to your Flask application",
9-
long_description=open("README.rst").read(),
22+
long_description=open("README.md").read(),
23+
long_description_content_type="text/markdown",
1024
url="https://github.com/graphql-python/flask-graphql",
1125
download_url="https://github.com/graphql-python/flask-graphql/releases",
1226
author="Syrus Akbary",
@@ -29,8 +43,12 @@
2943
],
3044
keywords="api graphql protocol rest flask",
3145
packages=find_packages(exclude=["tests"]),
32-
install_requires=required_packages,
33-
tests_require=["pytest>=2.7.3"],
46+
install_requires=install_requires,
47+
tests_require=tests_requires,
48+
extras_require={
49+
'test': tests_require,
50+
'dev': dev_requires,
51+
}
3452
include_package_data=True,
3553
zip_safe=False,
3654
platforms="any",

tests/test_graphiqlview.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,49 @@
66

77
@pytest.fixture
88
def app():
9-
return create_app(graphiql=True)
9+
# import app factory pattern
10+
app = create_app(graphiql=True)
1011

12+
# pushes an application context manually
13+
ctx = app.app_context()
14+
ctx.push()
15+
return app
1116

12-
def test_graphiql_is_enabled(client):
13-
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
17+
18+
@pytest.fixture
19+
def client(app):
20+
return app.test_client()
21+
22+
23+
def test_graphiql_is_enabled(app, client):
24+
with app.test_request_context():
25+
response = client.get(url_for('graphql', externals=False), headers={'Accept': 'text/html'})
1426
assert response.status_code == 200
1527

1628

17-
def test_graphiql_renders_pretty(client):
18-
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
29+
def test_graphiql_renders_pretty(app, client):
30+
with app.test_request_context():
31+
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
1932
assert response.status_code == 200
2033
pretty_response = (
2134
'{\n'
2235
' "data": {\n'
2336
' "test": "Hello World"\n'
2437
' }\n'
2538
'}'
26-
).replace("\"","\\\"").replace("\n","\\n")
39+
).replace("\"", "\\\"").replace("\n", "\\n")
2740

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

3043

31-
def test_graphiql_default_title(client):
32-
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
44+
def test_graphiql_default_title(app, client):
45+
with app.test_request_context():
46+
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
3347
assert '<title>GraphiQL</title>' in response.data.decode('utf-8')
3448

3549

3650
@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
37-
def test_graphiql_custom_title(client):
38-
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
51+
def test_graphiql_custom_title(app, client):
52+
with app.test_request_context():
53+
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
3954
assert '<title>Awesome</title>' in response.data.decode('utf-8')

0 commit comments

Comments
 (0)