| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- """Integration tests against the live Chatto API.
- Run with: pytest tests/test_integration.py -v
- Requires: CHATTO_LOGIN and CHATTO_PASSWORD environment variables.
- """
- import os
- import pytest
- from chattolib.client import ChattoClient
- from chattolib.exceptions import ChattoAuthError
- pytestmark = pytest.mark.skipif(
- not os.environ.get("CHATTO_LOGIN") or not os.environ.get("CHATTO_PASSWORD"),
- reason="CHATTO_LOGIN and CHATTO_PASSWORD env vars required",
- )
- @pytest.fixture
- async def client():
- c = await ChattoClient.login(
- os.environ["CHATTO_LOGIN"],
- os.environ["CHATTO_PASSWORD"],
- )
- async with c:
- yield c
- async def test_login_and_me(client):
- user = await client.me()
- assert user.id
- assert user.login == os.environ["CHATTO_LOGIN"]
- print(f"Logged in as {user.login} (id={user.id})")
- async def test_invalid_login():
- with pytest.raises(ChattoAuthError, match="Invalid credentials"):
- await ChattoClient.login("nonexistent_user_xyz", "wrongpassword")
- async def test_list_spaces(client):
- spaces = await client.spaces()
- assert isinstance(spaces, list)
- print(f"Found {len(spaces)} spaces")
- for s in spaces:
- print(f" - {s.name} (id={s.id}, members={s.member_count})")
- async def test_create_user(client):
- """Test creating a new user via the createUser mutation (requires admin)."""
- import random
- import string
- suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
- login = f"testbot_{suffix}"
- display_name = f"Test Bot {suffix}"
- password = "TestPass123!"
- user = await client.create_user(login, display_name, password)
- assert user.id
- assert user.login == login
- assert user.display_name == display_name
- print(f"Created user: {user.login} (id={user.id})")
|