def test_gamelist_new(client): game_ids = [o[0] for o in Game.select(Game.id).tuples()] db_wrapper.database.close() resp = client.post('/games') assert resp.status_code == 201 data = resp.json assert data['id'] not in game_ids
def test_roundslist_post(client): expected_game = Game.select()[:1][0] db_wrapper.database.close() req = {'hand': ['GREEN', 'BLUE', 'YELLOW', 'MAGENTA']} resp = client.post( f"/games/{expected_game.id}/rounds", data=json.dumps(req), content_type='application/json', ) assert resp.status_code == 201 data = resp.json assert data == {'answer': ['BLACK', 'BLACK', 'WHITE']}
def test_gamesdetail_get(client): game_id = Game.select(Game.id).tuples()[0][0] db_wrapper.database.close() resp = client.get(f'/games/{game_id}') assert resp.status_code == 200 data = resp.json game = data['game'] assert game['id'] == game_id rounds = game['rounds_chrono'] assert len(rounds) == 2 # TODO add date modified to serializer and do a more robust check # slopy check for desc order assert rounds[0]['id'] > rounds[1]['id']
def test_roundslist_post_win(client): expected_game = Game.select()[:1][0] db_wrapper.database.close() # should be case insensitive req = {'hand': ['GREEN', 'BLUE', 'cyan', 'yellow']} resp = client.post( f"/games/{expected_game.id}/rounds", data=json.dumps(req), content_type='application/json', ) assert resp.status_code == 201 data = resp.json # win condition assert data == {'answer': ['BLACK', 'BLACK', 'BLACK', 'BLACK']}
def test_roundslist_post_wrong_game(client): # fetch a finished game expected_game = Game.select().where(Game.over == True)[:1][0] db_wrapper.database.close() req = {'hand': None} resp = client.post( f"/games/{expected_game.id}/rounds", data=json.dumps(req), content_type='application/json', ) assert resp.status_code == 400 data = resp.json assert data == { 'errors': { 'game': [f'No such open game: {expected_game.id}'] } }
def test_roundslist_post_win_edge(client): expected_game = Game.select()[:1][0] # we have 2 rounds from conftest, make it so that the game ends on next round expected_game.num_rounds = 3 expected_game.save() db_wrapper.database.close() # should be case insensitive # win combination req = {'hand': ['GREEN', 'BLUE', 'cyan', 'yellow']} resp = client.post( f"/games/{expected_game.id}/rounds", data=json.dumps(req), content_type='application/json', ) assert resp.status_code == 201 data = resp.json # win condition assert data == {'answer': ['BLACK', 'BLACK', 'BLACK', 'BLACK']} game = Game.get(Game.id == expected_game.id) assert game.over