|
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
|
@@ -1025,6 +1026,46 @@ def test_get_list_response(client, register_routes):
|
1025 | 1026 | assert response.status_code == 200, response.json['errors']
|
1026 | 1027 |
|
1027 | 1028 |
|
| 1029 | +class TestResourceArgs: |
| 1030 | + def test_resource_args(self, app): |
| 1031 | + class TestResource(ResourceDetail): |
| 1032 | + """ |
| 1033 | + This fake resource always renders a constructor parameter |
| 1034 | + """ |
| 1035 | + def __init__(self, *args, **kwargs): |
| 1036 | + super(TestResource, self).__init__() |
| 1037 | + self.constant = args[0] |
| 1038 | + |
| 1039 | + def get(self): |
| 1040 | + return self.constant |
| 1041 | + api = Api(app=app) |
| 1042 | + api.route(TestResource, 'resource_args', '/resource_args', resource_args=['hello!']) |
| 1043 | + api.init_app() |
| 1044 | + with app.test_client() as client: |
| 1045 | + rv = client.get('/resource_args') |
| 1046 | + assert rv.json == 'hello!' |
| 1047 | + |
| 1048 | + def test_resource_kwargs(self, app): |
| 1049 | + class TestResource(ResourceDetail): |
| 1050 | + """ |
| 1051 | + This fake resource always renders a constructor parameter |
| 1052 | + """ |
| 1053 | + def __init__(self, *args, **kwargs): |
| 1054 | + super(TestResource, self).__init__() |
| 1055 | + self.constant = kwargs.get('constant') |
| 1056 | + |
| 1057 | + def get(self): |
| 1058 | + return self.constant |
| 1059 | + api = Api(app=app) |
| 1060 | + api.route(TestResource, 'resource_kwargs', '/resource_kwargs', resource_kwargs={ |
| 1061 | + 'constant': 'hello!' |
| 1062 | + }) |
| 1063 | + api.init_app() |
| 1064 | + with app.test_client() as client: |
| 1065 | + rv = client.get('/resource_kwargs') |
| 1066 | + assert rv.json == 'hello!' |
| 1067 | + |
| 1068 | + |
1028 | 1069 | # test various Accept headers
|
1029 | 1070 | def test_single_accept_header(client, register_routes):
|
1030 | 1071 | with client:
|
|
0 commit comments