From 201fd194517e8c3bd3c3cf096c574b0b757994c4 Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Sat, 6 Jun 2020 11:39:03 -0600 Subject: [PATCH] Add test for max_limit. --- graphene_django/tests/test_query.py | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index fcc53e8..92b8101 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -1084,6 +1084,48 @@ def test_should_resolve_get_queryset_connectionfields(): assert result.data == expected +REPORTERS = [ + dict( + first_name=f"First {i}", + last_name=f"Last {i}", + email=f"johndoe+{i}@example.com", + a_choice=1, + ) + for i in range(6) +] + + +def test_should_return_max_limit(graphene_settings): + graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 4 + reporters = [Reporter(**kwargs) for kwargs in REPORTERS] + Reporter.objects.bulk_create(reporters) + + class ReporterType(DjangoObjectType): + class Meta: + model = Reporter + interfaces = (Node,) + + class Query(graphene.ObjectType): + all_reporters = DjangoConnectionField(ReporterType) + + schema = graphene.Schema(query=Query) + query = """ + query AllReporters { + allReporters { + edges { + node { + id + } + } + } + } + """ + + result = schema.execute(query) + assert not result.errors + assert len(result.data["allReporters"]["edges"]) == 4 + + def test_should_preserve_prefetch_related(django_assert_num_queries): class ReporterType(DjangoObjectType): class Meta: