def test_roundkitty_delete_missing(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/kitty' page is requested (DELETE) THEN check that the response is successful """ # Create a new round round_id = str(uuid.uuid4()) # Retrieve the generated hand_id (as a UUID object). hand_id = str(uuid.uuid4()) # Verify the database agrees. db_response = hand.read_one(hand_id) assert db_response is None with app.test_client() as test_client: # Attempt to access the delete round api response = test_client.delete(f"/api/round/{round_id}/kitty") assert response.status == "204 NO CONTENT" # Attempt to retrieve the now-deleted round id response = test_client.get(f"/api/round/{round_id}/kitty") assert response.status == "204 NO CONTENT" assert response.data is not None response_str = response.get_data(as_text=True) assert response_str == "" # Verify the database agrees. db_response = roundkitty.read(round_id) assert db_response is None with pytest.raises(exceptions.NotFound): round_.read_one(round_id)
def test_game_round_delete_missing(app): """ GIVEN a Flask application configured for testing WHEN the '/api/game/{game_id}/{round_id}' page is requested (DELETE) THEN check that the response is successful """ # Create a new game game_id = str(uuid.uuid4()) # Create a new round round_id = str(uuid.uuid4()) with app.test_client() as test_client: # Attempt to access the delete round api response = test_client.delete(f"/api/game/{game_id}/{round_id}") assert response.status == "404 NOT FOUND" # Attempt to retrieve the now-deleted round id response = test_client.get(f"/api/game/{game_id}/{round_id}") assert "404 NOT FOUND" in response.status # Verify the database agrees. with pytest.raises(exceptions.NotFound): round_.read_one(round_id) with pytest.raises(exceptions.NotFound): gameround.read_one(game_id, round_id)
def test_game_round_list(app): """ GIVEN a Flask application configured for testing WHEN the '/api/game/{game_id}/round' page is requested (GET) THEN check that the response is successful """ # Create a new game game_id = str(test_utils.create_game(4)) # Create a new round round_id = test_utils.create_round(game_id) with app.test_client() as test_client: # Attempt to access the get round api response = test_client.get(f"/api/game/{game_id}/round") assert response.status == "200 OK" response_str = response.get_data(as_text=True) response_data = json.loads(response_str) # print(f"response_data={response_data}") # Verify the database agrees. db_response = round_.read_one(round_id) # print(f"db_response={db_response}") db_response = gameround.read_one(game_id, round_id) # print(f"db_response={db_response}") assert response_data == db_response
def test_round_read_one(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}' page is requested (GET) THEN check that the response is a UUID and contains the expected information """ # Create a new game game_id = test_utils.create_game(4) # Create a new round round_id = test_utils.create_round(game_id) with app.test_client() as test_client: # Attempt to access the create round api response = test_client.get(f"/api/round/{round_id}") assert response.status == "200 OK" assert response.get_data(as_text=True) is not None # This is a JSON formatted STRING response_str = response.get_data(as_text=True) response_data = json.loads(response_str) r_round_id = response_data.get("round_id") assert r_round_id != "" assert r_round_id == round_id assert test_utils.UUID_REGEX.match(r_round_id) # Verify the database agrees. db_response = round_.read_one(round_id) assert db_response is not None assert round_id == db_response.get("round_id")
def test_round_create(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round' page is requested (POST) THEN check that the response is a UUID and contains the expected information """ # Create a new game game_id = test_utils.create_game(4) with app.test_client() as test_client: # Attempt to access the create round api response = test_client.post(f"/api/game/{game_id}/round") assert response.status == "201 CREATED" assert response.get_data(as_text=True) is not None # This is a JSON formatted STRING response_str = response.get_data(as_text=True) response_data = json.loads(response_str) round_id = response_data.get("round_id") assert round_id != "" assert test_utils.UUID_REGEX.match(round_id) # Verify the database agrees. db_response = round_.read_one(round_id) assert db_response is not None assert round_id == db_response.get("round_id") assert db_response.get("trump") == "NONE" assert db_response.get("bid_winner") is None assert isinstance(db_response.get("round_seq"), int) assert db_response.get("bid") == 20
def setup_complete_game(kitty_s: int): # Create a new game game_id = str(create_game(kitty_s)) # Create a new round round_id = str(create_round(game_id)) # Verify the database agrees. db_response = round_.read_one(round_id) assert db_response is not None db_response = gameround.read_one(game_id, round_id) assert db_response is not None # Create players player_ids = [] for player_name in PLAYER_NAMES: player_id = create_player(player_name) assert UUID_REGEX.match(player_id) player_ids.append(player_id) # Create a new teams team_ids = [] for item in range(2): team_id = create_team(choice(TEAM_NAMES)) team_ids.append(team_id) teamplayers.create(team_id=team_id, player_id={"player_id": player_ids[item]}) teamplayers.create( team_id=team_id, player_id={"player_id": player_ids[item + 2]} ) # Create the roundteam association for the teams. roundteams.create(round_id=round_id, teams=team_ids) return game_id, round_id, team_ids, player_ids
def test_round_read_one_missing(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}' page is requested (GET) THEN check that the response is a UUID and contains the expected information """ # Create a new round round_id = str(uuid.uuid4()) with app.test_client() as test_client: # Attempt to access the create round api response = test_client.get(f"/api/round/{round_id}") assert response.status == "404 NOT FOUND" # Verify the database agrees. with pytest.raises(exceptions.NotFound): round_.read_one(round_id)
def test_roundkitty_delete(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/kitty' page is requested (DELETE) THEN check that the response is successful """ # Create a new game game_id = test_utils.create_game(4) assert test_utils.UUID_REGEX.match(game_id) # Create a new round round_id = test_utils.create_round(game_id) assert test_utils.UUID_REGEX.match(round_id) # Retrieve the generated hand_id (as a UUID object). hand_uuid = Round.query.filter(Round.round_id == round_id).all() assert hand_uuid is not None assert hand_uuid != [] hand_id = str(hand_uuid[0].hand_id) print(f"round_id={round_id} hand_id={hand_id}") # Populate Hand with cards. for card in test_utils.CARD_LIST: hand.addcard(hand_id, card) # Verify the database agrees. db_response = hand.read_one(hand_id) assert db_response is not None assert hand_id == db_response.get("hand_id") assert db_response.get("cards") == test_utils.CARD_LIST with app.test_client() as test_client: # Attempt to access the delete round api response = test_client.delete(f"/api/round/{round_id}/kitty") assert response.status == "204 NO CONTENT" # Attempt to retrieve the now-deleted round id response = test_client.get(f"/api/round/{round_id}/kitty") assert response.status == "200 OK" assert response.data is not None response_str = response.get_data(as_text=True) response_data = json.loads(response_str) cards = response_data.get("cards") assert cards is not None assert cards == [] # Verify the database agrees. db_response = roundkitty.read(round_id) assert db_response == {"cards": []} db_response = round_.read_one(round_id) assert db_response.get("hand_id") is None
def test_game_round_start_invalid(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/start' page is requested (POST) THEN check that the response is successful """ # Create a new, invalidround round_id = str(uuid.uuid4()) # Verify the database agrees. with pytest.raises(exceptions.NotFound): round_.read_one(round_id) # print(f"db_response={db_response}") # assert db_response is not None with app.test_client() as test_client: # Attempt to access the get round api response = test_client.post(f"/api/round/{round_id}/start") assert response.status == "404 NOT FOUND" response_str = response.get_data(as_text=True) assert f"Round {round_id} not found." in response_str
def test_roundteam_addcard_missing(app): """ GIVEN a Flask application configured for testing WHEN the '/api/round/{round_id}/{team_id}' page is requested (PUT) THEN check that the response contains the expected information """ # Create a new round round_id = str(uuid.uuid4()) # Create a new team team_id = str(uuid.uuid4()) # Create the roundteam association for the teams. with pytest.raises(exceptions.Conflict): roundteams.create(round_id=round_id, teams=[team_id]) with app.test_client() as test_client: # Attempt to access the addcard roundteam api put_data = {} response = test_client.put( f"/api/round/{round_id}/{team_id}?card={choice(test_utils.CARD_LIST)}", data=json.dumps(put_data), content_type="application/json", ) assert response.status == "404 NOT FOUND" # This is a JSON formatted STRING response_str = response.get_data(as_text=True) assert response_str is not None response_data = json.loads(response_str) hand_id = response_data.get("hand_id") assert hand_id is None # Verify the database agrees. with pytest.raises(exceptions.NotFound): round_.read_one(round_id)
def setup_complete_game(kitty_s: int): # Create a new game game_id = str(create_game(kitty_s)) # Create a new round round_id = str(create_round(game_id)) # Verify the database agrees. db_response = round_.read_one(round_id) assert db_response is not None db_response = gameround.read_one(game_id, round_id) assert db_response is not None # Create players player_ids = [] for player_name in PLAYER_NAMES: player_id = create_player(player_name) assert UUID_REGEX.match(player_id) player_ids.append(player_id) # Create a new teams team_ids = [] for item in range(2): team_id = create_team(choice(TEAM_NAMES)) team_ids.append(team_id) teamplayers.create(team_id=team_id, player_id={"player_id": player_ids[item]}) teamplayers.create(team_id=team_id, player_id={"player_id": player_ids[item + 2]}) # Create the roundteam association for the teams. roundteams.create(round_id=round_id, teams=team_ids) # The order expected by the tests is to be the same as the game, which is not the # order from the original list. return game_id, round_id, team_ids, utils.query_player_ids_for_round( round_id)