|
|
5 months ago | |
|---|---|---|
| .. | ||
| README.md | 5 months ago | |
| conftest.py | 5 months ago | |
| test_api_e2e.py | 5 months ago | |
| test_crypto_utils.py | 5 months ago | |
| test_scheduler.py | 5 months ago | |
Comprehensive test suite with unit tests and end-to-end integration tests.
tests/
├── conftest.py # Pytest fixtures and configuration
├── test_crypto_utils.py # Unit tests for encryption/hashing
├── test_scheduler.py # Unit tests for schedule logic
├── test_api_e2e.py # E2E API tests (requires running service)
└── README.md # This file
Install test dependencies:
pip install -r requirements-test.txt
Unit tests run without requiring a running Modal service:
# Run all unit tests
pytest -m "not e2e"
# Run specific unit test file
pytest tests/test_crypto_utils.py
pytest tests/test_scheduler.py
# Run with verbose output
pytest -v -m "not e2e"
E2E tests require a running Modal service and valid Letta credentials:
1. Start the service:
export LETTA_SCHEDULES_DEV_MODE=true
modal serve app.py
2. In another terminal, set environment variables:
export LETTA_API_KEY="sk-..." # Required: Valid Letta API key
export LETTA_AGENT_ID="agent-xxx" # Required: Valid agent ID
export LETTA_SCHEDULES_URL="https://your-modal-url" # Optional: defaults to dev URL
export LETTA_API_KEY_2="sk-different-key" # Optional: for multi-user tests
3. Run E2E tests:
# Run all E2E tests (excluding slow tests)
pytest -m "e2e and not slow"
# Run all E2E tests including slow ones
pytest -m "e2e"
# Run specific E2E test class
pytest tests/test_api_e2e.py::TestAuthentication
pytest tests/test_api_e2e.py::TestRecurringScheduleCRUD
# Run execution tests (these take 60-90 seconds each)
pytest -m "slow" -v
# Run everything (unit + e2e, excluding slow tests)
pytest -m "not slow"
# Run absolutely everything
pytest
Tests are organized with pytest markers:
@pytest.mark.unit - Fast unit tests (no external dependencies)@pytest.mark.e2e - End-to-end tests (requires running service)@pytest.mark.slow - Tests that wait for cron execution (60-90s each)test_crypto_utils.py:
test_scheduler.py:
test_api_e2e.py:
Authentication:
Recurring Schedules CRUD:
One-Time Schedules CRUD:
Results:
Execution (Slow Tests):
Required for E2E tests:
LETTA_API_KEY - Valid Letta API keyLETTA_AGENT_ID - Valid Letta agent IDOptional:
LETTA_SCHEDULES_URL - Override API base URL (default: dev URL)LETTA_API_KEY_2 - Second API key for multi-user isolation testsLETTA_SCHEDULES_DEV_MODE - Enable dev mode (default: true for tests)For continuous integration, run only fast tests:
# Run unit tests + fast E2E tests
pytest -m "not slow" --timeout=30
# Generate coverage report
pytest --cov=. --cov-report=html -m "not slow"
For full integration testing (slower):
# Run everything including execution tests
pytest -v --timeout=120
Tests fail with "LETTA_API_KEY not set":
pytest -m "not e2e"Tests timeout:
modal serve app.pymodal app logs letta-schedules --follow"Service not reachable":
LETTA_SCHEDULES_URL points to correct endpointcurl <service-url>/schedules/recurringDev mode warnings:
LETTA_SCHEDULES_DEV_MODE=true# Terminal 1: Start service
export LETTA_SCHEDULES_DEV_MODE=true
modal serve app.py
# Terminal 2: Run tests
export LETTA_API_KEY="sk-..."
export LETTA_AGENT_ID="agent-..."
pytest -v -m "e2e and not slow"
Expected output:
tests/test_api_e2e.py::TestAuthentication::test_invalid_api_key_returns_401 PASSED
tests/test_api_e2e.py::TestRecurringScheduleCRUD::test_create_recurring_schedule PASSED
tests/test_api_e2e.py::TestOneTimeScheduleCRUD::test_create_onetime_schedule PASSED
...
========== 15 passed in 12.34s ==========