Skip to content

Commit f6034ab

Browse files
authored
Merge pull request #132 from LearntEmail/rename_fields
Add tests for DjangoObjectType only/exclude_fields
2 parents 1139507 + 46048cd commit f6034ab

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

graphene_django/tests/test_types.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from graphene import Interface, ObjectType, Schema
44
from graphene.relay import Node
55

6-
from ..registry import reset_global_registry
6+
from .. import registry
77
from ..types import DjangoObjectType
88
from .models import Article as ArticleModel
99
from .models import Reporter as ReporterModel
1010

11-
reset_global_registry()
11+
registry.reset_global_registry()
1212

1313

1414
class Reporter(DjangoObjectType):
@@ -124,3 +124,42 @@ def test_schema_representation():
124124
}
125125
""".lstrip()
126126
assert str(schema) == expected
127+
128+
129+
def with_local_registry(func):
130+
def inner(*args, **kwargs):
131+
old = registry.get_global_registry()
132+
registry.reset_global_registry()
133+
try:
134+
retval = func(*args, **kwargs)
135+
except Exception as e:
136+
registry.registry = old
137+
raise e
138+
else:
139+
registry.registry = old
140+
return retval
141+
return inner
142+
143+
144+
@with_local_registry
145+
def test_django_objecttype_only_fields():
146+
class Reporter(DjangoObjectType):
147+
class Meta:
148+
model = ReporterModel
149+
only_fields = ('id', 'email', 'films')
150+
151+
152+
fields = list(Reporter._meta.fields.keys())
153+
assert fields == ['id', 'email', 'films']
154+
155+
156+
@with_local_registry
157+
def test_django_objecttype_exclude_fields():
158+
class Reporter(DjangoObjectType):
159+
class Meta:
160+
model = ReporterModel
161+
exclude_fields = ('email')
162+
163+
164+
fields = list(Reporter._meta.fields.keys())
165+
assert 'email' not in fields

0 commit comments

Comments
 (0)