2017-04-10 07:04:03 +03:00
|
|
|
from graphene.test import Client
|
2017-07-13 07:45:06 +03:00
|
|
|
|
2015-10-28 09:56:24 +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
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
client = Client(schema)
|
2015-10-31 23:46:43 +03:00
|
|
|
|
2017-07-13 07:45:06 +03:00
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_hero_name_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query HeroNameQuery {
|
|
|
|
hero {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_hero_name_and_friends_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query HeroNameAndFriendsQuery {
|
|
|
|
hero {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
friends {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_nested_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_fetch_luke_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query FetchLukeQuery {
|
|
|
|
human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_fetch_some_id_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query FetchSomeIDQuery($someId: String!) {
|
|
|
|
human(id: $someId) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
|
|
|
params = {"someId": "1000"}
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query, variable_values=params))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_fetch_some_id_query2(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query FetchSomeIDQuery($someId: String!) {
|
|
|
|
human(id: $someId) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
|
|
|
params = {"someId": "1002"}
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query, variable_values=params))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_invalid_id_query(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query humanQuery($id: String!) {
|
|
|
|
human(id: $id) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
|
|
|
params = {"id": "not a valid id"}
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query, variable_values=params))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_fetch_luke_aliased(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query FetchLukeAliased {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_fetch_luke_and_leia_aliased(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query FetchLukeAndLeiaAliased {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
leia: human(id: "1003") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_duplicate_fields(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query DuplicateFields {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
leia: human(id: "1003") {
|
|
|
|
name
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_use_fragment(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
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
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_check_type_of_r2(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2015-09-24 12:11:50 +03:00
|
|
|
query CheckTypeOfR2 {
|
|
|
|
hero {
|
|
|
|
__typename
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|
2015-09-24 12:11:50 +03:00
|
|
|
|
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
def test_check_type_of_luke(snapshot):
|
2018-07-06 22:09:23 +03:00
|
|
|
query = """
|
2016-06-05 00:05:31 +03:00
|
|
|
query CheckTypeOfLuke {
|
|
|
|
hero(episode: EMPIRE) {
|
|
|
|
__typename
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 22:09:23 +03:00
|
|
|
"""
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|