1
-
1
+ from collections import OrderedDict
2
2
from graphene import Field , Int , Interface , ObjectType
3
3
from graphene .relay import Node , is_node
4
4
import six
@@ -121,30 +121,34 @@ def test_custom_objecttype_registered():
121
121
# Test Custom SQLAlchemyObjectType with Custom Options
122
122
class CustomOptions (SQLAlchemyObjectTypeOptions ):
123
123
custom_option = None
124
+ custom_fields = None
124
125
125
126
126
127
class SQLAlchemyObjectTypeWithCustomOptions (SQLAlchemyObjectType ):
127
128
class Meta :
128
129
abstract = True
129
130
130
131
@classmethod
131
- def __init_subclass_with_meta__ (cls , custom_option = None , ** options ):
132
+ def __init_subclass_with_meta__ (cls , custom_option = None , custom_fields = None , ** options ):
132
133
_meta = CustomOptions (cls )
133
134
_meta .custom_option = custom_option
135
+ _meta .fields = custom_fields
134
136
super (SQLAlchemyObjectTypeWithCustomOptions , cls ).__init_subclass_with_meta__ (_meta = _meta , ** options )
135
137
136
138
137
139
class ReporterWithCustomOptions (SQLAlchemyObjectTypeWithCustomOptions ):
138
140
class Meta :
139
141
model = Reporter
140
142
custom_option = 'custom_option'
143
+ custom_fields = OrderedDict ([('custom_field' , Field (Int ()))])
141
144
142
145
143
146
def test_objecttype_with_custom_options ():
144
147
assert issubclass (ReporterWithCustomOptions , ObjectType )
145
148
assert ReporterWithCustomOptions ._meta .model == Reporter
146
149
assert list (
147
150
ReporterWithCustomOptions ._meta .fields .keys ()) == [
151
+ 'custom_field' ,
148
152
'id' ,
149
153
'first_name' ,
150
154
'last_name' ,
@@ -153,28 +157,4 @@ def test_objecttype_with_custom_options():
153
157
'articles' ,
154
158
'favorite_article' ]
155
159
assert ReporterWithCustomOptions ._meta .custom_option == 'custom_option'
156
-
157
-
158
- class ReporterWithCustomOptionsAndField (SQLAlchemyObjectTypeWithCustomOptions ):
159
- class Meta :
160
- model = Reporter
161
- custom_option = 'custom_option'
162
-
163
- custom_field = Field (Int ())
164
-
165
-
166
- def test_objecttype_with_custom_options_and_field ():
167
- assert issubclass (ReporterWithCustomOptions , ObjectType )
168
- assert ReporterWithCustomOptions ._meta .model == Reporter
169
- assert list (
170
- ReporterWithCustomOptionsAndField ._meta .fields .keys ()) == [
171
- 'id' ,
172
- 'first_name' ,
173
- 'last_name' ,
174
- 'email' ,
175
- 'pets' ,
176
- 'articles' ,
177
- 'favorite_article' ,
178
- 'custom_field' ]
179
- assert ReporterWithCustomOptionsAndField ._meta .custom_option == 'custom_option'
180
- assert isinstance (ReporterWithCustomOptionsAndField ._meta .fields ['custom_field' ].type , Int )
160
+ assert isinstance (ReporterWithCustomOptions ._meta .fields ['custom_field' ].type , Int )
0 commit comments