2015-10-28 09:56:24 +03:00
|
|
|
from ..data import setup
|
2015-10-31 23:46:43 +03:00
|
|
|
from ..schema import schema
|
2015-10-27 09:54:51 +03:00
|
|
|
|
|
|
|
setup()
|
2015-09-26 09:25:10 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2016-08-14 09:00:25 +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 {
|
2016-09-09 06:32:24 +03:00
|
|
|
shipName: String!
|
2016-09-09 07:02:29 +03:00
|
|
|
factionId: String!
|
|
|
|
clientMutationId: String
|
2016-08-14 09:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type IntroduceShipPayload {
|
|
|
|
ship: Ship
|
|
|
|
faction: Faction
|
|
|
|
}
|
|
|
|
|
|
|
|
type Mutation {
|
2016-09-09 06:32:24 +03:00
|
|
|
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
|
2016-08-14 09:00:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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!
|
|
|
|
edges: [ShipEdge]
|
|
|
|
}
|
|
|
|
|
|
|
|
type ShipEdge {
|
|
|
|
node: Ship
|
|
|
|
cursor: String!
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
2015-09-26 09:25:10 +03:00
|
|
|
def test_correctly_fetches_id_name_rebels():
|
|
|
|
query = '''
|
|
|
|
query RebelsQuery {
|
|
|
|
rebels {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
expected = {
|
2015-10-03 08:17:51 +03:00
|
|
|
'rebels': {
|
|
|
|
'id': 'RmFjdGlvbjox',
|
|
|
|
'name': 'Alliance to Restore the Republic'
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
}
|
2015-09-28 06:19:33 +03:00
|
|
|
result = schema.execute(query)
|
2015-09-29 10:31:59 +03:00
|
|
|
assert not result.errors
|
2015-09-26 09:25:10 +03:00
|
|
|
assert result.data == expected
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-26 09:25:10 +03:00
|
|
|
def test_correctly_refetches_rebels():
|
|
|
|
query = '''
|
|
|
|
query RebelsRefetchQuery {
|
|
|
|
node(id: "RmFjdGlvbjox") {
|
|
|
|
id
|
|
|
|
... on Faction {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
expected = {
|
2015-10-03 08:17:51 +03:00
|
|
|
'node': {
|
|
|
|
'id': 'RmFjdGlvbjox',
|
|
|
|
'name': 'Alliance to Restore the Republic'
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
}
|
2015-09-28 06:19:33 +03:00
|
|
|
result = schema.execute(query)
|
2015-09-29 10:31:59 +03:00
|
|
|
assert not result.errors
|
2015-09-26 09:25:10 +03:00
|
|
|
assert result.data == expected
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-26 09:25:10 +03:00
|
|
|
def test_correctly_fetches_id_name_empire():
|
|
|
|
query = '''
|
|
|
|
query EmpireQuery {
|
|
|
|
empire {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
expected = {
|
2015-10-03 08:17:51 +03:00
|
|
|
'empire': {
|
|
|
|
'id': 'RmFjdGlvbjoy',
|
|
|
|
'name': 'Galactic Empire'
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
}
|
2015-09-28 06:19:33 +03:00
|
|
|
result = schema.execute(query)
|
2015-09-29 10:31:59 +03:00
|
|
|
assert not result.errors
|
2015-09-26 09:25:10 +03:00
|
|
|
assert result.data == expected
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-26 09:25:10 +03:00
|
|
|
def test_correctly_refetches_empire():
|
|
|
|
query = '''
|
|
|
|
query EmpireRefetchQuery {
|
|
|
|
node(id: "RmFjdGlvbjoy") {
|
|
|
|
id
|
|
|
|
... on Faction {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
expected = {
|
2015-10-03 08:17:51 +03:00
|
|
|
'node': {
|
|
|
|
'id': 'RmFjdGlvbjoy',
|
|
|
|
'name': 'Galactic Empire'
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
}
|
2015-09-28 06:19:33 +03:00
|
|
|
result = schema.execute(query)
|
2015-09-29 10:31:59 +03:00
|
|
|
assert not result.errors
|
2015-09-26 09:25:10 +03:00
|
|
|
assert result.data == expected
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2015-09-26 09:25:10 +03:00
|
|
|
def test_correctly_refetches_xwing():
|
|
|
|
query = '''
|
|
|
|
query XWingRefetchQuery {
|
|
|
|
node(id: "U2hpcDox") {
|
|
|
|
id
|
|
|
|
... on Ship {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
expected = {
|
2015-10-03 08:17:51 +03:00
|
|
|
'node': {
|
|
|
|
'id': 'U2hpcDox',
|
|
|
|
'name': 'X-Wing'
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
}
|
2015-09-28 06:19:33 +03:00
|
|
|
result = schema.execute(query)
|
2015-09-29 10:31:59 +03:00
|
|
|
assert not result.errors
|
2015-09-26 09:25:10 +03:00
|
|
|
assert result.data == expected
|