mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Improved tests
This commit is contained in:
parent
83589a21b8
commit
34d6d07fc3
|
@ -1,19 +0,0 @@
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
from .models import Article, Reporter
|
|
||||||
|
|
||||||
r = Reporter(first_name='John', last_name='Smith', email='john@example.com')
|
|
||||||
r.save()
|
|
||||||
|
|
||||||
r2 = Reporter(first_name='Paul', last_name='Jones', email='paul@example.com')
|
|
||||||
r2.save()
|
|
||||||
|
|
||||||
a = Article(id=None, headline="This is a test",
|
|
||||||
pub_date=date(2005, 7, 27), reporter=r)
|
|
||||||
a.save()
|
|
||||||
|
|
||||||
new_article = r.articles.create(
|
|
||||||
headline="John's second story", pub_date=date(2005, 7, 29))
|
|
||||||
|
|
||||||
new_article2 = Article(headline="Paul's story", pub_date=date(2006, 1, 17))
|
|
||||||
r.articles.add(new_article2)
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from mock import patch
|
||||||
|
|
||||||
from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType
|
from graphql.core.type import GraphQLInterfaceType, GraphQLObjectType
|
||||||
|
|
||||||
from graphene import Schema
|
from graphene import Schema
|
||||||
|
@ -24,9 +26,6 @@ class Human(DjangoNode):
|
||||||
|
|
||||||
pub_date = Int()
|
pub_date = Int()
|
||||||
|
|
||||||
def get_node(self, id):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Article
|
model = Article
|
||||||
|
|
||||||
|
@ -35,6 +34,12 @@ def test_django_interface():
|
||||||
assert DjangoNode._meta.is_interface is True
|
assert DjangoNode._meta.is_interface is True
|
||||||
|
|
||||||
|
|
||||||
|
@patch('graphene.contrib.django.tests.models.Article.objects.filter')
|
||||||
|
def test_django_get_node(objects):
|
||||||
|
Human.get_node(1)
|
||||||
|
objects.assert_called_with(id=1)
|
||||||
|
|
||||||
|
|
||||||
def test_pseudo_interface_registered():
|
def test_pseudo_interface_registered():
|
||||||
object_type = schema.T(Character)
|
object_type = schema.T(Character)
|
||||||
assert Character._meta.is_interface is True
|
assert Character._meta.is_interface is True
|
||||||
|
|
|
@ -51,10 +51,6 @@ class Field(OrderedType):
|
||||||
def resolver(self):
|
def resolver(self):
|
||||||
return self.resolver_fn or self.get_resolver_fn()
|
return self.resolver_fn or self.get_resolver_fn()
|
||||||
|
|
||||||
@resolver.setter
|
|
||||||
def resolver(self, value):
|
|
||||||
self.resolver_fn = value
|
|
||||||
|
|
||||||
def get_resolver_fn(self):
|
def get_resolver_fn(self):
|
||||||
resolve_fn_name = 'resolve_%s' % self.attname
|
resolve_fn_name = 'resolve_%s' % self.attname
|
||||||
if hasattr(self.object_type, resolve_fn_name):
|
if hasattr(self.object_type, resolve_fn_name):
|
||||||
|
|
|
@ -66,6 +66,13 @@ def test_field_self():
|
||||||
assert schema.T(field).type == schema.T(MyObjectType)
|
assert schema.T(field).type == schema.T(MyObjectType)
|
||||||
|
|
||||||
|
|
||||||
|
def test_field_eq():
|
||||||
|
field = Field('self', name='my_customName')
|
||||||
|
field2 = Field('self', name='my_customName')
|
||||||
|
assert field == field
|
||||||
|
assert field2 != field
|
||||||
|
|
||||||
|
|
||||||
def test_field_mounted():
|
def test_field_mounted():
|
||||||
field = Field(List('MyObjectType'), name='my_customName')
|
field = Field(List('MyObjectType'), name='my_customName')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user