test_integration.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """Integration tests against the live Chatto API.
  2. Run with: pytest tests/test_integration.py -v
  3. Requires: CHATTO_LOGIN and CHATTO_PASSWORD environment variables.
  4. """
  5. import os
  6. import pytest
  7. from chattolib.client import ChattoClient
  8. from chattolib.exceptions import ChattoAuthError
  9. pytestmark = pytest.mark.skipif(
  10. not os.environ.get("CHATTO_LOGIN") or not os.environ.get("CHATTO_PASSWORD"),
  11. reason="CHATTO_LOGIN and CHATTO_PASSWORD env vars required",
  12. )
  13. @pytest.fixture
  14. async def client():
  15. c = await ChattoClient.login(
  16. os.environ["CHATTO_LOGIN"],
  17. os.environ["CHATTO_PASSWORD"],
  18. )
  19. async with c:
  20. yield c
  21. async def test_login_and_me(client):
  22. user = await client.me()
  23. assert user.id
  24. assert user.login == os.environ["CHATTO_LOGIN"]
  25. print(f"Logged in as {user.login} (id={user.id})")
  26. async def test_invalid_login():
  27. with pytest.raises(ChattoAuthError, match="Invalid credentials"):
  28. await ChattoClient.login("nonexistent_user_xyz", "wrongpassword")
  29. async def test_list_rooms(client):
  30. rooms = await client.rooms()
  31. assert isinstance(rooms, list)
  32. print(f"Found {len(rooms)} rooms")
  33. for r in rooms:
  34. print(f" - {r.name} (id={r.id}, type={r.type})")