mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 11:03:58 +03:00
Improved testing coverage. Removed unused logic
This commit is contained in:
parent
55e2027dbb
commit
2d55d89047
|
@ -55,15 +55,8 @@ class Options(object):
|
|||
else:
|
||||
self.proxy = False
|
||||
|
||||
if self.interfaces != [] and self.interface:
|
||||
raise Exception("A interface cannot inherit from interfaces")
|
||||
|
||||
del self.meta
|
||||
|
||||
@cached_property
|
||||
def object(self):
|
||||
return namedtuple(self.type_name, self.fields_map.keys())
|
||||
|
||||
def add_field(self, field):
|
||||
self.local_fields.append(field)
|
||||
|
||||
|
|
|
@ -132,8 +132,6 @@ class BaseObjectType(object):
|
|||
def __new__(cls, *args, **kwargs):
|
||||
if cls._meta.is_interface:
|
||||
raise Exception("An interface cannot be initialized")
|
||||
if not args and not kwargs:
|
||||
return None
|
||||
return super(BaseObjectType, cls).__new__(cls)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
|
|
@ -24,10 +24,10 @@ class ProxySnakeDict(collections.MutableMapping):
|
|||
def __len__(self):
|
||||
return len(self.data)
|
||||
|
||||
def __delitem__(self):
|
||||
def __delitem__(self, item):
|
||||
raise TypeError('ProxySnakeDict does not support item deletion')
|
||||
|
||||
def __setitem__(self):
|
||||
def __setitem__(self, item, value):
|
||||
raise TypeError('ProxySnakeDict does not support item assignment')
|
||||
|
||||
def __getitem__(self, key):
|
||||
|
@ -59,5 +59,12 @@ class ProxySnakeDict(collections.MutableMapping):
|
|||
for k in self.iterkeys():
|
||||
yield k, self[k]
|
||||
|
||||
def to_data_dict(self):
|
||||
return self.data.__class__(self.iteritems())
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.to_data_dict() == other.to_data_dict()
|
||||
|
||||
def __repr__(self):
|
||||
return dict(self.iteritems()).__repr__()
|
||||
data_repr = self.to_data_dict().__repr__()
|
||||
return '<ProxySnakeDict {}>'.format(data_repr)
|
||||
|
|
|
@ -34,6 +34,18 @@ class Human(Character):
|
|||
class Meta:
|
||||
type_name = 'core_Human'
|
||||
|
||||
@property
|
||||
def readonly_prop(self):
|
||||
return 'readonly'
|
||||
|
||||
@property
|
||||
def write_prop(self):
|
||||
return self._write_prop
|
||||
|
||||
@write_prop.setter
|
||||
def write_prop(self, value):
|
||||
self._write_prop = value
|
||||
|
||||
schema = Schema()
|
||||
|
||||
|
||||
|
@ -44,8 +56,12 @@ def test_interface():
|
|||
assert Character._meta.type_name == 'core_Character'
|
||||
assert object_type.description == 'Character description'
|
||||
assert list(object_type.get_fields().keys()) == ['name']
|
||||
# assert object_type.get_fields() == {
|
||||
# 'name': Character._meta.fields_map['name'].internal_field(schema)}
|
||||
|
||||
|
||||
def test_interface_cannot_initialize():
|
||||
with raises(Exception) as excinfo:
|
||||
c = Character()
|
||||
assert 'An interface cannot be initialized' == str(excinfo.value)
|
||||
|
||||
|
||||
def test_interface_resolve_type():
|
||||
|
@ -66,6 +82,27 @@ def test_object_type():
|
|||
assert Human._meta.fields_map['name'].object_type == Human
|
||||
|
||||
|
||||
def test_object_type_container():
|
||||
h = Human(name='My name')
|
||||
assert h.name == 'My name'
|
||||
|
||||
|
||||
def test_object_type_set_properties():
|
||||
h = Human(readonly_prop='custom', write_prop='custom')
|
||||
assert h.readonly_prop == 'readonly'
|
||||
assert h.write_prop == 'custom'
|
||||
|
||||
|
||||
def test_object_type_container_invalid_kwarg():
|
||||
with raises(TypeError):
|
||||
Human(invalid='My name')
|
||||
|
||||
|
||||
def test_object_type_container_too_many_args():
|
||||
with raises(IndexError):
|
||||
Human('Peter', 'No friends :(', None)
|
||||
|
||||
|
||||
def test_field_clashes():
|
||||
with raises(Exception) as excinfo:
|
||||
class Droid(Character):
|
||||
|
|
13
tests/utils/test_misc.py
Normal file
13
tests/utils/test_misc.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import collections
|
||||
from graphql.core.type import GraphQLEnumType
|
||||
from graphene.utils.misc import enum_to_graphql_enum
|
||||
|
||||
item = collections.namedtuple('type', 'name value')
|
||||
|
||||
|
||||
class MyCustomEnum(list):
|
||||
__name__ = 'MyName'
|
||||
|
||||
|
||||
def test_enum_to_graphql_enum():
|
||||
assert isinstance(enum_to_graphql_enum(MyCustomEnum([item('k', 'v')])), GraphQLEnumType)
|
|
@ -1,3 +1,4 @@
|
|||
from py.test import raises
|
||||
from graphene.utils import ProxySnakeDict
|
||||
|
||||
|
||||
|
@ -8,6 +9,7 @@ def test_proxy_snake_dict():
|
|||
assert 'two' in p
|
||||
assert 'threeOrFor' in p
|
||||
assert 'none' in p
|
||||
assert len(p) == len(my_data)
|
||||
assert p['none'] is None
|
||||
assert p.get('none') is None
|
||||
assert p.get('none_existent') is None
|
||||
|
@ -15,6 +17,11 @@ def test_proxy_snake_dict():
|
|||
assert p.get('three_or_for') == 3
|
||||
assert 'inside' in p
|
||||
assert 'other_camel_case' in p['inside']
|
||||
assert sorted(p.items()) == sorted(list([('inside', ProxySnakeDict({'other_camel_case': 3})),
|
||||
('none', None),
|
||||
('three_or_for', 3),
|
||||
('two', 2),
|
||||
('one', 1)]))
|
||||
|
||||
|
||||
def test_proxy_snake_dict_as_kwargs():
|
||||
|
@ -24,3 +31,22 @@ def test_proxy_snake_dict_as_kwargs():
|
|||
def func(**kwargs):
|
||||
return kwargs.get('my_data')
|
||||
assert func(**p) == 1
|
||||
|
||||
|
||||
def test_proxy_snake_dict_repr():
|
||||
my_data = {'myData': 1}
|
||||
p = ProxySnakeDict(my_data)
|
||||
|
||||
assert repr(p) == "<ProxySnakeDict {'my_data': 1}>"
|
||||
|
||||
|
||||
def test_proxy_snake_dict_set():
|
||||
p = ProxySnakeDict({})
|
||||
with raises(TypeError):
|
||||
p['a'] = 2
|
||||
|
||||
|
||||
def test_proxy_snake_dict_delete():
|
||||
p = ProxySnakeDict({})
|
||||
with raises(TypeError):
|
||||
del p['a']
|
||||
|
|
Loading…
Reference in New Issue
Block a user