예제 #1
0
def test_disconnect_before_connect(patch_connection, events, run):
    ''' disconnect before connect does nothing '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.disconnect())
    assert not conn.connected
    assert not events.triggered("CLIENT_CONNECT")
    assert not events.triggered("CLIENT_DISCONNECT")
예제 #2
0
def test_connect_already_connected(patch_connection, writer, events, run):
    ''' Does not trigger CLIENT_CONNECT multiple times '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    run(conn.connect())
    assert not writer.closed
    assert events.triggered("CLIENT_CONNECT")
예제 #3
0
def test_connect(patch_connection, writer, events, run):
    ''' Connection.Connect opens a writer, triggers CLIENT_CONNECT '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    assert conn.connected
    assert not writer.closed
    assert events.triggered("CLIENT_CONNECT")
예제 #4
0
def test_read_disconnected(patch_connection, reader, events, run):
    ''' Nothing happens when reading after disconnecting '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    run(conn.disconnect())
    value = run(conn.read())
    assert not value
    assert not reader.used
예제 #5
0
def test_disconnect(writer, patch_connection, events, run):
    ''' Connection.disconnect closes writer, triggers CLIENT_DISCONNECT '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    run(conn.disconnect())
    assert not conn.connected
    assert writer.closed
    assert conn.writer is None
    assert events.triggered("CLIENT_CONNECT")
    assert events.triggered("CLIENT_DISCONNECT")
예제 #6
0
def test_send_disconnected(patch_connection, writer, events, run):
    ''' Nothing happens when sending after disconnecting '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    run(conn.disconnect())
    conn.send("test")
    assert not writer.used
예제 #7
0
def test_send_before_connected(patch_connection, writer, events, run):
    ''' Nothing happens when sending before connecting '''
    conn = Connection("host", "port", events, "UTF-8", True)
    assert not conn.connected
    conn.send("test")
    assert not writer.used
예제 #8
0
def conn(patch_connection, events, run):
    ''' Generic connection that is ready to read/send '''
    conn = Connection("host", "port", events, "UTF-8", True)
    run(conn.connect())
    assert conn.connected
    return conn