Beispiel #1
0
def test_unpack_and_execute():
    cmd = CmdHello("world")
    data = pickle.dumps(cmd)

    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)
    message_name, ret = server.unpack_and_execute(data)

    assert message_name == "CmdHello"
    assert ret == "hello world"
Beispiel #2
0
def test_unpack_and_execute():
    cmd = CmdHello("world")
    data = pickle.dumps(cmd)

    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)
    message_name, ret = server.unpack_and_execute(data)

    assert message_name == "CmdHello"
    assert ret == "hello world"
Beispiel #3
0
def test_base_server():

    # server
    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)

    holder = {'hello': ""}

    def sayHello():
        holder['hello'] = "world"

    server.register_start_function(sayHello)

    def server_thread():
        server.run()

    t = threading.Thread(target=server_thread)
    t.start()

    sleep(4)
    # client
    try:
        ret = client.send_message((HOST, PORT), CmdHello("world"))
        assert ret == "hello world"

        client.sendonly_message((HOST, PORT), CmdHello("world"))

    finally:
        server.shutdown()

    assert holder["hello"] == "world"
Beispiel #4
0
def test_unregister_handle_function():
    server = BaseServer(HOST, PORT)
    server.register_handle_function("helloworld", helloworld)
    assert server.handle_functions["helloworld"]() == "hello"

    server.unregister_handle_function("helloworld")
    assert server.handle_functions.has_key("helloworld") == False

    server.unregister_handle_function(
        "helloworld")  # this should not raise exception
Beispiel #5
0
def test_base_server():

    # server
    server = BaseServer(HOST, PORT)
    server.register_handle_function("CmdHello", hello)

    holder = {'hello': ""}
    def sayHello():
        holder['hello'] = "world"

    server.register_start_function(sayHello)
    def server_thread():
        server.run()

    t = threading.Thread(target = server_thread)
    t.start()

    sleep(4)
    # client
    try:
        ret = client.send_message((HOST, PORT), CmdHello("world"))
        assert ret == "hello world"

        client.sendonly_message((HOST, PORT), CmdHello("world"))

    finally:
        server.shutdown()

    assert holder["hello"] == "world"
Beispiel #6
0
def test_unregister_handle_function():
    server = BaseServer(HOST, PORT)
    server.register_handle_function("helloworld", helloworld)
    assert server.handle_functions["helloworld"]() == "hello"

    server.unregister_handle_function("helloworld")
    assert server.handle_functions.has_key("helloworld") == False

    server.unregister_handle_function("helloworld") # this should not raise exception
Beispiel #7
0
def test_register_handle_funtion():
    server = BaseServer(HOST, PORT)
    server.register_handle_function("helloworld", helloworld)
    assert server.handle_functions["helloworld"]() == "hello"
Beispiel #8
0
def test_register_handle_funtion():
    server = BaseServer(HOST, PORT)
    server.register_handle_function("helloworld", helloworld)
    assert server.handle_functions["helloworld"]() == "hello"