Skip to content

Contributing docs and refactor tox config #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[report]
omit = */tests/*
34 changes: 15 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
language: python
sudo: false
matrix:
include:
- python: pypy
env: TOX_ENV=pypy
- python: '2.7'
env: TOX_ENV=py27
- python: '3.5'
env: TOX_ENV=py35
- python: '3.6'
env: TOX_ENV=py36
- python: '3.6'
env: TOX_ENV=import-order,flake8
cache:
directories:
- $HOME/.cache/pip
- $TRAVIS_BUILD_DIR/.tox
python:
- 2.7
- 3.5
- 3.6
- 3.7
# - 3.8
cache: pip

install:
- pip install tox coveralls
- pip install tox-travis

script:
- tox -e $TOX_ENV -- --cov=flask_graphql
- tox

after_success:
- coveralls
- pip install coveralls
- coveralls

deploy:
provider: pypi
user: syrusakbary
Expand Down
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributing

Thanks for helping to make flask-graphql awesome!

We welcome all kinds of contributions:

- Bug fixes
- Documentation improvements
- New features
- Refactoring & tidying


## Getting started

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.


## Project setup

After cloning this repo, ensure dependencies are installed by running:

```sh
make dev-setup
```

## Running tests

After developing, the full test suite can be evaluated by running:

```sh
make tests
```

## Development on Conda

In order to run `tox` command on conda, you must create a new env (e.g. `flask-grapqhl-dev`) with the following command:

```sh
conda create -n flask-grapqhl-dev python=3.8
```

Then activate the environment with `conda activate flask-grapqhl-dev` and install [tox-conda](https://github.com/tox-dev/tox-conda):

```sh
conda install -c conda-forge tox-conda
```

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:

11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
include LICENSE
include README.md
include CONTRIBUTING.md

recursive-include flask_graphql/static *
recursive-include flask_graphql/templates *
recursive-include tests *.py

include Makefile

include .coveragerc
include tox.ini

global-exclude *.py[co] __pycache__
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dev-setup:
python pip install -e ".[test]"

tests:
py.test tests --cov=flask_graphql -vv
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ class UserRootValue(GraphQLView):
return request.user

```

## Contributing
See [CONTRIBUTING.md](contributing.md)
63 changes: 0 additions & 63 deletions README.rst

This file was deleted.

4 changes: 2 additions & 2 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from flask import Response, request
from flask.views import View

from graphql.type.schema import GraphQLSchema
from graphql_server import (HttpQueryError, default_format_error,
encode_execution_results, json_encode,
load_json_body, run_http_query)

from graphql.type.schema import GraphQLSchema

from .render_graphiql import render_graphiql


Expand Down
29 changes: 22 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
from setuptools import setup, find_packages

required_packages = [
"graphql-core>=2.3,<3",
install_requires = [
"flask>=0.7.0",
"graphql-core>=2.3,<3",
"graphql-server-core>=1.1,<2",
]

tests_requires = [
'pytest>=2.7.2',
'pytest-cov==2.8.1',
'pytest-flask>=0.10.0',
]

dev_requires = [
'flake8==3.7.9',
'isort<4.0.0',
'check-manifest>=0.40,<1',
] + tests_requires

setup(
name="Flask-GraphQL",
version="2.0.1",
description="Adds GraphQL support to your Flask application",
long_description=open("README.rst").read(),
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/graphql-python/flask-graphql",
download_url="https://github.com/graphql-python/flask-graphql/releases",
author="Syrus Akbary",
Expand All @@ -23,8 +36,6 @@
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
Expand All @@ -33,8 +44,12 @@
],
keywords="api graphql protocol rest flask",
packages=find_packages(exclude=["tests"]),
install_requires=required_packages,
tests_require=["pytest>=2.7.3"],
install_requires=install_requires,
tests_require=tests_requires,
extras_require={
'test': tests_requires,
'dev': dev_requires,
},
include_package_data=True,
zip_safe=False,
platforms="any",
Expand Down
31 changes: 23 additions & 8 deletions tests/test_graphiqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@

@pytest.fixture
def app():
return create_app(graphiql=True)
# import app factory pattern
app = create_app(graphiql=True)

# pushes an application context manually
ctx = app.app_context()
ctx.push()
return app

def test_graphiql_is_enabled(client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})

@pytest.fixture
def client(app):
return app.test_client()


def test_graphiql_is_enabled(app, client):
with app.test_request_context():
response = client.get(url_for('graphql', externals=False), headers={'Accept': 'text/html'})
assert response.status_code == 200


def test_graphiql_renders_pretty(client):
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
def test_graphiql_renders_pretty(app, client):
with app.test_request_context():
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
assert response.status_code == 200
pretty_response = (
'{\n'
Expand All @@ -28,12 +41,14 @@ def test_graphiql_renders_pretty(client):
assert pretty_response in response.data.decode('utf-8')


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


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