|
9 | 9 |
|
10 | 10 | import datetime |
11 | 11 |
|
| 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 | + |
12 | 23 |
|
13 | 24 | @pytest.yield_fixture |
14 | 25 | def app(): |
@@ -71,6 +82,12 @@ async def test_optional(request, test: str = 'helloworld'): |
71 | 82 | async def test_path_params(request, path_param: int, test: str, test_2: int=35): |
72 | 83 | return response.json({'path_param': path_param, 'test': test, 'test_2': test_2}) |
73 | 84 |
|
| 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 | + |
74 | 91 | yield app |
75 | 92 |
|
76 | 93 | @pytest.fixture |
@@ -200,3 +217,9 @@ async def test_with_path_params(test_cli): |
200 | 217 | assert resp.status == 200 |
201 | 218 | resp_json = await resp.json() |
202 | 219 | 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