From 66831e2ecf0e40865c64a00da5c26556ad95b855 Mon Sep 17 00:00:00 2001 From: Tobias Karlsson Date: Tue, 8 Jan 2019 12:07:10 +0100 Subject: [PATCH 1/3] wrap inner function so we can pass down the args signature, fixes #6 --- sanicargs/__init__.py | 3 ++- tests/test_sanicargs.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sanicargs/__init__.py b/sanicargs/__init__.py index 925ec92..6f6d534 100644 --- a/sanicargs/__init__.py +++ b/sanicargs/__init__.py @@ -1,5 +1,6 @@ import inspect import datetime +from functools import wraps from sanic import response from sanic.exceptions import abort @@ -62,8 +63,8 @@ async def generate_csv(request, query: str, businessunitid: str): for name, p in notations.parameters.items() ] request_arg_name = inspect.getfullargspec(func)[0][0] - + @wraps(func) async def inner(request, *old_args, **route_parameters): kwargs = {} name = None diff --git a/tests/test_sanicargs.py b/tests/test_sanicargs.py index 8090287..0cc2e64 100644 --- a/tests/test_sanicargs.py +++ b/tests/test_sanicargs.py @@ -9,6 +9,17 @@ import datetime +from functools import wraps +import inspect + +def has_test_arg(func): + signature = inspect.signature(func) + assert signature.parameters['test'] + @wraps(func) + async def decorated(request, *args, **kwargs): + return await func(request, *args, **kwargs) + return decorated + @pytest.yield_fixture def app(): @@ -71,6 +82,12 @@ async def test_optional(request, test: str = 'helloworld'): async def test_path_params(request, path_param: int, test: str, test_2: int=35): return response.json({'path_param': path_param, 'test': test, 'test_2': test_2}) + @app.route("/test_arg", methods=['GET']) + @has_test_arg + @parse_query_args + async def test_args(request, test: int): + return response.json({'test': test}) + yield app @pytest.fixture @@ -200,3 +217,9 @@ async def test_with_path_params(test_cli): assert resp.status == 200 resp_json = await resp.json() assert resp_json == {'path_param': 123, 'test': 'hello', 'test_2': 35} + +async def test_args_success(test_cli): + resp = await test_cli.get('/test_arg?test=10') + assert resp.status == 200 + resp_json = await resp.json() + assert resp_json == {'test': 10} From 0f4f7ed834c6587767a8885cc4882cef073b3423 Mon Sep 17 00:00:00 2001 From: Tobias Karlsson Date: Tue, 8 Jan 2019 12:15:17 +0100 Subject: [PATCH 2/3] Go away prospector --- .travis.yml | 1 - setup.py | 1 - 2 files changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 592f08a..819bb91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ install: - pip install pypandoc - pip install .[test] script: -- prospector -M - pytest branches: only: master diff --git a/setup.py b/setup.py index 6b54d0f..b7c2348 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,6 @@ test_requirements = [ 'pytest==3.2.0', - 'prospector==0.12.7', 'pytest-sanic==0.1.6' ] From ca9bcc0a8315020604913f70b9965dd306ce448e Mon Sep 17 00:00:00 2001 From: Tobias Karlsson Date: Tue, 8 Jan 2019 13:04:18 +0100 Subject: [PATCH 3/3] Release v1.3.0 --- HISTORY.rst | 7 ++++++- sanicargs/__version__.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 9c28005..018cde1 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -20,4 +20,9 @@ History 1.2.0 (2018-03-01) ------------------ -* added support for boolean parameters \ No newline at end of file +* added support for boolean parameters + +1.3.0 (2019-01-08) +------------------ + +* @wraps the inner function to keep the args signature \ No newline at end of file diff --git a/sanicargs/__version__.py b/sanicargs/__version__.py index e916218..f94ba41 100644 --- a/sanicargs/__version__.py +++ b/sanicargs/__version__.py @@ -1 +1 @@ -__version__ = '1.2.0' \ No newline at end of file +__version__ = '1.3.0' \ No newline at end of file