A modern, full-stack Python application for creating, scheduling, and monitoring database consistency tests with a beautiful React UI.
- Test Management: Create SQL-based tests to check data consistency
- Scheduling: Schedule tests with flexible cron-based scheduling (days, hours, frequency)
- Conditions: Multiple condition types (row count, value matching, etc.)
- Triggers: Execute actions on test success/failure:
- Run SQL queries
- Send email notifications
- Call webhooks
- Test Execution: Manual or scheduled test execution with detailed results
-
USER Role:
- Propose new tests
- Edit pending/rejected tests
- View test results and executions
- Manually trigger approved tests
-
ADMIN Role:
- Approve or reject proposed tests
- Archive or delete tests
- All user permissions
- Dashboard with KPI visualizations (24h, 7d, 30d, 6m)
- Real-time test execution monitoring
- Interactive charts showing success/failure rates
- Responsive Material-UI design
- FastAPI: Modern, fast Python web framework
- SQLAlchemy: SQL toolkit and ORM
- APScheduler: Advanced Python task scheduling
- JWT: Secure authentication
- PostgreSQL/MySQL/SQLite: Flexible database support
- React 18: Modern UI framework
- Material-UI: Beautiful, accessible components
- Recharts: Interactive data visualizations
- Axios: HTTP client
- Python 3.9+
- Node.js 16+ (for frontend)
- PostgreSQL/MySQL (optional, SQLite included)
- Clone the repository
cd DataTests- Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment
cp .env.example .env
# Edit .env with your settings- Initialize database
python -c "from backend.core.database import engine, Base; from backend.models import *; Base.metadata.create_all(bind=engine)"- Create first admin user
python -c "
from backend.core.database import SessionLocal
from backend.models.user import User
from backend.core.security import get_password_hash
db = SessionLocal()
admin = User(
username='admin',
email='[email protected]',
hashed_password=get_password_hash('admin123'),
is_admin=True
)
db.add(admin)
db.commit()
print('Admin user created: admin/admin123')
"- Run backend server
python backend/main.py
# Or with uvicorn:
# uvicorn backend.main:app --reload --host 0.0.0.0 --port 8000Backend will be available at: http://localhost:8000 API documentation: http://localhost:8000/docs
- Navigate to frontend directory
cd frontend- Install dependencies
npm install- Run development server
npm run devFrontend will be available at: http://localhost:3000
Edit .env file:
# Database for application data
DATABASE_URL=sqlite:///./datatest.db
# Or PostgreSQL: postgresql://user:password@localhost/dbname
# Or MySQL: mysql+pymysql://user:password@localhost/dbname
# Target database to test
TARGET_DB_URL=sqlite:///./target_database.db
# Security
SECRET_KEY=your-secret-key-change-this-in-production
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Email (for notifications)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-app-password
[email protected]For Gmail:
- Enable 2-factor authentication
- Generate an App Password: https://myaccount.google.com/apppasswords
- Use the app password in SMTP_PASSWORD
-
Login to the application
-
Navigate to "Tests" → "Create Test"
-
Fill in the test details:
- Name: Descriptive test name
- SQL Query: Query to check data consistency
- Condition: How to evaluate the result (e.g., "Has Rows", "Row Count > 10")
- Triggers: Actions to execute on success/failure
- Schedule: Optional scheduling configuration
-
Submit for approval (if you're not admin)
Check for duplicate emails:
SELECT email, COUNT(*) as count
FROM users
GROUP BY email
HAVING COUNT(*) > 1Condition: no_rows (expect no duplicates)
Trigger on failure: Send email to admin
Check daily transactions:
SELECT COUNT(*) FROM transactions
WHERE DATE(created_at) = CURRENT_DATECondition: row_count_gt with value 100 (expect >100 transactions)
Schedule: Daily at 6 PM
Check system health:
SELECT 'OK' as statusCondition: value_equals with value OK
Schedule: Every 15 minutes
Schedule Config Format:
{
"days": [0, 1, 2, 3, 4], // Monday-Friday (0=Monday, 6=Sunday)
"hours": [9, 12, 18], // At 9 AM, 12 PM, 6 PM
"frequency_minutes": null // Or set to run every X minutes
}Or use frequency:
{
"frequency_minutes": 15 // Run every 15 minutes
}Email Trigger:
{
"type": "email",
"config": {
"to": "[email protected]",
"subject": "Test Alert: {test_name}",
"body": "Test {test_name} has {status}. Row count: {row_count}"
}
}SQL Trigger:
{
"type": "sql_query",
"config": {
"query": "UPDATE system_status SET last_check = NOW()"
}
}Webhook Trigger:
{
"type": "webhook",
"config": {
"url": "https://your-webhook.com/notify",
"method": "POST"
}
}POST /api/auth/register- Register new userPOST /api/auth/login- Login and get token
GET /api/tests/- List all testsPOST /api/tests/- Create new testGET /api/tests/{id}- Get test detailsPUT /api/tests/{id}- Update testPOST /api/tests/{id}/approve- Approve test (admin)POST /api/tests/{id}/reject- Reject test (admin)POST /api/tests/{id}/execute- Execute test manuallyGET /api/tests/{id}/executions- Get execution history
GET /api/dashboard/kpis- Get KPI metricsGET /api/dashboard/recent-executions- Get recent executions
Full API documentation available at: http://localhost:8000/docs
DataTests/
├── backend/
│ ├── core/ # Configuration, database, security
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ ├── routers/ # API endpoints
│ ├── services/ # Business logic (scheduler, executor, triggers)
│ └── main.py # FastAPI application
├── frontend/
│ └── src/
│ ├── components/ # React components
│ ├── pages/ # Page components
│ ├── services/ # API client
│ └── context/ # React context (auth)
└── requirements.txt
# Backend tests
pytest
# Frontend tests
cd frontend && npm testUsing Alembic:
alembic init alembic
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head# Use production WSGI server
gunicorn backend.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000cd frontend
npm run build
# Serve the build/ directory with nginx or similarCreate Dockerfile:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY backend/ backend/
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"]- Change
SECRET_KEYin production - Use HTTPS in production
- Store sensitive credentials in environment variables
- Validate SQL queries to prevent injection
- Implement rate limiting
- Regular security updates
Backend won't start:
- Check Python version (3.9+)
- Verify all dependencies installed
- Check database connection string
Frontend won't connect:
- Ensure backend is running on port 8000
- Check CORS settings in backend/main.py
- Verify API_BASE_URL in frontend
Scheduler not working:
- Check test status is "approved"
- Verify schedule_enabled is True
- Check logs for errors
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
MIT License - See LICENSE file for details
For issues and questions:
- GitHub Issues: [Create an issue]
- Documentation: See
/docsendpoint - Email: [email protected]