Improved testing. Added strucutre serialization. Remove unused code

This commit is contained in:
Syrus Akbary 2016-08-12 18:13:47 -07:00
parent 1c24e1b954
commit e408541c7b
3 changed files with 27 additions and 36 deletions

View File

@ -2,44 +2,10 @@ import inspect
from functools import partial from functools import partial
from collections import OrderedDict from collections import OrderedDict
# from graphql.type import (GraphQLField, GraphQLInputObjectField)
# from graphql.utils.assert_valid_name import assert_valid_name
from ..utils.orderedtype import OrderedType from ..utils.orderedtype import OrderedType
from .structures import NonNull from .structures import NonNull
# from ..utils.str_converters import to_camel_case
# from .argument import to_arguments
# class AbstractField(object):
# @property
# def name(self):
# return self._name or self.attname and to_camel_case(self.attname)
# @name.setter
# def name(self, name):
# if name is not None:
# assert_valid_name(name)
# self._name = name
# @property
# def type(self):
# from ..utils.get_graphql_type import get_graphql_type
# from .structures import NonNull
# if inspect.isfunction(self._type):
# _type = self._type()
# else:
# _type = self._type
# if self.required:
# return NonNull(_type)
# return get_graphql_type(_type)
# @type.setter
# def type(self, type):
# self._type = type
def source_resolver(source, root, args, context, info): def source_resolver(source, root, args, context, info):
resolved = getattr(root, source, None) resolved = getattr(root, source, None)
if inspect.isfunction(resolved): if inspect.isfunction(resolved):

View File

@ -16,8 +16,10 @@ class Structure(UnmountedType):
class List(Structure): class List(Structure):
pass def __str__(self):
return '[{}]'.format(self.of_type)
class NonNull(Structure): class NonNull(Structure):
pass def __str__(self):
return '{}!'.format(self.of_type)

View File

@ -3,6 +3,7 @@ import pytest
from ..field import Field from ..field import Field
from ..interface import Interface from ..interface import Interface
from ..unmountedtype import UnmountedType from ..unmountedtype import UnmountedType
from ..abstracttype import AbstractType
class MyType(object): class MyType(object):
@ -57,3 +58,25 @@ def test_generate_interface_unmountedtype():
assert 'field' in MyInterface._meta.fields assert 'field' in MyInterface._meta.fields
assert isinstance(MyInterface._meta.fields['field'], Field) assert isinstance(MyInterface._meta.fields['field'], Field)
def test_generate_interface_inherit_abstracttype():
class MyAbstractType(AbstractType):
field1 = MyScalar(MyType)
class MyInterface(Interface, MyAbstractType):
field2 = MyScalar(MyType)
assert MyInterface._meta.fields.keys() == ['field1', 'field2']
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]
def test_generate_interface_inherit_abstracttype_reversed():
class MyAbstractType(AbstractType):
field1 = MyScalar(MyType)
class MyInterface(MyAbstractType, Interface):
field2 = MyScalar(MyType)
assert MyInterface._meta.fields.keys() == ['field1', 'field2']
assert [type(x) for x in MyInterface._meta.fields.values()] == [Field, Field]