Ejemplo n.º 1
0
    async def setup(self):
        await self.send_msg(message.Name(name=self.pname))
        g = await self.wait_msg(message.Game)
        ww = []
        for wi in range(0, g.numwords):
            ww.append(NOUNS.get_random_word())

        await self.send_msg(message.Words(words=ww))
Ejemplo n.º 2
0
    async def setup(self):
        await self.send_msg(
            message.Name(name=self.pname,
                         avatar=f'https://robohash.org/{self.pname}'))
        g = await self.wait_msg(message.Game)
        ww = []
        for wi in range(0, g.numwords):
            ww.append(NOUNS.get_random_word())

        await self.send_msg(message.Words(words=ww))
Ejemplo n.º 3
0
async def test_name_fail_connect():
    g = HatGame()
    m = message.Name(name='test1')
    ws = MockWebSocket()

    for st in (HatGame.ST_PLAY, HatGame.ST_FINISH):
        g.state = st
        await g.name(ws, m)
        e = message.Error(
            code=104,
            message="Can't login new user test1 while game in progress")
        ws.send_json.assert_awaited_once_with(e.data())
        ws.send_json.reset_mock()
Ejemplo n.º 4
0
async def test_name_connect_first():
    g = HatGame()
    m = message.Name(name='test2')
    ws = MockWebSocket()

    g.state = HatGame.ST_SETUP
    await g.name(ws, m)
    print(ws.send_json.await_args_list)
    ws.send_json.assert_has_awaits([
        call(g.game_msg().data()),
        call(message.Prepare(players={
            m.name: 0
        }).data())
    ],
                                   any_order=False)
Ejemplo n.º 5
0
async def test_name_connect_second():
    g = HatGame()
    ws1 = MockWebSocket()
    g.register_player(name="test1", socket=ws1)

    m = message.Name(name='test2')
    ws2 = MockWebSocket()

    g.state = HatGame.ST_SETUP
    await g.name(ws2, m)
    print(ws2.send_json.await_args_list)
    pm = message.Prepare(players={m.name: 0, 'test1': 0})
    ws2.send_json.assert_has_awaits(
        [call(g.game_msg().data()), call(pm.data())], any_order=False)
    ws1.send_json.assert_awaited_once_with(pm.data())