mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 01:47:57 +03:00 
			
		
		
		
	Test: erro if last is greater than max - plus fix wrong variable
This commit is contained in:
		
							parent
							
								
									65e63026a0
								
							
						
					
					
						commit
						de59d26968
					
				| 
						 | 
				
			
			@ -116,7 +116,7 @@ class DjangoConnectionField(ConnectionField):
 | 
			
		|||
            if last:
 | 
			
		||||
                assert last <= max_limit, (
 | 
			
		||||
                    'Requesting {} records on the `{}` connection exceeds the `last` limit of {} records.'
 | 
			
		||||
                ).format(first, info.field_name, max_limit)
 | 
			
		||||
                ).format(last, info.field_name, max_limit)
 | 
			
		||||
                args['last'] = min(last, max_limit)
 | 
			
		||||
 | 
			
		||||
        iterable = resolver(root, info, **args)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -606,6 +606,53 @@ def test_should_error_if_first_is_greater_than_max():
 | 
			
		|||
    graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_error_if_last_is_greater_than_max():
 | 
			
		||||
    graphene_settings.RELAY_CONNECTION_MAX_LIMIT = 100
 | 
			
		||||
 | 
			
		||||
    class ReporterType(DjangoObjectType):
 | 
			
		||||
 | 
			
		||||
        class Meta:
 | 
			
		||||
            model = Reporter
 | 
			
		||||
            interfaces = (Node, )
 | 
			
		||||
 | 
			
		||||
    class Query(graphene.ObjectType):
 | 
			
		||||
        all_reporters = DjangoConnectionField(ReporterType)
 | 
			
		||||
 | 
			
		||||
    r = Reporter.objects.create(
 | 
			
		||||
        first_name='John',
 | 
			
		||||
        last_name='Doe',
 | 
			
		||||
        email='johndoe@example.com',
 | 
			
		||||
        a_choice=1
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    schema = graphene.Schema(query=Query)
 | 
			
		||||
    query = '''
 | 
			
		||||
        query NodeFilteringQuery {
 | 
			
		||||
            allReporters(last: 101) {
 | 
			
		||||
                edges {
 | 
			
		||||
                    node {
 | 
			
		||||
                        id
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    '''
 | 
			
		||||
 | 
			
		||||
    expected = {
 | 
			
		||||
        'allReporters': None
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    result = schema.execute(query)
 | 
			
		||||
    assert len(result.errors) == 1
 | 
			
		||||
    assert str(result.errors[0]) == (
 | 
			
		||||
        'Requesting 101 records on the `allReporters` connection '
 | 
			
		||||
        'exceeds the `last` limit of 100 records.'
 | 
			
		||||
    )
 | 
			
		||||
    assert result.data == expected
 | 
			
		||||
 | 
			
		||||
    graphene_settings.RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST = False
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_should_query_promise_connectionfields():
 | 
			
		||||
    from promise import Promise
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user