mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 12:16:58 +03:00
Renaming order -> order_by (and fixing assert_not_orderable())
This commit is contained in:
parent
f616b597ac
commit
bbbf688449
|
@ -25,7 +25,7 @@ class GlobalIDMultipleChoiceFilter(MultipleChoiceFilter):
|
|||
return super(GlobalIDMultipleChoiceFilter, self).filter(qs, gids)
|
||||
|
||||
|
||||
ORDER_BY_FIELD = getattr(settings, 'GRAPHENE_ORDER_BY_FIELD', 'order')
|
||||
ORDER_BY_FIELD = getattr(settings, 'GRAPHENE_ORDER_BY_FIELD', 'order_by')
|
||||
|
||||
|
||||
GRAPHENE_FILTER_SET_OVERRIDES = {
|
||||
|
|
|
@ -36,8 +36,8 @@ class SimpleQuerySetConnectionResolver(BaseQuerySetConnectionResolver):
|
|||
return query
|
||||
|
||||
def get_filter_kwargs(self):
|
||||
ignore = ['first', 'last', 'before', 'after', 'order']
|
||||
ignore = ['first', 'last', 'before', 'after', 'order_by']
|
||||
return {k: v for k, v in self.args.items() if k not in ignore}
|
||||
|
||||
def get_order(self):
|
||||
return self.args.get('order', None)
|
||||
return self.args.get('order_by', None)
|
||||
|
|
|
@ -34,7 +34,7 @@ class PetNode(DjangoNode):
|
|||
|
||||
|
||||
def assert_arguments(field, *arguments):
|
||||
ignore = ('after', 'before', 'first', 'last', 'order')
|
||||
ignore = ('after', 'before', 'first', 'last', 'orderBy')
|
||||
actual = [
|
||||
name
|
||||
for name in field.arguments.arguments.keys()
|
||||
|
@ -48,12 +48,12 @@ def assert_arguments(field, *arguments):
|
|||
|
||||
|
||||
def assert_orderable(field):
|
||||
assert 'order' in field.arguments.arguments.keys(), \
|
||||
assert 'orderBy' in field.arguments.arguments.keys(), \
|
||||
'Field cannot be ordered'
|
||||
|
||||
|
||||
def assert_not_orderable(field):
|
||||
assert 'order' in field.arguments.arguments.keys(), \
|
||||
assert 'orderBy' not in field.arguments.arguments.keys(), \
|
||||
'Field can be ordered'
|
||||
|
||||
|
||||
|
@ -107,7 +107,7 @@ def test_filter_explicit_filterset_not_orderable():
|
|||
|
||||
def test_filter_shortcut_filterset_extra_meta():
|
||||
field = DjangoFilterConnectionField(ArticleNode, extra_filter_meta={
|
||||
'ordering': True
|
||||
'order_by': True
|
||||
})
|
||||
assert_orderable(field)
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ def test_filter_order():
|
|||
resolver = FilterConnectionResolver(ArticleNode,
|
||||
filterset_class=ArticleFilter)
|
||||
resolved = resolver(inst=article, args={
|
||||
'order': 'headline'
|
||||
'order_by': 'headline'
|
||||
}, info=None)
|
||||
assert 'WHERE' not in str(resolved.query)
|
||||
assert 'ORDER BY' in str(resolved.query)
|
||||
|
@ -76,7 +76,7 @@ def test_filter_order_not_available():
|
|||
resolver = FilterConnectionResolver(ReporterNode,
|
||||
filterset_class=ReporterFilter)
|
||||
resolved = resolver(inst=reporter, args={
|
||||
'order': 'last_name'
|
||||
'order_by': 'last_name'
|
||||
}, info=None)
|
||||
assert 'WHERE' not in str(resolved.query)
|
||||
assert 'ORDER BY' not in str(resolved.query)
|
||||
|
|
|
@ -51,7 +51,7 @@ def test_simple_order():
|
|||
reporter = Reporter(id=1, first_name='Cookie Monster')
|
||||
resolver = SimpleQuerySetConnectionResolver(ReporterNode)
|
||||
resolved = resolver(inst=reporter, args={
|
||||
'order': 'last_name'
|
||||
'order_by': 'last_name'
|
||||
}, info=None)
|
||||
assert 'WHERE' not in str(resolved.query)
|
||||
assert 'ORDER BY' in str(resolved.query)
|
||||
|
|
|
@ -45,7 +45,8 @@ def get_filtering_args_from_filterset(filterset_class, type):
|
|||
args[name] = field_type
|
||||
|
||||
# Also add the 'order_by' field
|
||||
args[filterset_class.order_by_field] = Argument(String)
|
||||
if filterset_class._meta.order_by:
|
||||
args[filterset_class.order_by_field] = Argument(String)
|
||||
return args
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user