Ejemplo n.º 1
0
def test_messenger_constructor():
    # port assignment
    mes1 = Messenger()
    assert_equal(mes1.port, 8099)

    mes2 = Messenger(3000)
    assert_equal(mes2.port, 3000)

    # host assignment
    assert_equal(mes1.host, 'localhost')
    assert_equal(mes2.host, 'localhost')

    # socket family and type
    assert_is_instance(mes1.sock, socket.SocketType)
    assert_equal(mes1.sock.type, socket.SOCK_STREAM)
    assert_equal(mes1.sock.family, socket.AF_INET)

    assert_is_instance(mes2.sock, socket.SocketType)
    assert_equal(mes2.sock.type, socket.SOCK_STREAM)
    assert_equal(mes2.sock.family, socket.AF_INET)
Ejemplo n.º 2
0
def test_send_fail():
    """Messenger.send raises error for non connected port"""
    # should raise error when oxd server is not running
    msgr = Messenger(4000)
    with assert_raises(socket.error):
        msgr.send({'command': 'raise_error'})
Ejemplo n.º 3
0
def test_first_connection():
    """Messenger connects deffered until first send"""
    msgr = Messenger()
    assert_false(msgr.firstDone)
    msgr.send({})
    assert_true(msgr.firstDone)
Ejemplo n.º 4
0
def test_send():
    """Messenger.send sends message"""
    msgr = Messenger(8099)
    response = msgr.send({"command": "test"})
    assert response.status