From a58a4ed77d4783b48cb2f7d6753ca66f4b8fd951 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 9 Aug 2021 14:06:37 +0200 Subject: [PATCH 1/3] Pin some dependant libs --- setup.py | 6 +++--- tests/sanic/app.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 3758a20..b56acdd 100644 --- a/setup.py +++ b/setup.py @@ -23,11 +23,11 @@ ] + tests_requires install_flask_requires = [ - "flask>=0.7.0", + "flask>=0.7.0<1", ] install_sanic_requires = [ - "sanic>=20.3.0", + "sanic>=20.3.0,<21", ] install_webob_requires = [ @@ -39,7 +39,7 @@ ] install_quart_requires = [ - "quart>=0.6.15" + "quart>=0.6.15,<1" ] install_all_requires = \ diff --git a/tests/sanic/app.py b/tests/sanic/app.py index f5a74cf..6966b1e 100644 --- a/tests/sanic/app.py +++ b/tests/sanic/app.py @@ -8,6 +8,9 @@ from .schema import Schema +Sanic.test_mode = True + + def create_app(path="/graphql", **kwargs): app = Sanic(__name__) app.debug = True From b5ac5330f01dc7ce4fc12817045d7407c0feb139 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 9 Aug 2021 14:06:49 +0200 Subject: [PATCH 2/3] Fix test --- graphql_server/__init__.py | 4 ++++ tests/test_query.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/graphql_server/__init__.py b/graphql_server/__init__.py index 8942332..239a1d4 100644 --- a/graphql_server/__init__.py +++ b/graphql_server/__init__.py @@ -255,6 +255,10 @@ def get_response( if not params.query: raise HttpQueryError(400, "Must provide query string.") + # Sanity check query + if not isinstance(params.query, str): + raise HttpQueryError(400, "Unexpected query type.") + schema_validation_errors = validate_schema(schema) if schema_validation_errors: return ExecutionResult(data=None, errors=schema_validation_errors) diff --git a/tests/test_query.py b/tests/test_query.py index 70f49ac..932a97e 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -495,8 +495,12 @@ def test_handles_errors_caused_by_a_lack_of_query(): def test_handles_errors_caused_by_invalid_query_type(): - results, params = run_http_query(schema, "get", dict(query=42)) - assert results == [(None, [{"message": "Must provide Source. Received: 42."}])] + with raises(HttpQueryError) as exc_info: + results, params = run_http_query(schema, "get", dict(query=42)) + + assert exc_info.value == HttpQueryError( + 400, "Unexpected query type." + ) def test_handles_batch_correctly_if_is_disabled(): From 2b491c425285ff631712dbbfa88899fb94b10053 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Mon, 9 Aug 2021 14:18:14 +0200 Subject: [PATCH 3/3] Run formatter --- setup.py | 24 ++++++++++-------------- tests/test_query.py | 4 +--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/setup.py b/setup.py index b56acdd..e3f769e 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,7 @@ from re import search from setuptools import setup, find_packages -install_requires = [ - "graphql-core>=3.1.0,<4", - "typing-extensions>=3.7.4,<4" -] +install_requires = ["graphql-core>=3.1.0,<4", "typing-extensions>=3.7.4,<4"] tests_requires = [ "pytest>=5.4,<5.5", @@ -38,17 +35,16 @@ "aiohttp>=3.5.0,<4", ] -install_quart_requires = [ - "quart>=0.6.15,<1" -] +install_quart_requires = ["quart>=0.6.15,<1"] -install_all_requires = \ - install_requires + \ - install_flask_requires + \ - install_sanic_requires + \ - install_webob_requires + \ - install_aiohttp_requires + \ - install_quart_requires +install_all_requires = ( + install_requires + + install_flask_requires + + install_sanic_requires + + install_webob_requires + + install_aiohttp_requires + + install_quart_requires +) with open("graphql_server/version.py") as version_file: version = search('version = "(.*)"', version_file.read()).group(1) diff --git a/tests/test_query.py b/tests/test_query.py index 932a97e..c4f6a43 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -498,9 +498,7 @@ def test_handles_errors_caused_by_invalid_query_type(): with raises(HttpQueryError) as exc_info: results, params = run_http_query(schema, "get", dict(query=42)) - assert exc_info.value == HttpQueryError( - 400, "Unexpected query type." - ) + assert exc_info.value == HttpQueryError(400, "Unexpected query type.") def test_handles_batch_correctly_if_is_disabled():