apigateway / tests /README.md
jebin2's picture
db services
50c20bf

DB Service - Quick Start

Run Tests

# Install test dependencies
pip install pytest pytest-asyncio httpx

# Run all tests
ADMIN_EMAILS="admin@example.com" pytest tests/test_db_service.py -v

# Run specific test
pytest tests/test_db_service.py::TestPermissions::test_user_can_read_own_data -v

# Run with coverage
pytest tests/test_db_service.py --cov=services/db_service --cov-report=html -v

Start Application

# Development (reset DB on startup)
RESET_DB=true ADMIN_EMAILS="your@email.com" python app.py

# Production (preserve DB)
ADMIN_EMAILS="admin@example.com" python app.py

Verify Integration

Check startup logs for:

βœ… DB Service configured
βœ… Database initialized
βœ… Database reset complete (if RESET_DB=true)

Test Endpoints

# As regular user
curl -X GET http://localhost:8000/gemini/jobs \
  -H "Authorization: Bearer <user_token>"

# As admin
curl -X GET http://localhost:8000/blink/audit-logs \
  -H "Authorization: Bearer <admin_token>"

Troubleshooting

Config not registered:

RuntimeError: DBServiceConfig not registered!

β†’ Ensure register_db_service_config() is called in app startup

Module not found:

ModuleNotFoundError: No module named 'services.db_service'

β†’ Verify __init__.py exists in services/db_service/

Permission denied:

403 Forbidden: Only administrators can...

β†’ Check ADMIN_EMAILS environment variable

Success Indicators

βœ… All files compile without errors βœ… Application starts successfully βœ… Database tables created βœ… Tests pass βœ… Endpoints return data correctly βœ… User isolation working (users see only own data) βœ… Admin access working (admins see all data)