-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_objecttype.py
49 lines (35 loc) · 1.12 KB
/
test_objecttype.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
41
42
43
44
45
46
47
48
49
import typing as T
import pytest
from pydantic import BaseModel
from graphene_pydantic.objecttype import PydanticObjectType
def test_object_type_onlyfields():
class Foo(BaseModel):
name: str
size: int
color: T.Tuple[int, int, int, int]
class GraphFoo(PydanticObjectType):
class Meta:
model = Foo
only_fields = ("name",)
assert list(GraphFoo._meta.fields.keys()) == ["name"]
def test_object_type_excludefields():
class Foo(BaseModel):
name: str
size: int
color: T.Tuple[int, int, int, int]
class GraphFoo(PydanticObjectType):
class Meta:
model = Foo
exclude_fields = ("size",)
assert list(GraphFoo._meta.fields.keys()) == ["name", "color"]
def test_object_type_onlyandexclude():
class Foo(BaseModel):
name: str
size: int
color: T.Tuple[int, int, int, int]
with pytest.raises(ValueError):
class GraphFoo(PydanticObjectType):
class Meta:
model = Foo
only_fields = ("name",)
exclude_fields = ("size",)