|
@@ -38,6 +38,7 @@ from vendor_path import setup_vendor_path
|
|
|
|
|
|
|
|
setup_vendor_path()
|
|
setup_vendor_path()
|
|
|
|
|
|
|
|
|
|
+from chattolib.client import ChattoClient
|
|
|
from chattolib.realtime_types import ReactionPayload
|
|
from chattolib.realtime_types import ReactionPayload
|
|
|
from chattolib.types import (
|
|
from chattolib.types import (
|
|
|
Asset,
|
|
Asset,
|
|
@@ -1909,3 +1910,42 @@ class TestConstants:
|
|
|
|
|
|
|
|
def test_seen_cap(self):
|
|
def test_seen_cap(self):
|
|
|
assert _SEEN_CAP == 500
|
|
assert _SEEN_CAP == 500
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# -- Client creation credentials --
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class TestOpenClientCredentials:
|
|
|
|
|
+ """Token wins; nothing configured raises as a normal creation failure."""
|
|
|
|
|
+
|
|
|
|
|
+ def _adapter(self):
|
|
|
|
|
+ return _make_adapter()
|
|
|
|
|
+
|
|
|
|
|
+ async def test_token_only_connects_without_login(self):
|
|
|
|
|
+ """The documented CHATTO_TOKEN path must not demand a login."""
|
|
|
|
|
+ adapter = self._adapter()
|
|
|
|
|
+ client = await adapter._open_client(
|
|
|
|
|
+ base_url="https://chat.example.com", login="", password="", token="t"
|
|
|
|
|
+ )
|
|
|
|
|
+ assert isinstance(client, ChattoClient)
|
|
|
|
|
+
|
|
|
|
|
+ async def test_no_credentials_raises_value_error(self):
|
|
|
|
|
+ """Misconfiguration reads as a logged creation failure, not a crash."""
|
|
|
|
|
+ adapter = self._adapter()
|
|
|
|
|
+ with pytest.raises(ValueError, match="neither token nor login"):
|
|
|
|
|
+ await adapter._open_client(
|
|
|
|
|
+ base_url="https://chat.example.com", login="", password=""
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ async def test_login_password_path_is_used_without_token(self):
|
|
|
|
|
+ adapter = self._adapter()
|
|
|
|
|
+ with patch("adapter.ChattoClient") as client_cls:
|
|
|
|
|
+ client_cls.login = AsyncMock(return_value=MagicMock())
|
|
|
|
|
+
|
|
|
|
|
+ await adapter._open_client(
|
|
|
|
|
+ base_url="https://chat.example.com", login="u", password="p"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ client_cls.login.assert_awaited_once_with(
|
|
|
|
|
+ "u", "p", base_url="https://chat.example.com"
|
|
|
|
|
+ )
|