コード例 #1
0
ファイル: test_server.py プロジェクト: bdvllrs/any-board-game
async def test_create_and_join_round(aiohttp_client, loop):
    app = make_app(sample_game_folder)
    client = await aiohttp_client(app)
    game_name = "bataille"
    usernames = ["test1", "test2", "test3"]
    response = await client.post(f"/round/create/{game_name}",
                                 json=dict(username=usernames[0]))
    response_data = await response.json()
    assert response_data['createdBy'] == usernames[0]
    assert response_data['id'] in client.app['games']

    # player 2 connects
    response_player2 = await client.get(f"/round/{response_data['id']}/join",
                                        params=dict(username=usernames[1]))

    response_data_player2 = await response_player2.json()
    assert response_data_player2['gameId'] == response_data['gameId']

    async with client.ws_connect(
            f"/round/{response_data['id']}/join?playerId={response_data['playerId']}"
    ) as ws:
        async for msg in ws:
            if msg.type == aiohttp.WSMsgType.TEXT:
                assert msg.json()['type'] == 'PLAYER_CONNECTED'
                break
            elif msg.type == aiohttp.WSMsgType.ERROR:
                break
        await ws.send_json({"type": "PING"})
        async for msg in ws:
            if msg.type == aiohttp.WSMsgType.TEXT:
                assert msg.json()['type'] == 'PONG'
                break
            elif msg.type == aiohttp.WSMsgType.ERROR:
                break
コード例 #2
0
ファイル: test_server.py プロジェクト: bdvllrs/any-board-game
async def test_chat_feature(aiohttp_client, loop):
    app = make_app(sample_game_folder)
    usernames = ['player 1', 'player 2']
    round_id, clients, responses = await initialize_start_game(
        app, aiohttp_client, 'bataille', usernames)

    await asyncio.gather(*[
        send_receive_chat(clients[username], round_id, responses[username]
                          ['playerId'], username) for username in usernames
    ])
コード例 #3
0
ファイル: test_server.py プロジェクト: bdvllrs/any-board-game
async def test_game_info(aiohttp_client, loop):
    app = make_app(sample_game_folder)
    client = await aiohttp_client(app)
    response = await client.get("/game/list")
    available_games = await response.json()
    if len(available_games):
        response = await client.get(f"/game/{available_games[0]['gameId']}")
        game = await response.json()
        for key, value in available_games[0].items():
            assert key in game
            assert game[key] == value
コード例 #4
0
ファイル: test_server.py プロジェクト: bdvllrs/any-board-game
async def test_list_games(aiohttp_client, loop):
    app = make_app(sample_game_folder)
    client = await aiohttp_client(app)
    response = await client.get("/game/list")
    response_data = await response.json()
    for game in response_data:
        assert 'gameId' in game
        assert 'description' in game
        assert 'rules' in game
        assert 'min_players' in game
        assert 'max_players' in game
コード例 #5
0
ファイル: test_server.py プロジェクト: bdvllrs/any-board-game
async def test_list_rounds(aiohttp_client, loop):
    app = make_app(sample_game_folder)
    usernames = ["player1", "player2"]
    game_id = "bataille"
    await initialize_start_game(app, aiohttp_client, game_id, usernames,
                                {'public': True})
    client = await aiohttp_client(app)
    response = await client.get("/round/list")
    response_data = await response.json()
    assert type(response_data) == list
    assert len(response_data) == 1
    assert response_data[0]['gameId'] == game_id
    assert response_data[0]['players'] == usernames
コード例 #6
0
async def test_bataille_game(aiohttp_client, loop):
    np.random.seed(0)
    app = make_app(sample_game_folder)

    game_name = "bataille"
    usernames = ["test1", "test2", "test3"]
    round_id, clients, response_data = await initialize_start_game(
        app, aiohttp_client, game_name, usernames)

    await asyncio.gather(*[
        bataille_player(clients[username], round_id, response_data[username]
                        ['playerId'], username == usernames[0])
        for username in usernames
    ])