Пример #1
0
def test_unicode_privmsg():
    """
    Ensure the client can send unicode and also receives unicode.
    """
    TEST_STRING = u'± äöü @ o ↑↑↓↓←→←→BA コナミコマンド'

    client1 = ProtocolClient(
        unique_identity(), 'localhost', plugins=[
            HandshakePlugin,
            LogPlugin(),
            ProtocolPlugin()
        ]
    )

    client2 = ProtocolClient(
        unique_identity(), 'localhost', plugins=[
            HandshakePlugin,
            LogPlugin(),
            ProtocolPlugin()
        ]
    )

    class Container(object):
        pass
    got_message = Container()
    got_message.value = False

    def on_376(client, prefix, target, args):
        client.join_channel('#test')

    def on_join(client, prefix, target, args):
        client.privmsg('#test', TEST_STRING)

    def on_privmsg(client, prefix, target, args):
        got_message.value = (args[0] == TEST_STRING)
        client1.terminate()
        client2.terminate()

    signals.m.on_376.connect(on_376, sender=client1)
    signals.m.on_376.connect(on_376, sender=client2)
    signals.m.on_JOIN.connect(on_join, sender=client1)
    signals.m.on_PRIVMSG.connect(on_privmsg, sender=client2)

    assert(client1.connect().get() is True)
    assert(client2.connect().get() is True)

    client1._io_workers.join(timeout=5)
    client2._io_workers.join(timeout=5)

    assert(got_message.value)
Пример #2
0
def test_disconnect_event():
    """
    Ensure on_disconnect() is triggered on terminate().
    """
    identity = unique_identity()

    class ConnectPlugin(object):
        def __init__(self):
            self.got_connect = False
            self.got_disconnect = False

        def bind(self, client):
            signals.on_connect.connect(self.connected, sender=client)
            signals.on_disconnect.connect(self.disconnected, sender=client)

        def connected(self, client):
            self.got_connect = True

        def disconnected(self, client):
            self.got_disconnect = True

    connect_plugin = ConnectPlugin()

    client = CoreClient(identity, 'localhost', plugins=[connect_plugin])
    result = client.connect()
    assert(result.get() is True)

    client.terminate()
    assert(connect_plugin.got_connect)
    assert(connect_plugin.got_disconnect)
Пример #3
0
def test_connect_success():
    """
    Ensure a basic connection can be successfully created.
    """
    identity = unique_identity()
    client = CoreClient(identity, 'localhost')
    result = client.connect()
    assert(result.get() is True)
Пример #4
0
def test_handshake_success():
    """
    Ensure the handshake works when configured properly.
    """
    identity = unique_identity()

    rec_plugin = RecPlugin(terminate_on=('001',))

    client = CoreClient(identity, 'localhost', plugins=[
        HandshakePlugin,
        rec_plugin
    ])

    result = client.connect()
    assert(result.get() is True)

    client._io_workers.join(timeout=5)
    assert(rec_plugin.did_receive('001'))