graphene/examples/starwars/tests/test_query.py

188 lines
3.7 KiB
Python
Raw Normal View History

from graphene.test import Client
from ..data import setup
2016-06-04 21:21:33 +03:00
from ..schema import schema
2015-09-24 12:11:50 +03:00
2015-10-27 09:54:51 +03:00
setup()
2015-09-24 12:11:50 +03:00
client = Client(schema)
def test_hero_name_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query HeroNameQuery {
hero {
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_hero_name_and_friends_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query HeroNameAndFriendsQuery {
hero {
id
name
friends {
name
}
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_nested_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query NestedQuery {
hero {
name
friends {
name
2016-06-05 00:05:31 +03:00
appearsIn
2015-09-24 12:11:50 +03:00
friends {
name
}
}
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_fetch_luke_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query FetchLukeQuery {
human(id: "1000") {
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_fetch_some_id_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
name
}
}
'''
params = {
'someId': '1000',
}
snapshot.assert_match(client.execute(query, variable_values=params))
2015-09-24 12:11:50 +03:00
def test_fetch_some_id_query2(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
name
}
}
'''
params = {
'someId': '1002',
}
snapshot.assert_match(client.execute(query, variable_values=params))
2015-09-24 12:11:50 +03:00
def test_invalid_id_query(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query humanQuery($id: String!) {
human(id: $id) {
name
}
}
'''
params = {
'id': 'not a valid id',
}
snapshot.assert_match(client.execute(query, variable_values=params))
2015-09-24 12:11:50 +03:00
def test_fetch_luke_aliased(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query FetchLukeAliased {
luke: human(id: "1000") {
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_fetch_luke_and_leia_aliased(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query FetchLukeAndLeiaAliased {
luke: human(id: "1000") {
name
}
leia: human(id: "1003") {
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_duplicate_fields(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query DuplicateFields {
luke: human(id: "1000") {
name
homePlanet
}
leia: human(id: "1003") {
name
homePlanet
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_use_fragment(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query UseFragment {
luke: human(id: "1000") {
...HumanFragment
}
leia: human(id: "1003") {
...HumanFragment
}
}
fragment HumanFragment on Human {
name
homePlanet
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_check_type_of_r2(snapshot):
2015-09-24 12:11:50 +03:00
query = '''
query CheckTypeOfR2 {
hero {
__typename
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-24 12:11:50 +03:00
def test_check_type_of_luke(snapshot):
2016-06-05 00:05:31 +03:00
query = '''
query CheckTypeOfLuke {
hero(episode: EMPIRE) {
__typename
name
}
}
'''
snapshot.assert_match(client.execute(query))