コード例 #1
0
    async def test_send(self):
        message = dict(message='message')
        socket = SocketMock()
        client = ClientConnection(None, socket)
        await client.send(message)

        self.assertIn(message, socket.sent_messages)
コード例 #2
0
def create_group(size=__default_size__):
    clients = list()
    for i in range(size):
        socket = SocketMock()
        client = ClientConnection(i, socket)
        clients.append(client)
    return ConnectionGroup(clients)
コード例 #3
0
    async def test_receive(self):
        message = dict(message='message')
        socket = SocketMock()
        socket.received_messages.append(message)
        client = ClientConnection(None, socket)
        received_message = await client.receive()

        self.assertEqual(message, received_message)
コード例 #4
0
    def test_is_closed_retrieves_socket_state(self):
        socket = SocketMock()
        client = ClientConnection(None, socket)

        socket.closed = True
        self.assertTrue(client.is_connected)

        socket.closed = False
        self.assertFalse(client.is_connected)
コード例 #5
0
    def test_equality_defined_by_type_and_id(self):

        class Dummy(object):
            def __init__(self, _id):
                self._id = _id

        id_a = 'a'
        id_b = 'b'
        socket_a = SocketMock()
        socket_b = SocketMock()

        client_a = ClientConnection(id_a, socket_a)
        client_b = ClientConnection(id_b, socket_b)
        client_c = ClientConnection(id_a, socket_b)
        dummy = Dummy(id_a)

        self.assertEqual(client_a, client_c)
        self.assertNotEqual(client_b, client_c)
        self.assertNotEqual(client_a, dummy)
コード例 #6
0
    def test_raises_exception_when_trying_to_send_message_with_closed_socket(self):
        @run_async
        async def invoke_send():
            return await client.send(message)

        socket = SocketMock()
        socket.closed = True
        client = ClientConnection(None, socket)
        message = dict()

        self.assertRaises(IOError, invoke_send)
コード例 #7
0
ファイル: match_view.py プロジェクト: pitzer42/micro-tcg
async def enter_waiting_list(*args,
                             socket=None,
                             user=None,
                             waiting_list=None,
                             game_loop=None,
                             **kwargs):
    try:
        user_name = user[User.__name_attr__]
        client = ClientConnection(user_name, socket)
        ack = dict(message='you are now in the waiting list', status=200)
        await client.send(ack)
        await play_next_match(client, waiting_list, game_loop)
    except IOError as e:
        print(e)
    return socket
コード例 #8
0
 def append(self, item: ClientConnection):
     if not isinstance(item, ClientConnection):
         raise TypeError(
             'ConnectionGroup only accept ClientConnection as members')
     item.group = self
     list.append(self, item)