client: add ConnectionFailed and reconnect method
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""Tests for MumbleClient dispatcher and callback wiring."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from tuimble.client import MumbleClient
|
||||
from tuimble.client import ConnectionFailed, MumbleClient
|
||||
|
||||
|
||||
def test_default_state():
|
||||
@@ -83,3 +83,40 @@ def test_cert_custom():
|
||||
)
|
||||
assert client._certfile == "/path/cert.pem"
|
||||
assert client._keyfile == "/path/key.pem"
|
||||
|
||||
|
||||
def test_connection_failed_retryable():
|
||||
exc = ConnectionFailed("network error", retryable=True)
|
||||
assert str(exc) == "network error"
|
||||
assert exc.retryable is True
|
||||
|
||||
|
||||
def test_connection_failed_not_retryable():
|
||||
exc = ConnectionFailed("auth rejected", retryable=False)
|
||||
assert str(exc) == "auth rejected"
|
||||
assert exc.retryable is False
|
||||
|
||||
|
||||
def test_connection_failed_default_retryable():
|
||||
exc = ConnectionFailed("something broke")
|
||||
assert exc.retryable is True
|
||||
|
||||
|
||||
def test_reconnect_resets_state():
|
||||
client = MumbleClient(host="localhost")
|
||||
client._connected = True
|
||||
client._mumble = MagicMock()
|
||||
|
||||
with patch.object(client, "connect"):
|
||||
client.reconnect()
|
||||
|
||||
# disconnect should have cleared _mumble before connect
|
||||
assert client._connected is False
|
||||
|
||||
|
||||
def test_disconnect_clears_connected():
|
||||
client = MumbleClient(host="localhost")
|
||||
client._connected = True
|
||||
client._mumble = MagicMock()
|
||||
client.disconnect()
|
||||
assert client.connected is False
|
||||
|
||||
Reference in New Issue
Block a user