graphene/tests/starwars_relay/data.py

103 lines
1.6 KiB
Python
Raw Normal View History

2015-09-26 09:25:10 +03:00
from collections import namedtuple
2015-10-03 08:17:51 +03:00
Ship = namedtuple('Ship', ['id', 'name'])
Faction = namedtuple('Faction', ['id', 'name', 'ships'])
2015-09-26 09:25:10 +03:00
xwing = Ship(
id='1',
name='X-Wing',
)
ywing = Ship(
id='2',
name='Y-Wing',
)
awing = Ship(
id='3',
name='A-Wing',
)
# Yeah, technically it's Corellian. But it flew in the service of the rebels,
# so for the purposes of this demo it's a rebel ship.
falcon = Ship(
id='4',
name='Millenium Falcon',
)
homeOne = Ship(
id='5',
name='Home One',
)
tieFighter = Ship(
id='6',
name='TIE Fighter',
)
tieInterceptor = Ship(
id='7',
name='TIE Interceptor',
)
executor = Ship(
id='8',
name='Executor',
)
rebels = Faction(
id='1',
name='Alliance to Restore the Republic',
ships=['1', '2', '3', '4', '5']
)
empire = Faction(
id='2',
name='Galactic Empire',
2015-10-03 08:17:51 +03:00
ships=['6', '7', '8']
2015-09-26 09:25:10 +03:00
)
data = {
'Faction': {
'1': rebels,
'2': empire
},
'Ship': {
'1': xwing,
'2': ywing,
'3': awing,
'4': falcon,
'5': homeOne,
'6': tieFighter,
'7': tieInterceptor,
'8': executor
}
}
2015-10-03 08:17:51 +03:00
2015-09-26 09:25:10 +03:00
def createShip(shipName, factionId):
nextShip = len(data['Ship'].keys())+1
newShip = Ship(
id=str(nextShip),
name=shipName
)
data['Ship'][newShip.id] = newShip
data['Faction'][factionId].ships.append(newShip.id)
return newShip
def getShip(_id):
return data['Ship'][_id]
2015-10-03 08:17:51 +03:00
2015-09-26 09:25:10 +03:00
def getFaction(_id):
return data['Faction'][_id]
2015-10-03 08:17:51 +03:00
2015-09-26 09:25:10 +03:00
def getRebels():
return rebels
2015-10-03 08:17:51 +03:00
2015-09-26 09:25:10 +03:00
def getEmpire():
return empire