コード例 #1
0
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
コード例 #2
0
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']}
コード例 #3
0
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']
コード例 #4
0
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']}
コード例 #5
0
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}']
        }
    }
コード例 #6
0
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