Skip to content
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ install:
- pip install pypandoc
- pip install .[test]
script:
- prospector -M
- pytest
branches:
only: master
Expand Down
7 changes: 6 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ History
1.2.0 (2018-03-01)
------------------

* added support for boolean parameters
* added support for boolean parameters

1.3.0 (2019-01-08)
------------------

* @wraps the inner function to keep the args signature
3 changes: 2 additions & 1 deletion sanicargs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import datetime
from functools import wraps

from sanic import response
from sanic.exceptions import abort
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sanicargs/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.0'
__version__ = '1.3.0'
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

test_requirements = [
'pytest==3.2.0',
'prospector==0.12.7',
'pytest-sanic==0.1.6'
]

Expand Down
23 changes: 23 additions & 0 deletions tests/test_sanicargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}