Skip to content

Commit 88089b6

Browse files
authored
Contributing docs and refactor tox config (#77)
* chore: contributing docs and tox config * chore: add pytest-cov and syntax fixes * chore: sort imports on graphqlview * chore: comment out tox-conda on tox file * chore: remove readme rst * chore: add check manifest to dev dependencies * chore: remove matrix jobs on travis * chore: add pyversions to Travis CI * chore: remove py33 and py34 from classifiers
1 parent d29cc6f commit 88089b6

12 files changed

+242
-179
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: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
language: python
22
sudo: false
3-
matrix:
4-
include:
5-
- python: pypy
6-
env: TOX_ENV=pypy
7-
- python: '2.7'
8-
env: TOX_ENV=py27
9-
- python: '3.5'
10-
env: TOX_ENV=py35
11-
- python: '3.6'
12-
env: TOX_ENV=py36
13-
- python: '3.6'
14-
env: TOX_ENV=import-order,flake8
15-
cache:
16-
directories:
17-
- $HOME/.cache/pip
18-
- $TRAVIS_BUILD_DIR/.tox
3+
python:
4+
- 2.7
5+
- 3.5
6+
- 3.6
7+
- 3.7
8+
# - 3.8
9+
cache: pip
10+
1911
install:
20-
- pip install tox coveralls
12+
- pip install tox-travis
13+
2114
script:
22-
- tox -e $TOX_ENV -- --cov=flask_graphql
15+
- tox
16+
2317
after_success:
24-
- coveralls
18+
- pip install coveralls
19+
- coveralls
20+
2521
deploy:
2622
provider: pypi
2723
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+

MANIFEST.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
include LICENSE
12
include README.md
3+
include CONTRIBUTING.md
4+
25
recursive-include flask_graphql/static *
36
recursive-include flask_graphql/templates *
7+
recursive-include tests *.py
8+
9+
include Makefile
10+
11+
include .coveragerc
12+
include tox.ini
13+
14+
global-exclude *.py[co] __pycache__

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)

README.rst

Lines changed: 0 additions & 63 deletions
This file was deleted.

flask_graphql/graphqlview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from flask import Response, request
44
from flask.views import View
5-
6-
from graphql.type.schema import GraphQLSchema
75
from graphql_server import (HttpQueryError, default_format_error,
86
encode_execution_results, json_encode,
97
load_json_body, run_http_query)
108

9+
from graphql.type.schema import GraphQLSchema
10+
1111
from .render_graphiql import render_graphiql
1212

1313

setup.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
from setuptools import setup, find_packages
22

3-
required_packages = [
4-
"graphql-core>=2.3,<3",
3+
install_requires = [
54
"flask>=0.7.0",
5+
"graphql-core>=2.3,<3",
66
"graphql-server-core>=1.1,<2",
77
]
88

9+
tests_requires = [
10+
'pytest>=2.7.2',
11+
'pytest-cov==2.8.1',
12+
'pytest-flask>=0.10.0',
13+
]
14+
15+
dev_requires = [
16+
'flake8==3.7.9',
17+
'isort<4.0.0',
18+
'check-manifest>=0.40,<1',
19+
] + tests_requires
20+
921
setup(
1022
name="Flask-GraphQL",
1123
version="2.0.1",
1224
description="Adds GraphQL support to your Flask application",
13-
long_description=open("README.rst").read(),
25+
long_description=open("README.md").read(),
26+
long_description_content_type="text/markdown",
1427
url="https://github.com/graphql-python/flask-graphql",
1528
download_url="https://github.com/graphql-python/flask-graphql/releases",
1629
author="Syrus Akbary",
@@ -23,8 +36,6 @@
2336
"Programming Language :: Python :: 2",
2437
"Programming Language :: Python :: 2.7",
2538
"Programming Language :: Python :: 3",
26-
"Programming Language :: Python :: 3.3",
27-
"Programming Language :: Python :: 3.4",
2839
"Programming Language :: Python :: 3.5",
2940
"Programming Language :: Python :: 3.6",
3041
"Programming Language :: Python :: 3.7",
@@ -33,8 +44,12 @@
3344
],
3445
keywords="api graphql protocol rest flask",
3546
packages=find_packages(exclude=["tests"]),
36-
install_requires=required_packages,
37-
tests_require=["pytest>=2.7.3"],
47+
install_requires=install_requires,
48+
tests_require=tests_requires,
49+
extras_require={
50+
'test': tests_requires,
51+
'dev': dev_requires,
52+
},
3853
include_package_data=True,
3954
zip_safe=False,
4055
platforms="any",

tests/test_graphiqlview.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,29 @@
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'
@@ -28,12 +41,14 @@ def test_graphiql_renders_pretty(client):
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")])
3751
def test_graphiql_custom_title(app, client):
38-
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
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)