예제 #1
0
def test_make_move_fail_game_is_done():
    game = {'id': 'foo-bar', 'status': 'done'}

    with pytest.raises(InvalidMove) as e:
        make_move(game, {})

    assert str(
        e.value) == (f'Game ID ({game["id"]}) is not in progress anymore, '
                     f'current status is ({game["status"]})!')
예제 #2
0
def test_make_move_fail_wrong_player():
    game = {'status': 'in_progress', 'next_player_number': 1}
    move = {'player_number': 2}

    with pytest.raises(InvalidMove) as e:
        make_move(game, move)

    assert str(e.value) == (
        f'Expecting player number ({game["next_player_number"]}) to make a '
        f'move but found player number ({move["player_number"]}) instead!')
예제 #3
0
def create_move(store: Storage, game_id: str, body) -> Tuple[Dict, int]:
    try:
        game = store.get_game(game_id)
        game = logic.make_move(game, body)
        return store.set_game(game), 201
    except logic.InvalidMove as e:
        return _http_error(400, str(e))
    except GameNotFound as e:
        return _http_error(404, str(e))
예제 #4
0
def test_make_move_fail_tile_used_before():
    game = {
        'status':
        'in_progress',
        'next_player_number':
        1,
        'moves': [{
            'player_number': 1,
            'tile_number': 5
        }, {
            'player_number': 2,
            'tile_number': 3
        }]
    }
    move = {'player_number': 1, 'tile_number': 5}

    with pytest.raises(InvalidMove) as e:
        make_move(game, move)

    assert str(
        e.value) == f'Tile number ({move["tile_number"]}) was already played!'
예제 #5
0
def test_make_move_success_inserted():
    game = {
        'status':
        'in_progress',
        'next_player_number':
        1,
        'moves': [{
            'player_number': 1,
            'tile_number': 5
        }, {
            'player_number': 2,
            'tile_number': 3
        }]
    }
    move = {'player_number': 1, 'tile_number': 6}

    game = make_move(game, move)

    assert game['last_update_time'] == move['create_time']
    assert len(game['moves']) == 3
    assert move in game['moves']
    assert game['next_player_number'] == 2