Skip to content

Commit 67804fd

Browse files
author
Niall
committed
Add broken test
1 parent 7085437 commit 67804fd

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Byte-compiled / optimized / DLL files
55
__pycache__/
66
*.py[cod]
7+
.virtualenv
78

89
# C extensions
910
*.so

examples/starwars/tests/test_mutation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ def test_mutations():
7575
}
7676
}
7777
result = schema.execute(query)
78+
print(result.data)
7879
assert not result.errors
7980
assert result.data == expected

graphene_django/tests/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Article(models.Model):
4545
], default='es')
4646
importance = models.IntegerField('Importance', null=True, blank=True,
4747
choices=[(1, u'Very important'), (2, u'Not as important')])
48+
tag = models.CharField(max_length=100)
4849

4950
def __str__(self): # __unicode__ on Python 2
5051
return self.headline

graphene_django/tests/test_query.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,98 @@ class Query(graphene.ObjectType):
368368
assert result.data == expected
369369

370370

371+
@pytest.mark.skipif(not DJANGO_FILTER_INSTALLED,
372+
reason="django-filter should be installed")
373+
def test_should_query_node_multiple_filtering():
374+
class ReporterType(DjangoObjectType):
375+
376+
class Meta:
377+
model = Reporter
378+
interfaces = (Node, )
379+
380+
class ArticleType(DjangoObjectType):
381+
382+
class Meta:
383+
model = Article
384+
interfaces = (Node, )
385+
filter_fields = ('lang', 'tag')
386+
387+
class Query(graphene.ObjectType):
388+
all_reporters = DjangoConnectionField(ReporterType)
389+
390+
r = Reporter.objects.create(
391+
first_name='John',
392+
last_name='Doe',
393+
email='johndoe@example.com',
394+
a_choice=1
395+
)
396+
Article.objects.create(
397+
headline='Article Node 1',
398+
pub_date=datetime.date.today(),
399+
reporter=r,
400+
editor=r,
401+
lang='es',
402+
tag='one'
403+
)
404+
Article.objects.create(
405+
headline='Article Node 2',
406+
pub_date=datetime.date.today(),
407+
reporter=r,
408+
editor=r,
409+
lang='en',
410+
tag='two'
411+
)
412+
Article.objects.create(
413+
headline='Article Node 3',
414+
pub_date=datetime.date.today(),
415+
reporter=r,
416+
editor=r,
417+
lang='en',
418+
tag='three'
419+
)
420+
421+
schema = graphene.Schema(query=Query)
422+
query = '''
423+
query NodeFilteringQuery {
424+
allReporters {
425+
edges {
426+
node {
427+
id
428+
articles(lang: "es", tag: "two") {
429+
edges {
430+
node {
431+
id
432+
}
433+
}
434+
}
435+
}
436+
}
437+
}
438+
}
439+
'''
440+
441+
expected = {
442+
'allReporters': {
443+
'edges': [{
444+
'node': {
445+
'id': 'UmVwb3J0ZXJUeXBlOjE=',
446+
'articles': {
447+
'edges': [{
448+
'node': {
449+
'id': 'QXJ0aWNsZVR5cGU6MQ=='
450+
}
451+
}]
452+
}
453+
}
454+
}]
455+
}
456+
}
457+
458+
result = schema.execute(query)
459+
assert not result.errors
460+
assert result.data == expected
461+
462+
371463
def test_should_query_filter_node_limit():
372464
class ReporterFilter(FilterSet):
373465
limit = NumberFilter(method='filter_limit')

0 commit comments

Comments
 (0)