This is what you should do for the case interview - all external services are mocked.
# Navigate to the lambda directory
cd c:/Users/1/Downloads/case/lambda
# Install Python dependencies
pip install -r requirements.txt
# Install test dependencies
pip install pytest pytest-asyncio pytest-cov# Run all 80 tests
pytest tests/ -v
# Expected output:
# ========================== 80 passed in 3.45s ===========================# See code coverage
pytest tests/ --cov=lambda_function --cov=api_client --cov-report=term-missing
# Generate HTML report
pytest tests/ --cov=. --cov-report=html
# Then open: htmlcov/index.html# Just pure function tests (fastest)
pytest tests/test_email_utils.py -v
pytest tests/test_budget_utils.py -v
# FSM orchestration tests
pytest tests/test_deal_conversation_fsm.py -v
# Full handler integration tests
pytest tests/test_lambda_handler.py -v# Run one specific test
pytest tests/test_email_utils.py::TestExtractEmailAddress::test_extract_with_name_and_brackets -v
# Run all tests in a class
pytest tests/test_budget_utils.py::TestExtractBudgetValue -vIf you want to invoke the actual Lambda handler locally (not recommended for case interview):
- AWS credentials configured
- SES set up to receive emails
- S3 bucket created
- Backend API running
- OpenAI API key
# On Windows (PowerShell)
$env:API_BASE_URL = "http://localhost:8000"
$env:API_AUTH_TOKEN = "your-token"
$env:S3_BUCKET = "your-bucket"
$env:SES_REGION = "us-east-1"
$env:OPENAI_API_KEY = "sk-..."
# On Linux/Mac
export API_BASE_URL="http://localhost:8000"
export API_AUTH_TOKEN="your-token"
export S3_BUCKET="your-bucket"
export SES_REGION="us-east-1"
export OPENAI_API_KEY="sk-..."Create test_event.json:
{
"Records": [{
"ses": {
"mail": {
"messageId": "test-msg-123",
"timestamp": "2025-10-10T10:00:00Z",
"commonHeaders": {
"from": ["Brand Rep <[email protected]>"],
"to": ["[email protected]"],
"subject": "Sponsorship opportunity"
}
},
"receipt": {}
}
}]
}# Create test_invoke.py
import json
from lambda_function import lambda_handler
with open('test_event.json') as f:
event = json.load(f)
result = lambda_handler(event, {})
print(json.dumps(result, indent=2))python test_invoke.pyTest individual functions interactively:
python# Import functions
from lambda_function import (
extract_email_address,
extract_budget_value,
determine_deal_type_from_budget,
normalize_subject_for_thread,
generate_thread_id,
)
# Test email extraction
extract_email_address("John Doe <[email protected]>")
# Output: '[email protected]'
# Test budget parsing
extract_budget_value("$1,000 - $5,000")
# Output: 1000.0
# Test deal type detection
determine_deal_type_from_budget("10% affiliate commission")
# Output: 'AFFILIATE'
# Test subject normalization
normalize_subject_for_thread("Re: Sponsorship Opportunity")
# Output: 'Sponsorship Opportunity'
# Test thread ID generation
generate_thread_id("[email protected]", "[email protected]", "Partnership")
# Output: 'a1b2c3d4e5f6g7h8-partnershi'# Most common commands:
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ --cov=. --cov-report=term-missing
# Run specific file
pytest tests/test_email_utils.py -v
# Run specific test
pytest tests/test_email_utils.py::test_extract_with_name_and_brackets -v
# Run and show print statements
pytest tests/ -v -s
# Run and stop on first failure
pytest tests/ -x
# Run only async tests
pytest tests/ -m asyncio -v
# Run with verbose output
pytest tests/ -vv# Add current directory to Python path
export PYTHONPATH="${PYTHONPATH}:$(pwd)" # Linux/Mac
$env:PYTHONPATH = "$env:PYTHONPATH;$PWD" # Windows PowerShell# Upgrade pytest-asyncio
pip install --upgrade pytest-asyncio# Install everything
pip install -r requirements.txt pytest pytest-asyncio pytest-cov# Check Python version (need 3.10+)
python --version
# Use specific Python version
python3.12 -m pytest tests/ -vThe test suite covers:
✅ Pure Functions (61 tests)
- Email parsing utilities
- Budget extraction
- Deal type determination
- Thread ID generation
- Conversation formatting
✅ FSM Logic (6 tests)
- State transitions
- Agent orchestration
- Deal qualification
- Recommendation handling
✅ Handler Integration (13 tests)
- Early exit scenarios
- Full email processing flow
- SES reply logic
- Error handling
All external services are mocked - no real AWS/API calls!
-
First time:
pip install -r requirements.txt pytest pytest-asyncio pytest tests/ -v
-
During development:
# Run tests in watch mode (requires pytest-watch) pip install pytest-watch ptw tests/ -- -v -
Before committing:
pytest tests/ --cov=. --cov-report=term-missing # Ensure coverage > 70%
tests/test_budget_utils.py::TestExtractBudgetValue::test_simple_dollar_amount PASSED
tests/test_budget_utils.py::TestExtractBudgetValue::test_amount_with_commas PASSED
tests/test_budget_utils.py::TestExtractBudgetValue::test_range_returns_lower_bound PASSED
...
tests/test_lambda_handler.py::TestLambdaHandler::test_new_sponsorship_thread_full_flow PASSED
tests/test_lambda_handler.py::TestLambdaHandler::test_ses_send_success_stores_outbound_message PASSED
========================== 80 passed in 3.45s ===========================
Success! ✅