def test_submit_trump_not_bid_winner(app, patch_geventws): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/kitty' page is requested (GET) THEN check that the response contains the expected information """ game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4) # Set all to bidding play_pinochle.set_players_bidding(player_ids) # Submit a valid bid for one player winner = choice(player_ids) play_pinochle.submit_bid(round_id, winner, 21) # Set three to pass, meaning one wins the bid. player_list = [x for x in player_ids if x != winner] # This didn't work: # map(lambda x: play_pinochle.submit_bid(round_id, x, -1), player_list) for item in player_list: play_pinochle.submit_bid(round_id, item, -1) assert len(play_pinochle.players_still_bidding(round_id)) == 1 a_round = utils.query_round(round_id) with pytest.raises(exceptions.Conflict): play_pinochle.set_trump(round_id, choice(player_list), "diamond") play_pinochle.set_trump(round_id, winner, "spade") a_round = utils.query_round(round_id) assert a_round.bid == 21 assert a_round.trump == "spade"
def test_set_trump_invalid_player(app): """ GIVEN a Flask application configured for testing WHEN the '/api/play/{round_id}/submit_bid' page is requested (PUT) THEN check that the response contains the expected information """ # Create a new game game_id = test_utils.create_game(kitty_size=0) # Create a new round round_id = test_utils.create_round(game_id) # Create new players trump = choice(SUITS) player_id = str(uuid.uuid4()) round_.update(round_id, {"bid_winner": uuid.uuid4()}) with app.test_client() as test_client: # Attempt to access the get round api response = test_client.put( f"/api/play/{round_id}/set_trump?player_id={player_id}&trump={trump}" ) assert response.status == "404 NOT FOUND" response_str = response.get_data(as_text=True) assert "not found" in response_str # Verify the database is unchanged temp_round = utils.query_round(round_id) assert temp_round.trump == "NONE" print(f"trump={temp_round.trump}")
def test_set_trump_bad_suit(app): """ GIVEN a Flask application configured for testing WHEN the '/api/play/{round_id}/submit_bid' page is requested (PUT) THEN check that the response contains the expected information """ # Create a new game game_id = test_utils.create_game(kitty_size=0) # Create a new round round_id = test_utils.create_round(game_id) # Create new players player_ids = [] for __ in range(len(test_utils.PLAYER_NAMES)): player_id = test_utils.create_player(choice(test_utils.PLAYER_NAMES)) player_ids.append(player_id) # Populate the bid trump = "Unics" player_id = choice(player_ids) round_.update(round_id, {"bid_winner": player_id}) with app.test_client() as test_client: # Attempt to access the get round api response = test_client.put( f"/api/play/{round_id}/set_trump?player_id={player_id}&trump={trump}" ) assert response.status == "409 CONFLICT" response_str = response.get_data(as_text=True) assert "Clubs" in response_str # Verify the database is unchanged temp_round = utils.query_round(round_id) assert temp_round.trump == "NONE" print(f"trump={temp_round.trump}")
def test_update_bid_invalid_player(app): """ GIVEN a Flask application configured for testing WHEN the '/api/play/{round_id}/submit_bid' page is requested (PUT) THEN check that the response contains the expected information """ # Create a new game game_id = test_utils.create_game(kitty_size=0) # Create a new round round_id = test_utils.create_round(game_id) # Create new players bid = 21 player_id = str(uuid.uuid4()) with app.test_client() as test_client: # Attempt to access the get round api response = test_client.put( f"/api/play/{round_id}/submit_bid?player_id={player_id}&bid={bid}") assert response.status == "404 NOT FOUND" response_str = response.get_data(as_text=True) assert "Player" in response_str and "not found" in response_str # Verify the database is unchanged temp_round = utils.query_round(round_id) assert temp_round.bid == 20 assert temp_round.bid_winner is None print(f"score={temp_round.bid}")
def test_player_bid_submission(app, patch_geventws): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/kitty' page is requested (GET) THEN check that the response contains the expected information """ game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4) # Set all to bidding play_pinochle.set_players_bidding(player_ids) # Submit a bid play_pinochle.submit_bid(round_id, choice(player_ids), 21) player_list = play_pinochle.players_still_bidding(round_id) assert len(player_list) == 4 # One player passes play_pinochle.submit_bid(round_id, choice(player_list), -1) player_list = play_pinochle.players_still_bidding(round_id) assert len(player_list) == 3 # Another player passes play_pinochle.submit_bid(round_id, choice(player_list), -1) player_list = play_pinochle.players_still_bidding(round_id) assert len(player_list) == 2 # Last player passes play_pinochle.submit_bid(round_id, choice(player_list), -1) player_list = play_pinochle.players_still_bidding(round_id) assert len(player_list) == 1 a_game = utils.query_game(game_id) a_round = utils.query_round(round_id) assert a_game.state == 1 assert a_round.bid == 21 assert str(a_round.bid_winner) == player_list[0]
def test_update_bid_low(app): """ GIVEN a Flask application configured for testing WHEN the '/api/play/{round_id}/submit_bid' page is requested (PUT) THEN check that the response contains the expected information """ # Create a new game game_id = test_utils.create_game(kitty_size=0) # Create a new round round_id = test_utils.create_round(game_id) # Create new players player_ids = [] for __ in range(len(test_utils.PLAYER_NAMES)): player_id = test_utils.create_player(choice(test_utils.PLAYER_NAMES)) player_ids.append(player_id) player.update(player_id, {"bidding": True}) # Create a new team team_ids = [] for __ in range(len(test_utils.TEAM_NAMES)): team_id = test_utils.create_team(choice(test_utils.TEAM_NAMES)) team_ids.append(team_id) # Join the player to the team. for idx, player_id in enumerate(player_ids): test_utils.create_teamplayer(team_ids[idx % 2], player_id) # Join the teams to the round. test_utils.create_roundteam(round_id, team_ids) # Set the first dealer # Maybe... temp_list = utils.query_player_ids_for_round(round_id) assert len(temp_list) == 4 # Populate the bid bid = -2 player_id = choice(player_ids) with app.test_client() as test_client: # Attempt to access the get round api response = test_client.put( f"/api/play/{round_id}/submit_bid?player_id={player_id}&bid={bid}" ) assert response.status == "409 CONFLICT" response_str = response.get_data(as_text=True) assert "low" in response_str # Verify the database is unchanged temp_round = utils.query_round(round_id) assert temp_round.bid == 20 assert temp_round.bid_winner is None print(f"score={temp_round.bid}")
def test_deal_to_players_w_kitty(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/kitty' page is requested (GET) THEN check that the response contains the expected information """ game_id, round_id, team_ids, player_ids = test_utils.setup_complete_game(4) # Retrieve the round's kitty hand round_info = utils.query_round(round_id=round_id) kitty_hand = str(round_info.hand_id) # Deal the cards play_pinochle.deal_pinochle(player_ids=player_ids, kitty_len=4, kitty_id=kitty_hand) # Inspect the results. kitty_cards = utils.query_hand_list(kitty_hand) assert len(kitty_cards) == 4 for __, p_id in enumerate(player_ids): temp_player = utils.query_player(p_id) cards = utils.query_hand_list(temp_player.hand_id) assert len(cards) == 11