2024-08-08 12:49:26 +03:00
|
|
|
import textwrap
|
|
|
|
|
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
|
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
|
|
|
|
2017-04-10 07:04:03 +03:00
|
|
|
client = Client(schema)
|
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
def test_str_schema():
|
|
|
|
assert str(schema).strip() == textwrap.dedent(
|
|
|
|
'''\
|
|
|
|
type Query {
|
|
|
|
rebels: Faction
|
|
|
|
empire: Faction
|
|
|
|
node(
|
|
|
|
"""The ID of the object"""
|
|
|
|
id: ID!
|
|
|
|
): Node
|
|
|
|
}
|
|
|
|
|
|
|
|
"""A faction in the Star Wars saga"""
|
|
|
|
type Faction implements Node {
|
|
|
|
"""The ID of the object"""
|
|
|
|
id: ID!
|
|
|
|
|
|
|
|
"""The name of the faction."""
|
|
|
|
name: String
|
|
|
|
|
|
|
|
"""The ships used by the faction."""
|
|
|
|
ships(before: String, after: String, first: Int, last: Int): ShipConnection
|
|
|
|
}
|
|
|
|
|
|
|
|
"""An object with an ID"""
|
|
|
|
interface Node {
|
|
|
|
"""The ID of the object"""
|
|
|
|
id: ID!
|
|
|
|
}
|
2016-08-14 09:00:25 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
type ShipConnection {
|
|
|
|
"""Pagination data for this connection."""
|
|
|
|
pageInfo: PageInfo!
|
|
|
|
|
|
|
|
"""Contains the nodes in this connection."""
|
|
|
|
edges: [ShipEdge]!
|
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
|
|
|
The Relay compliant `PageInfo` type, containing data necessary to paginate this connection.
|
|
|
|
"""
|
|
|
|
type PageInfo {
|
|
|
|
"""When paginating forwards, are there more items?"""
|
|
|
|
hasNextPage: Boolean!
|
|
|
|
|
|
|
|
"""When paginating backwards, are there more items?"""
|
|
|
|
hasPreviousPage: Boolean!
|
|
|
|
|
|
|
|
"""When paginating backwards, the cursor to continue."""
|
|
|
|
startCursor: String
|
|
|
|
|
|
|
|
"""When paginating forwards, the cursor to continue."""
|
|
|
|
endCursor: String
|
|
|
|
}
|
2016-08-14 09:00:25 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
"""A Relay edge containing a `Ship` and its cursor."""
|
|
|
|
type ShipEdge {
|
|
|
|
"""The item at the end of the edge"""
|
|
|
|
node: Ship
|
|
|
|
|
|
|
|
"""A cursor for use in pagination"""
|
|
|
|
cursor: String!
|
|
|
|
}
|
|
|
|
|
|
|
|
"""A ship in the Star Wars saga"""
|
|
|
|
type Ship implements Node {
|
|
|
|
"""The ID of the object"""
|
|
|
|
id: ID!
|
|
|
|
|
|
|
|
"""The name of the ship."""
|
|
|
|
name: String
|
|
|
|
}
|
|
|
|
|
|
|
|
type Mutation {
|
|
|
|
introduceShip(input: IntroduceShipInput!): IntroduceShipPayload
|
|
|
|
}
|
|
|
|
|
|
|
|
type IntroduceShipPayload {
|
|
|
|
ship: Ship
|
|
|
|
faction: Faction
|
|
|
|
clientMutationId: String
|
|
|
|
}
|
|
|
|
|
|
|
|
input IntroduceShipInput {
|
|
|
|
shipName: String!
|
|
|
|
factionId: String!
|
|
|
|
clientMutationId: String
|
|
|
|
}'''
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_correctly_fetches_id_name_rebels():
|
|
|
|
result = client.execute("""
|
2015-09-26 09:25:10 +03:00
|
|
|
query RebelsQuery {
|
|
|
|
rebels {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 12:49:26 +03:00
|
|
|
""")
|
|
|
|
assert result == {
|
|
|
|
"data": {
|
|
|
|
"rebels": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"}
|
|
|
|
}
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
def test_correctly_refetches_rebels():
|
|
|
|
result = client.execute("""
|
2015-09-26 09:25:10 +03:00
|
|
|
query RebelsRefetchQuery {
|
|
|
|
node(id: "RmFjdGlvbjox") {
|
|
|
|
id
|
|
|
|
... on Faction {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 12:49:26 +03:00
|
|
|
""")
|
|
|
|
assert result == {
|
|
|
|
"data": {
|
|
|
|
"node": {"id": "RmFjdGlvbjox", "name": "Alliance to Restore the Republic"}
|
|
|
|
}
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
def test_correctly_fetches_id_name_empire():
|
|
|
|
result = client.execute("""
|
2015-09-26 09:25:10 +03:00
|
|
|
query EmpireQuery {
|
|
|
|
empire {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 12:49:26 +03:00
|
|
|
""")
|
|
|
|
assert result == {
|
|
|
|
"data": {"empire": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}}
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
def test_correctly_refetches_empire():
|
|
|
|
result = client.execute("""
|
2015-09-26 09:25:10 +03:00
|
|
|
query EmpireRefetchQuery {
|
|
|
|
node(id: "RmFjdGlvbjoy") {
|
|
|
|
id
|
|
|
|
... on Faction {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 12:49:26 +03:00
|
|
|
""")
|
|
|
|
assert result == {
|
|
|
|
"data": {"node": {"id": "RmFjdGlvbjoy", "name": "Galactic Empire"}}
|
|
|
|
}
|
2015-09-26 09:25:10 +03:00
|
|
|
|
2015-10-03 08:17:51 +03:00
|
|
|
|
2024-08-08 12:49:26 +03:00
|
|
|
def test_correctly_refetches_xwing():
|
|
|
|
result = client.execute("""
|
2015-09-26 09:25:10 +03:00
|
|
|
query XWingRefetchQuery {
|
|
|
|
node(id: "U2hpcDox") {
|
|
|
|
id
|
|
|
|
... on Ship {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-08 12:49:26 +03:00
|
|
|
""")
|
|
|
|
assert result == {"data": {"node": {"id": "U2hpcDox", "name": "X-Wing"}}}
|