diff --git a/.gitignore b/.gitignore index 0b25625..4e81c34 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] +.virtualenv # C extensions *.so diff --git a/examples/starwars/tests/test_mutation.py b/examples/starwars/tests/test_mutation.py index aa312ff..7c8019a 100644 --- a/examples/starwars/tests/test_mutation.py +++ b/examples/starwars/tests/test_mutation.py @@ -75,5 +75,6 @@ def test_mutations(): } } result = schema.execute(query) + print(result.data) assert not result.errors assert result.data == expected diff --git a/graphene_django/tests/models.py b/graphene_django/tests/models.py index 0c62f28..03ca59d 100644 --- a/graphene_django/tests/models.py +++ b/graphene_django/tests/models.py @@ -45,6 +45,7 @@ class Article(models.Model): ], default='es') importance = models.IntegerField('Importance', null=True, blank=True, choices=[(1, u'Very important'), (2, u'Not as important')]) + tag = models.CharField(max_length=100) def __str__(self): # __unicode__ on Python 2 return self.headline diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 486e5ff..1f4809b 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -368,6 +368,98 @@ def test_should_query_node_filtering(): assert result.data == expected +@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED, + reason="django-filter should be installed") +def test_should_query_node_multiple_filtering(): + class ReporterType(DjangoObjectType): + + class Meta: + model = Reporter + interfaces = (Node, ) + + class ArticleType(DjangoObjectType): + + class Meta: + model = Article + interfaces = (Node, ) + filter_fields = ('lang', 'tag') + + 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 + ) + Article.objects.create( + headline='Article Node 1', + pub_date=datetime.date.today(), + reporter=r, + editor=r, + lang='es', + tag='one' + ) + Article.objects.create( + headline='Article Node 2', + pub_date=datetime.date.today(), + reporter=r, + editor=r, + lang='en', + tag='two' + ) + Article.objects.create( + headline='Article Node 3', + pub_date=datetime.date.today(), + reporter=r, + editor=r, + lang='en', + tag='three' + ) + + schema = graphene.Schema(query=Query) + query = ''' + query NodeFilteringQuery { + allReporters { + edges { + node { + id + articles(lang: "es", tag: "two") { + edges { + node { + id + } + } + } + } + } + } + } + ''' + + expected = { + 'allReporters': { + 'edges': [{ + 'node': { + 'id': 'UmVwb3J0ZXJUeXBlOjE=', + 'articles': { + 'edges': [{ + 'node': { + 'id': 'QXJ0aWNsZVR5cGU6MQ==' + } + }] + } + } + }] + } + } + + result = schema.execute(query) + assert not result.errors + assert result.data == expected + + def test_should_query_filter_node_limit(): class ReporterFilter(FilterSet): limit = NumberFilter(method='filter_limit')