Ejemplo n.º 1
0
def toggle(current_user, id):
    """
   Toggle a cell's status
   swagger_from_file: src/swagger/game_toggle_cell.yml
   """
    data = request.get_json(silent=True)
    schema = CellAction()
    try:
        game = find_game(current_user.id, id)
        service = GameService(game)
    except GameNotFoundException as gnf:
        return jsonify({"message": str(gnf)}), 404

    try:
        coords = schema.load(data)
    except ValidationError as err:
        return jsonify(err.messages), 400

    try:
        service.toggle(coords["row"], coords["column"])
        update_game(current_user.id, id, service.game)
    except InvalidClearException as exc:
        return jsonify({"message": str(exc)}), 400

    return jsonify(service.encode_game_info())
Ejemplo n.º 2
0
def test_toggle_uncovered_cell_should_do_nothing():
    service = GameService(get_mock_game())
    service.start_game(1, 10, 10, 20)

    board = service.game.board

    board[0][0]["value"] = 0
    service.clear(0, 0)
    assert board[0][0]["status"] == "U"
    service.toggle(0, 0)
    assert board[0][0]["status"] == "U"
Ejemplo n.º 3
0
def test_toggle_covered_cell():
    service = GameService(get_mock_game())
    service.start_game(1, 10, 10, 20)

    board = service.game.board

    assert board[0][0]["status"] == "C"
    service.toggle(0, 0)
    assert board[0][0]["status"] == "F"
    service.toggle(0, 0)
    assert board[0][0]["status"] == "?"
    service.toggle(0, 0)
    assert board[0][0]["status"] == "C"

    board[0][0]["value"] = 0
    service.clear