Skip to content

Commit 7b75f5a

Browse files
authored
Merge pull request #18 from jamesalbert/master
even more tests
2 parents 9cba161 + a3af506 commit 7b75f5a

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

tests/test_sqlalchemy_data_layer.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
from marshmallow_jsonapi import fields
1313

1414
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
1617
from flask_rest_jsonapi.querystring import QueryStringManager as QSManager
1718
from flask_rest_jsonapi.data_layers.alchemy import SqlalchemyDataLayer
1819
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
1922

2023

2124
@pytest.fixture(scope="module")
@@ -315,11 +318,61 @@ class get_object(object):
315318
})()
316319
})()
317320
})()
321+
318322
def __init__(self, kwargs):
319323
pass
320324
return get_object
321325

322326

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+
323376
# test good cases
324377
def test_get_list(client, register_routes, person, person_2):
325378
with client:

0 commit comments

Comments
 (0)