|
12 | 12 | from marshmallow_jsonapi import fields
|
13 | 13 |
|
14 | 14 | from flask_rest_jsonapi import Api, ResourceList, ResourceDetail, ResourceRelationship, JsonApiException
|
15 |
| -from flask_rest_jsonapi.exceptions import RelationNotFound, InvalidSort |
| 15 | +from flask_rest_jsonapi.pagination import add_pagination_links |
| 16 | +from flask_rest_jsonapi.exceptions import RelationNotFound, InvalidSort, InvalidFilters |
16 | 17 | from flask_rest_jsonapi.querystring import QueryStringManager as QSManager
|
17 | 18 | from flask_rest_jsonapi.data_layers.alchemy import SqlalchemyDataLayer
|
18 | 19 | from flask_rest_jsonapi.data_layers.base import BaseDataLayer
|
| 20 | +from flask_rest_jsonapi.data_layers.filtering.alchemy import Node |
| 21 | +import flask_rest_jsonapi.decorators |
19 | 22 |
|
20 | 23 |
|
21 | 24 | @pytest.fixture(scope="module")
|
@@ -315,11 +318,61 @@ class get_object(object):
|
315 | 318 | })()
|
316 | 319 | })()
|
317 | 320 | })()
|
| 321 | + |
318 | 322 | def __init__(self, kwargs):
|
319 | 323 | pass
|
320 | 324 | return get_object
|
321 | 325 |
|
322 | 326 |
|
| 327 | +def test_add_pagination_links(): |
| 328 | + qs = {'page[number]': '15', 'page[size]': '10'} |
| 329 | + qsm = QSManager(qs, None) |
| 330 | + add_pagination_links(dict(), 1000, qsm, str()) |
| 331 | + |
| 332 | + |
| 333 | +def test_Node(person_model, person_schema, monkeypatch): |
| 334 | + from copy import deepcopy |
| 335 | + filt = { |
| 336 | + 'val': '0000', |
| 337 | + 'field': True, |
| 338 | + 'not': dict(), |
| 339 | + 'name': 'name', |
| 340 | + 'op': 'eq', |
| 341 | + 'strip': lambda: 's' |
| 342 | + } |
| 343 | + filt['not'] = deepcopy(filt) |
| 344 | + del filt['not']['not'] |
| 345 | + n = Node(person_model, |
| 346 | + filt, |
| 347 | + None, |
| 348 | + person_schema) |
| 349 | + with pytest.raises(TypeError): |
| 350 | + # print(n.val is None and n.field is None) |
| 351 | + # # n.column |
| 352 | + n.resolve() |
| 353 | + with pytest.raises(AttributeError): |
| 354 | + n.model = None |
| 355 | + n.column |
| 356 | + with pytest.raises(InvalidFilters): |
| 357 | + n.model = person_model |
| 358 | + n.filter_['op'] = '' |
| 359 | + n.operator |
| 360 | + with pytest.raises(InvalidFilters): |
| 361 | + n.related_model |
| 362 | + with pytest.raises(InvalidFilters): |
| 363 | + n.related_schema |
| 364 | + |
| 365 | + |
| 366 | +def test_check_method_requirements(monkeypatch): |
| 367 | + class Self(object): |
| 368 | + def __init__(self): |
| 369 | + pass |
| 370 | + request = type('request', (object,), dict(method=None)) |
| 371 | + monkeypatch.setattr(flask_rest_jsonapi.decorators, 'request', request) |
| 372 | + with pytest.raises(Exception): |
| 373 | + flask_rest_jsonapi.decorators.check_method_requirements(lambda: 1)(Self()) |
| 374 | + |
| 375 | + |
323 | 376 | # test good cases
|
324 | 377 | def test_get_list(client, register_routes, person, person_2):
|
325 | 378 | with client:
|
|
0 commit comments