|
3 | 3 | from graphene import Interface, ObjectType, Schema
|
4 | 4 | from graphene.relay import Node
|
5 | 5 |
|
6 |
| -from ..registry import reset_global_registry |
| 6 | +from .. import registry |
7 | 7 | from ..types import DjangoObjectType
|
8 | 8 | from .models import Article as ArticleModel
|
9 | 9 | from .models import Reporter as ReporterModel
|
10 | 10 |
|
11 |
| -reset_global_registry() |
| 11 | +registry.reset_global_registry() |
12 | 12 |
|
13 | 13 |
|
14 | 14 | class Reporter(DjangoObjectType):
|
@@ -124,3 +124,42 @@ def test_schema_representation():
|
124 | 124 | }
|
125 | 125 | """.lstrip()
|
126 | 126 | 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