コード例 #1
0
def test_roundteam_readall_empty(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round/{round_id}/{team_id}' page is requested (GET)
    THEN check that the response contains the expected information
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    # Create a new round
    round_id = str(uuid.uuid4())

    # Create a new teams
    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])

    # Verify the association was created in the database.
    with pytest.raises(exceptions.NotFound):
        roundteams.read(round_id=round_id, team_id=team_id)

    with app.test_client() as test_client:
        # Attempt to access the readall roundteam api
        test_client.get(f"/api/round/{round_id}/{team_id}")

    # Verify the database agrees.
    db_response = roundteams.read_all()
    assert db_response == []
コード例 #2
0
def test_players_read_all_empty(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/player' page is requested (GET)
    THEN check that the response contains the expected information
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    with app.test_client() as test_client:
        # Attempt to access the read player api
        response = test_client.get("/api/player")
        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)
        assert len(response_data) == 0

        for response_item in response_data:
            player_uuid = response_item.get("player_id")
            assert player_uuid is None

            # Verify the database agrees.
            db_response = player.read_one(player_uuid)
            assert db_response is None
            assert player_uuid == db_response.get("player_id")
コード例 #3
0
def test_players_read_all(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/player' page is requested (GET)
    THEN check that the response contains the expected information
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    player_ids = {}
    # Create a new player
    for player_name in test_utils.PLAYER_NAMES:
        # Create a new game
        db_response, status = player.create({"name": player_name})
        assert status == 201
        assert db_response is not None
        player_id = db_response.get("player_id")
        assert test_utils.UUID_REGEX.match(player_id)
        player_ids[player_id] = player_name

    with app.test_client() as test_client:
        # Attempt to access the read player api
        response = test_client.get("/api/player")
        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)
        assert len(test_utils.PLAYER_NAMES) == len(response_data)

        for response_item in response_data:
            player_uuid = response_item.get("player_id")
            assert player_uuid is not None
            assert player_uuid != ""
            assert player_uuid in list(player_ids.keys())
            player_name = response_item.get("name")
            assert player_name is not None
            assert player_name != ""
            assert player_name in list(player_ids.values())

            # Verify the database agrees.
            db_response = player.read_one(player_uuid)
            assert db_response is not None
            assert player_uuid == db_response.get("player_id")
            assert db_response.get("meld_score") == 0
            assert player_name == db_response.get("name")
コード例 #4
0
def test_round_read_all(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round' page is requested (GET)
    THEN check that the response is a list of UUID and contains the expected information
    """
    create_games = 2

    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    game_ids = []
    round_ids = []
    for _ in range(create_games):
        # Create a new game
        game_id = test_utils.create_game(4)
        game_ids.append(game_id)

        for _ in range(create_games):
            # Create a new round
            round_id = test_utils.create_round(game_id)
            round_ids.append(round_id)
    assert len(game_ids) == create_games
    assert len(round_ids) == create_games * 2

    with app.test_client() as test_client:
        # Attempt to access the GET game api
        response = test_client.get("/api/round")
        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  # List of dicts
        assert len(r_round_id) >= create_games
        for item in r_round_id:
            assert item["round_id"] != ""
            assert item["round_id"] in round_ids
            assert test_utils.UUID_REGEX.match(item.get("round_id"))

    # Verify the database agrees.
    db_response = round_.read_all()  # List of dicts
    assert db_response is not None
    for item in db_response:
        assert item["round_id"] in round_ids
コード例 #5
0
def test_roundteam_readall(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round/{round_id}/{team_id}' page is requested (GET)
    THEN check that the response contains the expected information
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    # Create a new game
    game_id = test_utils.create_game(4)

    # Create a new round
    round_id = test_utils.create_round(game_id)

    # Create a new teams
    team_ids = []
    for __ in range(2):
        team_id = test_utils.create_team(choice(test_utils.TEAM_NAMES))
        team_ids.append(team_id)

    # Create the roundteam association for the teams.
    roundteams.create(round_id=round_id, teams=team_ids)

    # Verify the association was created in the database.
    db_response = roundteams.read(round_id=round_id, team_id=team_id)
    assert db_response is not None

    with app.test_client() as test_client:
        # Attempt to access the readall roundteam api
        response = test_client.get(f"/api/round/{round_id}/{team_id}")
        assert response.status == "200 OK"

    # Verify the database agrees.
    db_response = roundteams.read_all()
    team_hand = None
    assert db_response is not None
    for item in db_response:
        assert round_id == item["round_id"]
        assert item["team_id"] in team_ids
        if team_hand is None:
            team_hand = item["hand_id"]
        else:
            assert team_hand != item["hand_id"]
コード例 #6
0
def test_round_read_all_empty(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/round' page is requested (GET)
    THEN check that the response is a list of UUID and contains the expected information
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    with app.test_client() as test_client:
        # Attempt to access the GET game api
        response = test_client.get("/api/round")
        assert response.status == "404 NOT FOUND"

    # Verify the database agrees.
    with pytest.raises(exceptions.NotFound):
        round_.read_all()  # List of dicts
コード例 #7
0
def test_game_read_all_empty(app):
    """
    GIVEN a Flask application configured for testing
    WHEN the '/api/game/{game_id}' page is requested (GET)
    THEN check that the response is empty
    """
    # Clear out ALL previous test data.
    db.drop_all()
    db.create_all()

    with app.test_client() as test_client:
        # Attempt to access the create round api
        response = test_client.get("/api/game")
        assert response.status == "200 OK"
        assert response.get_data(as_text=True) == "[]\n"

    # Verify the database agrees.
    db_response = game.read_all()
    assert db_response is not None
    assert db_response == []