graphene/examples/starwars/tests/test_query.py

183 lines
3.6 KiB
Python
Raw Normal View History

from graphene.test import Client
2017-07-13 07:45:06 +03:00
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)
2017-07-13 07:45:06 +03:00
def test_hero_name_query(snapshot):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
name
}
}
"""
params = {"someId": "1000"}
snapshot.assert_match(client.execute(query, variables=params))
2015-09-24 12:11:50 +03:00
def test_fetch_some_id_query2(snapshot):
query = """
2015-09-24 12:11:50 +03:00
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
name
}
}
"""
params = {"someId": "1002"}
snapshot.assert_match(client.execute(query, variables=params))
2015-09-24 12:11:50 +03:00
def test_invalid_id_query(snapshot):
query = """
2015-09-24 12:11:50 +03:00
query humanQuery($id: String!) {
human(id: $id) {
name
}
}
"""
params = {"id": "not a valid id"}
snapshot.assert_match(client.execute(query, variables=params))
2015-09-24 12:11:50 +03:00
def test_fetch_luke_aliased(snapshot):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2015-09-24 12:11:50 +03:00
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):
query = """
2016-06-05 00:05:31 +03:00
query CheckTypeOfLuke {
hero(episode: EMPIRE) {
__typename
name
}
}
"""
snapshot.assert_match(client.execute(query))