def test_socket_connect(_mock):
    client = CloudClient(socket_url="", key_id="", key_secret="")

    with pytest.raises(ConnectionError):
        client.initialize()

    assert not client.is_connected
    client.connect()

    client._socket.recv.return_value = json.dumps({
        "error":
        None,
        "final":
        False,
        "hypotheses": [{
            "confidence": 0.5,
            "transcript": "this is a test"
        }],
        "status":
        "ok",
    })
    assert client.is_connected

    # try a double connect which should be silently ignored
    client.connect()

    client.disconnect()
    assert not client.is_connected
Exemple #2
0
def test_disconnect(_mock):
    client = CloudClient(socket_url="", key_id="", key_secret="")

    assert not client.is_connected
    client.connect()
    assert client.is_connected
    client.disconnect()
    assert not client.is_connected