Ejemplo n.º 1
0
def test_round_score_meld_bad_hand(app, patch_ws_messenger):  # pylint: disable=unused-argument
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round/{round_id}/score_hand_meld' page is requested (POST)
    THEN check that the response is successful
    """
    game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4)

    # FIXME: This is pinochle-specific and should be moved to the play_pinochle test.
    play_pinochle.start(round_id=round_id)
    player_id = choice(player_ids)
    # Choose another player so that the cards don't match exactly.
    temp_player_id = choice([x for x in player_ids if x != player_id])
    hand_id = test_utils.query_player_hand_id(player_id=temp_player_id)
    temp_cards = [item.card for item in utils.query_hand_list(hand_id)]
    print(f"round_id={round_id}, player_id={player_id}")
    print(f"player_cards={temp_cards}")
    print(f"temp_cards= {','.join(temp_cards)}")
    cards_str = ",".join(temp_cards)
    with app.test_client() as test_client:
        # Attempt to access the get round api
        response = test_client.get(
            f"/api/round/{round_id}/score_meld?player_id={player_id}&cards={cards_str}"
        )
        assert response.status == "409 CONFLICT"
Ejemplo n.º 2
0
def test_register_new_players_game_bid(app, patch_geventws):  # pylint: disable=unused-argument
    """
    GIVEN a Flask application configured for testing
    WHEN the register_new_player function is called
    THEN check that the response is successful
    """
    game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4)

    ws_mess = WSM()
    ws_mess.client_sockets.clear()
    ws_mess.game_update = game.update
    ws_mess.update_refreshed_page_bid = MagicMock()
    ws_mess.update_refreshed_page_reveal = MagicMock()
    ws_mess.update_refreshed_page_trump = MagicMock()

    dummy_ws = geventwebsocket.websocket.WebSocket(None, None, None)
    play_pinochle.start(round_id)
    test_utils.set_game_state(game_id, 1)
    assert utils.query_game(game_id).state == 1
    ws_mess.register_new_player(game_id, player_ids[0], dummy_ws)
    ws_mess.register_new_player(game_id, player_ids[1], dummy_ws)

    ws_mess.update_refreshed_page_bid.assert_called_with(
        round_id, player_ids[1], dummy_ws)
    ws_mess.update_refreshed_page_reveal.assert_not_called()
    ws_mess.update_refreshed_page_trump.assert_not_called()
Ejemplo n.º 3
0
def test_round_score_meld_hand_no_trump(app, patch_ws_messenger):  # pylint: disable=unused-argument
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round/{round_id}/score_hand_meld' page is requested (POST)
    THEN check that the response is successful
    """
    game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4)

    # FIXME: This is pinochle-specific and should be moved to the play_pinochle test.
    play_pinochle.start(round_id=round_id)
    player_id = choice(player_ids)
    hand_id = test_utils.query_player_hand_id(player_id=player_id)
    temp_cards = [item.card for item in utils.query_hand_list(hand_id)]
    print(f"round_id={round_id}, player_id={player_id}")
    print(f"player_cards={temp_cards}")
    print(f"temp_cards= {','.join(temp_cards)}")
    cards_str = ",".join(temp_cards)
    with app.test_client() as test_client:
        # Attempt to access the get round api
        response = test_client.get(
            f"/api/round/{round_id}/score_meld?player_id={player_id}&cards={cards_str}"
        )
        assert response.status == "200 OK"
        response_str = response.get_data(as_text=True)
        response_data = json.loads(response_str)
        score = response_data.get("score")
        assert "score" in response_str
        assert isinstance(score, int)
        print(f"score={score}")

    # Verify database agrees.
    updated_player = utils.query_player(player_id=player_id)
    print(f"updated_player={updated_player}")
    assert updated_player.meld_score == score