add test for using queryset with django filters

This commit is contained in:
Jason Kraus 2019-10-21 11:21:08 -07:00
parent 077b5aa96f
commit 38fc15c481

View File

@ -669,7 +669,7 @@ def test_order_by_is_perserved():
assert reverse_result.data == reverse_expected
def test_annotation_is_perserved():
def test_annotation_is_preserved():
class ReporterType(DjangoObjectType):
full_name = String()
@ -714,6 +714,48 @@ def test_annotation_is_perserved():
assert result.data == expected
def test_annotation_with_only():
class ReporterType(DjangoObjectType):
full_name = String()
class Meta:
model = Reporter
interfaces = (Node,)
filter_fields = ()
class Query(ObjectType):
all_reporters = DjangoFilterConnectionField(ReporterType)
def resolve_all_reporters(self, info, **args):
return Reporter.objects.only("first_name", "last_name").annotate(
full_name=Concat(
"first_name", Value(" "), "last_name", output_field=TextField()
)
)
Reporter.objects.create(first_name="John", last_name="Doe")
schema = Schema(query=Query)
query = """
query NodeFilteringQuery {
allReporters(first: 1) {
edges {
node {
fullName
}
}
}
}
"""
expected = {"allReporters": {"edges": [{"node": {"fullName": "John Doe"}}]}}
result = schema.execute(query)
assert not result.errors
assert result.data == expected
def test_integer_field_filter_type():
class PetType(DjangoObjectType):
class Meta: