Fixed lint and registry error description

This commit is contained in:
Syrus Akbary 2017-02-18 14:20:23 -08:00
parent b06e33ddd7
commit d81892e0d4
3 changed files with 16 additions and 6 deletions

View File

@ -9,8 +9,15 @@ class Registry(object):
model = cls._meta.model model = cls._meta.model
assert self._registry.get(model, cls) == cls, ( assert self._registry.get(model, cls) == cls, (
'Django Model "{}.{}" already associated with {}. ' 'Django Model "{}.{}" already associated with {}. '
'You can use a different registry for {} or skip the global Registry with "{}.Meta.skip_global_registry = True".' 'You can use a different registry for {} or skip '
).format(model._meta.app_label, model._meta.object_name, repr(self.get_type_for_model(cls._meta.model)), repr(cls), cls) 'the global Registry with "{}.Meta.skip_global_registry = True".'
).format(
model._meta.app_label,
model._meta.object_name,
repr(self.get_type_for_model(cls._meta.model)),
repr(cls),
cls
)
assert issubclass( assert issubclass(
cls, DjangoObjectType), 'Only DjangoObjectTypes can be registered, received "{}"'.format( cls, DjangoObjectType), 'Only DjangoObjectTypes can be registered, received "{}"'.format(
cls.__name__) cls.__name__)

View File

@ -27,6 +27,9 @@ def test_registry_multiple_types():
class Meta: class Meta:
model = ReporterModel model = ReporterModel
class Reporter2(object):
pass
with raises(Exception) as exc_info: with raises(Exception) as exc_info:
class Reporter2(DjangoObjectType): class Reporter2(DjangoObjectType):
'''Reporter2 description''' '''Reporter2 description'''
@ -34,10 +37,10 @@ def test_registry_multiple_types():
model = ReporterModel model = ReporterModel
assert str(exc_info.value) == ( assert str(exc_info.value) == (
'Django Model "tests.Reporter" already associated with <class \'graphene_django.tests.test_registry.Reporter\'>. ' 'Django Model "tests.Reporter" already associated with {}. '
'You can use a different registry for <class \'graphene_django.tests.test_registry.Reporter2\'> ' 'You can use a different registry for {} '
'or skip the global Registry with "Reporter2.Meta.skip_global_registry = True".' 'or skip the global Registry with "Reporter2.Meta.skip_global_registry = True".'
) ).format(repr(Reporter), repr(Reporter2))
def test_registry_multiple_types_dont_collision_if_skip_global_registry(): def test_registry_multiple_types_dont_collision_if_skip_global_registry():

View File

@ -72,7 +72,7 @@ class DjangoObjectTypeMeta(ObjectTypeMeta):
attrs.pop('Meta', None), attrs.pop('Meta', None),
**defaults **defaults
) )
# If the DjangoObjectType wants to skip the registry # If the DjangoObjectType wants to skip the global registry
# we will automatically create one, so the model is isolated # we will automatically create one, so the model is isolated
# there. # there.
if options.skip_global_registry: if options.skip_global_registry: