|
| 1 | +from pytest import raises |
1 | 2 | from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType
|
2 | 3 | from mock import patch
|
3 | 4 |
|
@@ -33,10 +34,11 @@ def test_django_interface():
|
33 | 34 | assert DjangoNode._meta.is_interface is True
|
34 | 35 |
|
35 | 36 |
|
36 |
| -@patch('graphene.contrib.django.tests.models.Article.objects.filter') |
37 |
| -def test_django_get_node(objects): |
38 |
| - Human.get_node(1) |
39 |
| - objects.assert_called_with(id=1) |
| 37 | +@patch('graphene.contrib.django.tests.models.Article.objects.get', return_value=Article(id=1)) |
| 38 | +def test_django_get_node(get): |
| 39 | + human = Human.get_node(1) |
| 40 | + get.assert_called_with(id=1) |
| 41 | + assert human.id == 1 |
40 | 42 |
|
41 | 43 |
|
42 | 44 | def test_pseudo_interface_registered():
|
@@ -67,10 +69,26 @@ def test_node_replacedfield():
|
67 | 69 |
|
68 | 70 |
|
69 | 71 | def test_interface_resolve_type():
|
70 |
| - resolve_type = Character.resolve_type(schema, Human(object())) |
| 72 | + resolve_type = Character.resolve_type(schema, Human()) |
71 | 73 | assert isinstance(resolve_type, GraphQLObjectType)
|
72 | 74 |
|
73 | 75 |
|
| 76 | +def test_interface_objecttype_init_none(): |
| 77 | + h = Human() |
| 78 | + assert h._root is None |
| 79 | + |
| 80 | + |
| 81 | +def test_interface_objecttype_init_good(): |
| 82 | + instance = Article() |
| 83 | + h = Human(instance) |
| 84 | + assert h._root == instance |
| 85 | + |
| 86 | + |
| 87 | +def test_interface_objecttype_init_unexpected(): |
| 88 | + with raises(AssertionError) as excinfo: |
| 89 | + Human(object()) |
| 90 | + assert str(excinfo.value) == "Human received a non-compatible instance (object) when expecting Article" |
| 91 | + |
74 | 92 | def test_object_type():
|
75 | 93 | object_type = schema.T(Human)
|
76 | 94 | Human._meta.fields_map
|
|
0 commit comments