mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 17:47:12 +03:00
Add failing test case
This commit is contained in:
parent
dbd3957a9f
commit
23eb8eea80
|
@ -19,6 +19,10 @@ class FilmDetails(models.Model):
|
|||
|
||||
|
||||
class Film(models.Model):
|
||||
genre = models.CharField(max_length=2, help_text='Genre', choices=[
|
||||
('do', 'Documentary'),
|
||||
('ot', 'Other')
|
||||
], default='ot')
|
||||
reporters = models.ManyToManyField('Reporter',
|
||||
related_name='films')
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ from django.db import models
|
|||
from django.utils.functional import SimpleLazyObject
|
||||
from py.test import raises
|
||||
|
||||
from django.db.models import Q
|
||||
|
||||
import graphene
|
||||
from graphene.relay import Node
|
||||
|
||||
|
@ -17,6 +19,8 @@ from .models import (
|
|||
Article,
|
||||
CNNReporter,
|
||||
Reporter,
|
||||
Film,
|
||||
FilmDetails,
|
||||
)
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
@ -431,6 +435,61 @@ 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_filtering_with_distinct_queryset():
|
||||
class FilmType(DjangoObjectType):
|
||||
|
||||
class Meta:
|
||||
model = Film
|
||||
interfaces = (Node, )
|
||||
filter_fields = ('genre',)
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
films = DjangoConnectionField(FilmType)
|
||||
|
||||
# def resolve_all_reporters_with_berlin_films(self, args, context, info):
|
||||
# return Reporter.objects.filter(Q(films__film__location__contains="Berlin") | Q(a_choice=1))
|
||||
|
||||
def resolve_films(self, args, context, info):
|
||||
return Film.objects.filter(Q(details__location__contains="Berlin") | Q(genre__in=['ot'])).distinct()
|
||||
|
||||
f = Film.objects.create(
|
||||
)
|
||||
fd = FilmDetails.objects.create(
|
||||
location="Berlin",
|
||||
film=f
|
||||
)
|
||||
|
||||
schema = graphene.Schema(query=Query)
|
||||
query = '''
|
||||
query NodeFilteringQuery {
|
||||
films {
|
||||
edges {
|
||||
node {
|
||||
genre
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
expected = {
|
||||
'films': {
|
||||
'edges': [{
|
||||
'node': {
|
||||
'genre': 'ot'
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
result = schema.execute(query)
|
||||
assert not result.errors
|
||||
print(result.data)
|
||||
assert result.data == expected
|
||||
|
||||
|
||||
@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
|
||||
reason="django-filter should be installed")
|
||||
def test_should_query_node_multiple_filtering():
|
||||
|
|
Loading…
Reference in New Issue
Block a user