2015-09-24 12:11:50 +03:00
|
|
|
from py.test import raises
|
|
|
|
from collections import namedtuple
|
|
|
|
from pytest import raises
|
|
|
|
from graphene.core.fields import (
|
|
|
|
Field,
|
|
|
|
StringField,
|
|
|
|
)
|
|
|
|
|
|
|
|
from graphene.core.options import Options
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
class Meta:
|
2015-10-26 12:27:45 +03:00
|
|
|
is_interface = True
|
2015-09-24 12:11:50 +03:00
|
|
|
type_name = 'Character'
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
class InvalidMeta:
|
|
|
|
other_value = True
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
def test_field_added_in_meta():
|
|
|
|
opt = Options(Meta)
|
|
|
|
|
|
|
|
class ObjectType(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
opt.contribute_to_class(ObjectType, '_meta')
|
|
|
|
f = StringField()
|
|
|
|
f.field_name = 'string_field'
|
|
|
|
opt.add_field(f)
|
|
|
|
assert f in opt.fields
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
def test_options_contribute():
|
|
|
|
opt = Options(Meta)
|
|
|
|
|
|
|
|
class ObjectType(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
opt.contribute_to_class(ObjectType, '_meta')
|
|
|
|
assert ObjectType._meta == opt
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
def test_options_typename():
|
|
|
|
opt = Options(Meta)
|
|
|
|
|
|
|
|
class ObjectType(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
opt.contribute_to_class(ObjectType, '_meta')
|
|
|
|
assert opt.type_name == 'Character'
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
def test_options_description():
|
|
|
|
opt = Options(Meta)
|
|
|
|
|
|
|
|
class ObjectType(object):
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
'''False description'''
|
|
|
|
pass
|
|
|
|
|
|
|
|
opt.contribute_to_class(ObjectType, '_meta')
|
|
|
|
assert opt.description == 'False description'
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-24 12:11:50 +03:00
|
|
|
def test_field_no_contributed_raises_error():
|
|
|
|
opt = Options(InvalidMeta)
|
|
|
|
|
|
|
|
class ObjectType(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
with raises(Exception) as excinfo:
|
|
|
|
opt.contribute_to_class(ObjectType, '_meta')
|
|
|
|
|
|
|
|
assert 'invalid attribute' in str(excinfo.value)
|