def assert_conversion(django_field, graphene_field, *args, **kwargs): field = django_field(help_text='Custom Help Text', *args, **kwargs) graphene_type = convert_django_field(field) assert isinstance(graphene_type, graphene_field) field = graphene_type.as_field() assert field.description == 'Custom Help Text' return field
def test_should_manytoone_convert_connectionorlist(): # Django 1.9 uses 'rel', <1.9 uses 'related related = getattr(Reporter.articles, "rel", None) or getattr(Reporter.articles, "related") graphene_type = convert_django_field(related) assert isinstance(graphene_type, ConnectionOrListField) assert isinstance(graphene_type.type, DjangoModelField) assert graphene_type.type.model == Article
def test_should_manytoone_convert_connectionorlist(): # Django 1.9 uses 'rel', <1.9 uses 'related related = getattr(Reporter.articles, 'rel', None) or \ getattr(Reporter.articles, 'related') graphene_type = convert_django_field(related) assert isinstance(graphene_type, ConnectionOrListField) assert isinstance(graphene_type.type, DjangoModelField) assert graphene_type.type.model == Article
def add_extra_fields(cls): if not cls._meta.model: return only_fields = cls._meta.only_fields reverse_fields = get_reverse_fields(cls._meta.model) all_fields = sorted(list(cls._meta.model._meta.fields) + list(cls._meta.model._meta.local_many_to_many)) all_fields += list(reverse_fields) for field in all_fields: is_not_in_only = only_fields and field.name not in only_fields is_excluded = field.name in cls._meta.exclude_fields if is_not_in_only or is_excluded: # We skip this field if we specify only_fields and is not # in there. Or when we excldue this field in exclude_fields continue converted_field = convert_django_field(field) cls.add_to_class(field.name, converted_field)
def test_should_manytomany_convert_connectionorlist(): graphene_type = convert_django_field(Reporter._meta.local_many_to_many[0]) assert isinstance(graphene_type, ConnectionOrListField) assert isinstance(graphene_type.type, DjangoModelField) assert graphene_type.type.model == Reporter
def test_should_unknown_django_field_raise_exception(): with raises(Exception) as excinfo: convert_django_field(None) assert 'Don\'t know how to convert the Django field' in str(excinfo.value)
def test_should_manytoone_convert_connectionorlist(): graphene_type = convert_django_field(Reporter.articles.related) assert isinstance(graphene_type, ConnectionOrListField) assert isinstance(graphene_type.type, DjangoModelField) assert graphene_type.type.model == Article
def assert_conversion(django_field, graphene_field, *args): field = django_field(*args, help_text='Custom Help Text') graphene_type = convert_django_field(field) assert isinstance(graphene_type, graphene_field) assert graphene_type.description == 'Custom Help Text' return graphene_type