forked from graphql-python/graphene-sqlalchemy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_fields.py
40 lines (26 loc) · 1012 Bytes
/
test_fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pytest
from graphene.relay import Connection
from ..fields import SQLAlchemyConnectionField
from ..types import SQLAlchemyObjectType
from ..utils import get_sort_argument_for_model
from .models import Editor
from .models import Pet as PetModel
class Pet(SQLAlchemyObjectType):
class Meta:
model = PetModel
class PetConn(Connection):
class Meta:
node = Pet
def test_sort_added_by_default():
arg = SQLAlchemyConnectionField(PetConn)
assert "sort" in arg.args
assert arg.args["sort"] == get_sort_argument_for_model(PetModel)
def test_sort_can_be_removed():
arg = SQLAlchemyConnectionField(PetConn, sort=None)
assert "sort" not in arg.args
def test_custom_sort():
arg = SQLAlchemyConnectionField(PetConn, sort=get_sort_argument_for_model(Editor))
assert arg.args["sort"] == get_sort_argument_for_model(Editor)
def test_init_raises():
with pytest.raises(Exception, match="Cannot create sort"):
SQLAlchemyConnectionField(Connection)