conftest.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import pytest
  2. import os
  3. import sys
  4. import tempfile
  5. import shutil
  6. from pathlib import Path
  7. from datetime import datetime, timezone, timedelta
  8. from cryptography.fernet import Fernet
  9. # Add parent directory to path for imports
  10. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  11. os.environ["LETTA_SWITCHBOARD_DEV_MODE"] = "true"
  12. @pytest.fixture
  13. def temp_volume_path():
  14. """Create a temporary directory to simulate Modal volume."""
  15. temp_dir = tempfile.mkdtemp()
  16. yield temp_dir
  17. shutil.rmtree(temp_dir)
  18. @pytest.fixture
  19. def mock_api_key():
  20. """A mock API key for testing."""
  21. return "test-api-key-12345"
  22. @pytest.fixture
  23. def mock_api_key_2():
  24. """A second mock API key for multi-user testing."""
  25. return "test-api-key-67890"
  26. @pytest.fixture
  27. def mock_agent_id():
  28. """A mock agent ID for testing."""
  29. return "agent-test-123"
  30. @pytest.fixture
  31. def encryption_key():
  32. """Generate a test encryption key."""
  33. return Fernet.generate_key()
  34. @pytest.fixture
  35. def test_recurring_schedule_data(mock_api_key, mock_agent_id):
  36. """Sample recurring schedule data."""
  37. return {
  38. "agent_id": mock_agent_id,
  39. "api_key": mock_api_key,
  40. "cron": "*/5 * * * *",
  41. "message": "Test recurring message",
  42. "role": "user"
  43. }
  44. @pytest.fixture
  45. def test_onetime_schedule_data(mock_api_key, mock_agent_id):
  46. """Sample one-time schedule data."""
  47. future_time = datetime.now(timezone.utc) + timedelta(minutes=5)
  48. return {
  49. "agent_id": mock_agent_id,
  50. "api_key": mock_api_key,
  51. "execute_at": future_time.isoformat(),
  52. "message": "Test one-time message",
  53. "role": "user"
  54. }
  55. @pytest.fixture
  56. def past_onetime_schedule_data(mock_api_key, mock_agent_id):
  57. """One-time schedule scheduled in the past (should execute immediately)."""
  58. past_time = datetime.now(timezone.utc) - timedelta(minutes=5)
  59. return {
  60. "agent_id": mock_agent_id,
  61. "api_key": mock_api_key,
  62. "execute_at": past_time.isoformat(),
  63. "message": "Test past message",
  64. "role": "user"
  65. }
  66. @pytest.fixture
  67. def api_base_url():
  68. """Base URL for API testing. Override with LETTA_SWITCHBOARD_URL env var."""
  69. return os.getenv("LETTA_SWITCHBOARD_URL", "https://letta--letta-switchboard-api-dev.modal.run")
  70. @pytest.fixture
  71. def valid_letta_api_key():
  72. """Real Letta API key for E2E tests. Must be set via env var."""
  73. api_key = os.getenv("LETTA_API_KEY")
  74. if not api_key:
  75. pytest.skip("LETTA_API_KEY not set - skipping E2E test")
  76. return api_key
  77. @pytest.fixture
  78. def valid_letta_agent_id():
  79. """Real Letta agent ID for E2E tests."""
  80. agent_id = os.getenv("LETTA_AGENT_ID")
  81. if not agent_id:
  82. pytest.skip("LETTA_AGENT_ID not set - skipping E2E test")
  83. return agent_id