2017-04-10 07:04:03 +03:00
|
|
|
from graphene.test import Client
|
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-04-10 07:04:03 +03:00
|
|
|
def test_hero_name_query(snapshot):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query HeroNameQuery {
|
|
|
|
hero {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query HeroNameAndFriendsQuery {
|
|
|
|
hero {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
friends {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query FetchLukeQuery {
|
|
|
|
human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query FetchSomeIDQuery($someId: String!) {
|
|
|
|
human(id: $someId) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query FetchSomeIDQuery($someId: String!) {
|
|
|
|
human(id: $someId) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query humanQuery($id: String!) {
|
|
|
|
human(id: $id) {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query FetchLukeAliased {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query FetchLukeAndLeiaAliased {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
leia: human(id: "1003") {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query DuplicateFields {
|
|
|
|
luke: human(id: "1000") {
|
|
|
|
name
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
leia: human(id: "1003") {
|
|
|
|
name
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
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
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2015-09-24 12:11:50 +03:00
|
|
|
query = '''
|
|
|
|
query CheckTypeOfR2 {
|
|
|
|
hero {
|
|
|
|
__typename
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
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):
|
2016-06-05 00:05:31 +03:00
|
|
|
query = '''
|
|
|
|
query CheckTypeOfLuke {
|
|
|
|
hero(episode: EMPIRE) {
|
|
|
|
__typename
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
2017-04-10 07:04:03 +03:00
|
|
|
snapshot.assert_match(client.execute(query))
|