{% extends "base.html" %} {% block title %}Admin & Testing - Data Science Lab{% endblock %} {% block content %}

๐Ÿ” Data Validation

Run validation checks on all ingested data to ensure quality and consistency.

๐Ÿ“Š Database Summary

TableRow Count

๐Ÿ“œ API Access Logs

EndpointMethodStatusDurationTimestamp

๐Ÿ“– Writing Tests

Python
import pytest
from app import create_app

@pytest.fixture
def client():
    """Create test client."""
    app = create_app()
    app.config['TESTING'] = True
    with app.test_client() as client:
        yield client

def test_api_summary(client):
    """Test the /api/summary endpoint."""
    response = client.get('/api/summary')
    assert response.status_code == 200
    data = response.get_json()
    assert 'tables' in data

def test_model_train(client):
    """Test model training endpoint."""
    response = client.post('/api/model/train',
                          json={'model_type': 'linear_regression'})
    assert response.status_code == 200
    data = response.get_json()
    assert 'metrics' in data

def test_sql_readonly(client):
    """Test that SQL endpoint blocks write operations."""
    response = client.post('/api/sql/execute',
                          json={'query': 'DROP TABLE raw_data'})
    assert response.status_code == 400  # Should reject

# Run: pytest tests/ -v

๐Ÿ“– Testing Best Practices

Test TypeWhat It TestsExample
Unit TestSingle functionTest price prediction returns a number
Integration TestComponent interactionTest ingestion โ†’ database โ†’ query
API TestHTTP endpointsTest GET /api/housing returns valid JSON
Data ValidationData qualityTest no negative prices in fact table
๐Ÿงช Exercises

1. Run the data validation and fix any issues found.

2. Check the API logs โ€” which endpoints are most frequently called?

3. Write a test that verifies the pipeline runs without errors.

{% endblock %}