graphene/examples/starwars_relay/tests/test_objectidentification.py

136 lines
2.2 KiB
Python
Raw Normal View History

from graphene.test import Client
from ..data import setup
from ..schema import schema
2015-10-27 09:54:51 +03:00
setup()
2015-09-26 09:25:10 +03:00
client = Client(schema)
2015-10-03 08:17:51 +03:00
def test_str_schema():
assert str(schema) == '''schema {
query: Query
mutation: Mutation
}
type Faction implements Node {
id: ID!
name: String
ships(before: String, after: String, first: Int, last: Int): ShipConnection
}
input IntroduceShipInput {
shipName: String!
factionId: String!
clientMutationId: String
}
type IntroduceShipPayload {
ship: Ship
faction: Faction
clientMutationId: String
}
type Mutation {
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
}
interface Node {
id: ID!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}
type Query {
rebels: Faction
empire: Faction
node(id: ID!): Node
}
type Ship implements Node {
id: ID!
name: String
}
type ShipConnection {
pageInfo: PageInfo!
2016-10-27 20:35:31 +03:00
edges: [ShipEdge]!
}
type ShipEdge {
node: Ship
cursor: String!
}
'''
def test_correctly_fetches_id_name_rebels(snapshot):
2015-09-26 09:25:10 +03:00
query = '''
query RebelsQuery {
rebels {
id
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
def test_correctly_refetches_rebels(snapshot):
2015-09-26 09:25:10 +03:00
query = '''
query RebelsRefetchQuery {
node(id: "RmFjdGlvbjox") {
id
... on Faction {
name
}
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
def test_correctly_fetches_id_name_empire(snapshot):
2015-09-26 09:25:10 +03:00
query = '''
query EmpireQuery {
empire {
id
name
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
def test_correctly_refetches_empire(snapshot):
2015-09-26 09:25:10 +03:00
query = '''
query EmpireRefetchQuery {
node(id: "RmFjdGlvbjoy") {
id
... on Faction {
name
}
}
}
'''
snapshot.assert_match(client.execute(query))
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
def test_correctly_refetches_xwing(snapshot):
2015-09-26 09:25:10 +03:00
query = '''
query XWingRefetchQuery {
node(id: "U2hpcDox") {
id
... on Ship {
name
}
}
}
'''
snapshot.assert_match(client.execute(query))