Skip to content

Commit ddd1e6f

Browse files
authored
Merge pull request #7 from trustpilot/fix-issues-in-reviewsearchapi-master-related-to-sanicargs-not-loving-trustpilotauth
Fix issues in reviewsearchapi master related to sanicargs not loving trustpilotauth
2 parents 1c27e84 + ca9bcc0 commit ddd1e6f

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ install:
99
- pip install pypandoc
1010
- pip install .[test]
1111
script:
12-
- prospector -M
1312
- pytest
1413
branches:
1514
only: master

HISTORY.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ History
2020
1.2.0 (2018-03-01)
2121
------------------
2222

23-
* added support for boolean parameters
23+
* added support for boolean parameters
24+
25+
1.3.0 (2019-01-08)
26+
------------------
27+
28+
* @wraps the inner function to keep the args signature

sanicargs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import datetime
3+
from functools import wraps
34

45
from sanic import response
56
from sanic.exceptions import abort
@@ -62,8 +63,8 @@ async def generate_csv(request, query: str, businessunitid: str):
6263
for name, p in notations.parameters.items()
6364
]
6465
request_arg_name = inspect.getfullargspec(func)[0][0]
65-
6666

67+
@wraps(func)
6768
async def inner(request, *old_args, **route_parameters):
6869
kwargs = {}
6970
name = None

sanicargs/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.0'
1+
__version__ = '1.3.0'

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
test_requirements = [
2424
'pytest==3.2.0',
25-
'prospector==0.12.7',
2625
'pytest-sanic==0.1.6'
2726
]
2827

tests/test_sanicargs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
import datetime
1111

12+
from functools import wraps
13+
import inspect
14+
15+
def has_test_arg(func):
16+
signature = inspect.signature(func)
17+
assert signature.parameters['test']
18+
@wraps(func)
19+
async def decorated(request, *args, **kwargs):
20+
return await func(request, *args, **kwargs)
21+
return decorated
22+
1223

1324
@pytest.yield_fixture
1425
def app():
@@ -71,6 +82,12 @@ async def test_optional(request, test: str = 'helloworld'):
7182
async def test_path_params(request, path_param: int, test: str, test_2: int=35):
7283
return response.json({'path_param': path_param, 'test': test, 'test_2': test_2})
7384

85+
@app.route("/test_arg", methods=['GET'])
86+
@has_test_arg
87+
@parse_query_args
88+
async def test_args(request, test: int):
89+
return response.json({'test': test})
90+
7491
yield app
7592

7693
@pytest.fixture
@@ -200,3 +217,9 @@ async def test_with_path_params(test_cli):
200217
assert resp.status == 200
201218
resp_json = await resp.json()
202219
assert resp_json == {'path_param': 123, 'test': 'hello', 'test_2': 35}
220+
221+
async def test_args_success(test_cli):
222+
resp = await test_cli.get('/test_arg?test=10')
223+
assert resp.status == 200
224+
resp_json = await resp.json()
225+
assert resp_json == {'test': 10}

0 commit comments

Comments
 (0)