Example #1
0
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)
Example #2
0
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
Example #3
0
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
Example #4
0
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)