Fixed argument getter in django filters tests

This commit is contained in:
Syrus Akbary 2015-12-11 11:20:35 -08:00
parent 689db2c70e
commit b4f7df3c9d
3 changed files with 9 additions and 4 deletions

View File

@ -35,12 +35,13 @@ class PetNode(DjangoNode):
class Meta:
model = Pet
schema = Schema()
def assert_arguments(field, *arguments):
ignore = ('after', 'before', 'first', 'last', 'orderBy')
actual = [
name
for name in field.arguments.arguments.keys()
for name in schema.T(field.arguments)
if name not in ignore and not name.startswith('_')
]
assert set(arguments) == set(actual), \
@ -51,12 +52,12 @@ def assert_arguments(field, *arguments):
def assert_orderable(field):
assert 'orderBy' in field.arguments.arguments.keys(), \
assert 'orderBy' in schema.T(field.arguments), \
'Field cannot be ordered'
def assert_not_orderable(field):
assert 'orderBy' not in field.arguments.arguments.keys(), \
assert 'orderBy' not in schema.T(field.arguments), \
'Field can be ordered'

View File

@ -1,3 +1,4 @@
import pytest
from py.test import raises
import graphene
@ -7,6 +8,9 @@ from graphene.contrib.django import DjangoNode, DjangoObjectType
from .models import Article, Reporter
pytestmark = pytest.mark.django_db
def test_should_query_only_fields():
with raises(Exception):
class ReporterType(DjangoObjectType):

View File

@ -66,7 +66,7 @@ def get_filtering_args_from_filterset(filterset_class, type):
# Also add the 'order_by' field
if filterset_class._meta.order_by:
args[filterset_class.order_by_field] = Argument(String)
args[filterset_class.order_by_field] = Argument(String())
return args