This guide explains how to test the FerryNotifier webhook server.
Run the included test suite:
python web/test_app.pyThe test suite includes:
- Import and initialization tests
- Route registration tests
- Webhook endpoint tests with mock data
- API endpoint tests
- Data formatting tests
Tests run automatically via GitHub Actions on:
- Every push to any branch
- Every pull request to main
- Before any deployment
See .github/workflows/deploy.yml for the CI configuration.
# Make sure .env is configured with your API key
python web/app.pyOr use the quick start script:
./deployment/run.shHealth Check:
curl http://localhost:5050/healthExpected response:
{
"status": "healthy",
"timestamp": "2024-01-15T10:30:00.123456"
}Service Information:
curl http://localhost:5050/Expected response:
{
"service": "Washington State Ferry Status Webhook",
"version": "1.0.0",
"endpoints": {
"/webhook": "Main webhook endpoint for Trmnl (GET)",
"/api/ferry-status": "JSON API endpoint (GET)",
"/health": "Health check endpoint"
},
"documentation": "https://github.com/cdibona/FerryNotifier"
}HTML Output (for Trmnl):
curl http://localhost:5050/webhookThis returns HTML formatted for e-ink display.
Save to file for inspection:
curl http://localhost:5050/webhook > ferry_output.html
# Open ferry_output.html in a browserWith specific route:
curl "http://localhost:5050/webhook?route_id=YOUR_ROUTE_ID"curl http://localhost:5050/api/ferry-status | jqOr with a specific route:
curl "http://localhost:5050/api/ferry-status?route_id=YOUR_ROUTE_ID" | jq# Build the Docker image from project root
docker build -f deployment/Dockerfile -t ferrynotifier .
# Run with .env file
docker run -p 5050:5050 --env-file .env ferrynotifierOr use docker-compose:
cd deployment
docker-compose up --build# Check if container is healthy
docker ps
# Should show "healthy" in the STATUS columncd deployment
docker-compose logs -f# Test that your API key works
curl "https://www.wsdot.wa.gov/ferries/api/vessels/rest/vessellocations?apiaccesscode=YOUR_API_KEY"For development without hitting the WSDOT API, you can modify web/app.py temporarily:
def fetch_ferry_status(route_id: Optional[str] = None) -> Dict[str, Any]:
"""Mock version for testing."""
return {
"vessels": [
{
"VesselName": "Test Ferry",
"InService": "True",
"AtDock": "Seattle Terminal",
"LeftDock": "10:00 AM"
}
],
"route_info": {
"RouteName": "Seattle - Bainbridge",
"Description": "Test Route"
},
"timestamp": datetime.now().isoformat()
}cd web
gunicorn -w 4 -b 127.0.0.1:5050 app:appThen test endpoints as above.
After setting up nginx:
# Test through nginx
curl https://ferry.yourdomain.com/health
# Check nginx logs
sudo tail -f /var/log/nginx/ferrynotifier_access.log# Start service
sudo systemctl start ferrynotifier
# Check status
sudo systemctl status ferrynotifier
# View logs
sudo journalctl -u ferrynotifier -f
# Test endpoints
curl http://localhost:5050/healthFor production systems, consider load testing:
# Install ab
sudo apt-get install apache2-utils
# Test 100 requests with 10 concurrent
ab -n 100 -c 10 http://localhost:5050/health# Install wrk
sudo apt-get install wrk
# Test for 30 seconds with 10 threads and 100 connections
wrk -t10 -c100 -d30s http://localhost:5050/health- Log in to your Trmnl account
- Create a new webhook plugin
- Enter your webhook URL
- Set refresh interval
Before connecting to Trmnl, test that your webhook returns proper HTML:
curl http://localhost:5050/webhook > test.html
open test.html # macOS
xdg-open test.html # Linux
start test.html # WindowsVerify the HTML displays correctly in a browser.
Use Trmnl's "Test Plugin" feature to verify the webhook works from their servers.
Watch for Trmnl requests:
sudo journalctl -u ferrynotifier -f
# or
sudo tail -f /var/log/ferrynotifier/access.logMake sure you're in the correct directory:
cd /path/to/FerryNotifier
python web/test_app.pyOr run from the web directory:
cd /path/to/FerryNotifier/web
python test_app.py- Verify your API key is correct in
.env - Test API key directly with curl
- Check internet connectivity
- Verify WSDOT API is operational
# Find process using port 5050
sudo lsof -i :5050
# Kill the process
kill -9 <PID>
# Or use a different port in .env
FLASK_PORT=5051# Check Docker logs
cd deployment
docker-compose logs
# Rebuild without cache
docker-compose build --no-cache
# Check if port is available
netstat -tlnp | grep 5050For ongoing development, consider:
- Watch mode: Use a tool like
watchdogto run tests on file changes - Pre-commit hooks: Run tests before commits
- CI/CD: GitHub Actions runs tests automatically (see
.github/workflows/deploy.yml)
Before deploying to production:
- All automated tests pass (
python web/test_app.py) - Manual endpoint tests successful
- WSDOT API integration works
- HTML output displays correctly
- JSON API returns valid data
- Health check responds
- Docker container builds and runs
- Gunicorn serves requests
- Nginx proxy works (if used)
- Systemd service starts and restarts
- Logs are being written
- Trmnl can fetch webhook successfully
- Display updates on Trmnl device
If tests fail or you encounter issues:
- Check the logs for error messages
- Review the TROUBLESHOOTING section in README.md
- Open an issue on GitHub with:
- Test output
- Log messages
- Your environment details