|
19 | 19 | from flask_rest_jsonapi.data_layers.alchemy import SqlalchemyDataLayer |
20 | 20 | from flask_rest_jsonapi.data_layers.base import BaseDataLayer |
21 | 21 | from flask_rest_jsonapi.data_layers.filtering.alchemy import Node |
| 22 | +from flask_rest_jsonapi.decorators import check_headers, check_method_requirements, jsonapi_exception_formatter |
22 | 23 | import flask_rest_jsonapi.decorators |
23 | 24 | import flask_rest_jsonapi.resource |
24 | 25 | import flask_rest_jsonapi.schema |
@@ -983,6 +984,46 @@ def test_get_list_response(client, register_routes): |
983 | 984 | assert response.status_code == 200 |
984 | 985 |
|
985 | 986 |
|
| 987 | +class TestResourceArgs: |
| 988 | + def test_resource_args(self, app): |
| 989 | + class TestResource(ResourceDetail): |
| 990 | + """ |
| 991 | + This fake resource always renders a constructor parameter |
| 992 | + """ |
| 993 | + def __init__(self, *args, **kwargs): |
| 994 | + super().__init__() |
| 995 | + self.constant = args[0] |
| 996 | + |
| 997 | + def get(self): |
| 998 | + return self.constant |
| 999 | + api = Api(app=app) |
| 1000 | + api.route(TestResource, 'resource_args', '/resource_args', resource_args=['hello!']) |
| 1001 | + api.init_app() |
| 1002 | + with app.test_client() as client: |
| 1003 | + rv = client.get('/resource_args') |
| 1004 | + assert rv.json == 'hello!' |
| 1005 | + |
| 1006 | + def test_resource_kwargs(self, app): |
| 1007 | + class TestResource(ResourceDetail): |
| 1008 | + """ |
| 1009 | + This fake resource always renders a constructor parameter |
| 1010 | + """ |
| 1011 | + def __init__(self, *args, **kwargs): |
| 1012 | + super().__init__() |
| 1013 | + self.constant = kwargs.get('constant') |
| 1014 | + |
| 1015 | + def get(self): |
| 1016 | + return self.constant |
| 1017 | + api = Api(app=app) |
| 1018 | + api.route(TestResource, 'resource_kwargs', '/resource_kwargs', resource_kwargs={ |
| 1019 | + 'constant': 'hello!' |
| 1020 | + }) |
| 1021 | + api.init_app() |
| 1022 | + with app.test_client() as client: |
| 1023 | + rv = client.get('/resource_kwargs') |
| 1024 | + assert rv.json == 'hello!' |
| 1025 | + |
| 1026 | + |
986 | 1027 | # test various Accept headers |
987 | 1028 | def test_single_accept_header(client, register_routes): |
988 | 1029 | with client: |
|
0 commit comments