Skip to content

Commit 1a728e4

Browse files
committed
Fixed tests
1 parent b8f9fec commit 1a728e4

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

graphene_django/converter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ def dynamic_type():
114114
if not _type:
115115
return
116116

117-
return Field(_type, required=not field.null)
117+
# We do this for a bug in Django 1.8, where null attr
118+
# is not available in the OneToOneRel instance
119+
null = getattr(field, 'null', True)
120+
return Field(_type, required=not null)
118121

119122
return Dynamic(dynamic_type)
120123

@@ -149,7 +152,7 @@ def dynamic_type():
149152
return
150153

151154
if isinstance(field.field, models.OneToOneField):
152-
return Field(_type, required=not field.field.null)
155+
return Field(_type)
153156

154157
if is_node(_type):
155158
return get_connection_field(_type)

graphene_django/tests/test_converter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@
2020

2121

2222
def assert_conversion(django_field, graphene_field, *args, **kwargs):
23-
field = django_field(help_text='Custom Help Text', *args, **kwargs)
23+
field = django_field(help_text='Custom Help Text', null=True, *args, **kwargs)
2424
graphene_type = convert_django_field(field)
2525
assert isinstance(graphene_type, graphene_field)
2626
field = graphene_type.Field()
2727
assert field.description == 'Custom Help Text'
28+
nonnull_field = django_field(null=False, *args, **kwargs)
29+
if not nonnull_field.null:
30+
nonnull_graphene_type = convert_django_field(nonnull_field)
31+
nonnull_field = nonnull_graphene_type.Field()
32+
assert isinstance(nonnull_field.type, graphene.NonNull)
33+
return nonnull_field
2834
return field
2935

3036

@@ -226,8 +232,7 @@ class Meta:
226232
assert isinstance(graphene_field, graphene.Dynamic)
227233
dynamic_field = graphene_field.get_type()
228234
assert isinstance(dynamic_field, graphene.Field)
229-
assert isinstance(dynamic_field.type, graphene.NonNull)
230-
assert dynamic_field.of_type.type == A
235+
assert dynamic_field.type == A
231236

232237

233238
@pytest.mark.skipif(ArrayField is MissingType,

0 commit comments

Comments
 (0)