Beispiel #1
0
def test_ping_WebServer():
    """
    Start services and send Ping to WebServer. Then terminate the WebServer and
    verify that the ping fails.
    """
    # Convenience.
    WSClient = azrael.wsclient.WSClient
    ip, port = config.addr_webserver, config.port_webserver

    # Start the services.
    clerk = azrael.clerk.Clerk()
    web = azrael.web.WebServer()
    clerk.start()
    web.start()

    # Create a Websocket client.
    client = azrael.wsclient.WSClient(ip=ip, port=port, timeout=1)

    # Ping Clerk via WebServer.
    assert client.ping()
    assert client.pingWebserver().ok

    # Terminate the services.
    clerk.terminate()
    web.terminate()
    clerk.join()
    web.join()

    # Ping must now be impossible.
    with pytest.raises(ConnectionRefusedError):
        WSClient(ip=ip, port=port, timeout=1)

    assert not client.pingWebserver().ok
Beispiel #2
0
    def test_custom_objid(self):
        """
        Create two clients. The first automatically gets an ID assigned,
        whereas the second one specifies one explicitly.

        This behaviour matches that of `Client`` but is not automatically
        inherited because the ``WSClient`` is not a client itself but a
        wrapper to communicate with the client instance in WebServer.
        """
        # Start Clerk.
        clerk = azrael.clerk.Clerk()
        clerk.start()

        # Start WebServer.
        web = azrael.web.WebServer()
        web.start()

        # Instantiate a WSClient without specifiying an object ID.
        addr, port = config.azService['webapi']
        client = pyazrael.AzraelWSClient(addr, port, timeout=1)

        # Ping Clerk to verify the connection is live.
        ret = client.ping()
        assert (ret.ok, ret.data) == (True, 'pong clerk')

        # Shutdown the system.
        clerk.terminate()
        web.terminate()
        clerk.join(timeout=3)
        web.join(timeout=3)
Beispiel #3
0
    def test_ping_WebServer(self):
        """
        Start services and send Ping to WebServer. Then terminate the WebServer and
        verify that the ping fails.
        """
        # Convenience.
        addr_webapi, port_webapi = config.azService['webapi']

        # Start the services.
        clerk = azrael.clerk.Clerk()
        web = azrael.web.WebServer()
        clerk.start()
        web.start()

        # Create a Websocket client.
        client = pyazrael.AzraelWSClient(addr_webapi, port_webapi, timeout=1)

        # Ping Clerk via the Web service.
        assert client.ping()
        assert client.pingWebserver().ok

        # Terminate the services.
        clerk.terminate()
        web.terminate()
        clerk.join()
        web.join()

        # Ping must now be impossible.
        with pytest.raises(ConnectionRefusedError):
            pyazrael.AzraelWSClient(addr_webapi, port_webapi, timeout=1)

        assert not client.pingWebserver().ok
Beispiel #4
0
    def test_custom_objid(self):
        """
        Create two clients. The first automatically gets an ID assigned,
        whereas the second one specifies one explicitly.

        This behaviour matches that of `Client`` but is not automatically
        inherited because the ``WSClient`` is not a client itself but a
        wrapper to communicate with the client instance in WebServer.
        """
        # Start Clerk.
        clerk = azrael.clerk.Clerk()
        clerk.start()

        # Start WebServer.
        web = azrael.web.WebServer()
        web.start()

        # Instantiate a WSClient without specifiying an object ID.
        addr, port = config.azService['webapi']
        client = pyazrael.AzraelWSClient(addr, port, timeout=1)

        # Ping Clerk to verify the connection is live.
        ret = client.ping()
        assert (ret.ok, ret.data) == (True, 'pong clerk')

        # Shutdown the system.
        clerk.terminate()
        web.terminate()
        clerk.join(timeout=3)
        web.join(timeout=3)
Beispiel #5
0
def test_custom_objid():
    """
    Create two clients. The first automatically gets an ID assigned,
    whereas the second one specifies one explicitly.

    This behaviour matches that of `Client`` but is not automatically
    inherited because the ``WSClient`` is not a client itself but a
    wrapper to communicate with the client instance in WebServer.
    """
    # Start Clerk.
    clerk = azrael.clerk.Clerk()
    clerk.start()

    # Start WebServer.
    web = azrael.web.WebServer()
    web.start()

    # Convenience.
    ip, port = azrael.config.addr_webserver, azrael.config.port_webserver

    # Instantiate a WSClient without specifiying an object ID.
    client_0 = azrael.wsclient.WSClient(ip, port)

    # Ping Clerk to verify the connection is live.
    ret = client_0.ping()
    assert (ret.ok, ret.data) == (True, 'pong clerk')

    # Instantiate another WSClient. This time specify an ID. Note: the ID
    # need not exist albeit object specific commands will subsequently fail.
    client_1 = azrael.wsclient.WSClient(ip, port)

    # Ping Clerk again to verify the connection is live.
    ret = client_1.ping()
    assert (ret.ok, ret.data) == (True, 'pong clerk')

    # Shutdown the system.
    clerk.terminate()
    web.terminate()
    clerk.join(timeout=3)
    web.join(timeout=3)

    print('Test passed')