Django Testing
DebuggAI provides comprehensive end-to-end testing capabilities for Django applications through our VS Code and Cursor extensions. Test your Django web applications directly from your IDE, including forms, authentication, admin interfaces, and complex user workflows.
Overview
Django applications are perfect for DebuggAI's testing approach because they provide complete web interfaces that can be tested from the user's perspective. Our AI agents can interact with Django forms, test authentication flows, navigate admin interfaces, and validate complex business logic through the web interface.
Prerequisites
Before testing your Django application with DebuggAI:
- Python 3.8 or later with Django 3.2+
- DebuggAI extension installed in VS Code or Cursor
- Your Django development server running locally
- DebuggAI account connected through the extension
Getting Started
Step 1: Start Your Django Development Server
Make sure your Django application is running locally:
# Activate your virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activate
# Run Django development server
python manage.py runserver
# Or specify a different port
python manage.py runserver 8000
Your Django app will typically be available at http://localhost:8000
.
Step 2: Configure the Extension
- Open VS Code or Cursor
- Access DebuggAI extension settings (Cmd+, / Ctrl+,)
- Search for "DebuggAI"
- Set "Local Server Port" to your Django server port (usually 8000)
Step 3: Create Your First Test
- Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P)
- Run "DebuggAI: Create New E2E Test" or use Cmd+Alt+C / Ctrl+Alt+C
- Describe your test in natural language
Django-Specific Testing Scenarios
Django Forms Testing
DebuggAI excels at testing Django forms and form validation:
Example test descriptions:
• Test user registration form with validation
• Test contact form submission and email sending
• Test model form creates database records correctly
• Test form wizard completes multi-step process
• Test file upload form handles different file types
Authentication and Authorization Testing
Test Django's built-in authentication system:
Example test descriptions:
• Test user login with valid credentials
• Test user registration and email verification
• Test password reset flow via email
• Test user permissions and group access
• Test social authentication integration
Django Admin Testing
Comprehensive testing of Django admin interface:
Example test descriptions:
• Test admin login and dashboard access
• Test creating new model instances via admin
• Test bulk actions on admin list view
• Test admin form validation and saving
• Test custom admin actions work correctly
Model and Database Testing
Test Django models through the web interface:
Example test descriptions:
• Test blog post creation and publication
• Test e-commerce product catalog browsing
• Test user profile updates save correctly
• Test related model associations work
• Test database constraints are enforced
Django Views and Templates
Test Django views and template rendering:
Example test descriptions:
• Test homepage displays correct content
• Test dynamic content loads based on user
• Test template inheritance works correctly
• Test context variables display properly
• Test custom template tags function
Advanced Django Testing Features
Testing Django REST Framework APIs
When your Django app includes DRF APIs, test them through the frontend:
Example test descriptions:
• Test API-powered single page application
• Test AJAX form submissions to DRF endpoints
• Test API authentication through web interface
• Test real-time updates via WebSocket integration
Celery and Background Tasks
Test background task integration:
Example test descriptions:
• Test email sending triggers background task
• Test file processing completes asynchronously
• Test periodic task results appear in UI
• Test task status updates display correctly
Django Channels and WebSockets
Test real-time features:
Example test descriptions:
• Test chat application message delivery
• Test real-time notifications display
• Test WebSocket connection and reconnection
• Test live updates without page refresh
Multi-tenant Applications
Test tenant-specific functionality:
Example test descriptions:
• Test tenant isolation works correctly
• Test subdomain routing to correct tenant
• Test tenant-specific data and permissions
• Test cross-tenant data security
Django Project Structure Testing
Testing Different Django Configurations
DebuggAI adapts to various Django project structures:
Standard Django Project:
# settings.py
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
# DebuggAI works with any Django configuration
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Django with Custom User Model:
Example test descriptions:
• Test custom user registration flow
• Test custom user fields display correctly
• Test custom authentication backends
• Test user profile with custom fields
Django with Multiple Apps:
Example test descriptions:
• Test navigation between different apps
• Test app-specific functionality works
• Test shared templates and components
• Test inter-app communication flows
Environment-Specific Testing
Test with different Django settings:
# settings/development.py
from .base import *
DEBUG = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# DebuggAI tests against your development configuration
Common Django Testing Patterns
User Registration and Authentication
Test Description: "Test complete user registration and login flow"
DebuggAI will:
1. Navigate to registration page
2. Fill out registration form
3. Handle email verification (if enabled)
4. Test login with new credentials
5. Verify user dashboard access
6. Test logout functionality
Content Management
Test Description: "Test blog post creation and publication workflow"
DebuggAI will:
1. Login to admin or frontend editor
2. Create new blog post with content
3. Add images and media if applicable
4. Test draft saving and preview
5. Publish post and verify public display
6. Test editing and updating published post
E-commerce Functionality
Test Description: "Test product purchase flow end-to-end"
DebuggAI will:
1. Browse product catalog and filtering
2. Add products to cart
3. Test cart management (add/remove/update)
4. Proceed through checkout process
5. Handle payment form submission
6. Verify order confirmation and email
Form Handling and Validation
Test Description: "Test contact form with comprehensive validation"
DebuggAI will:
1. Navigate to contact form
2. Test required field validation
3. Test email format validation
4. Test custom field validation rules
5. Submit valid form data
6. Verify success message and email delivery
Testing Django with Frontend Frameworks
Django + React
For Django backends with React frontends:
Example test descriptions:
• Test Django API endpoints through React UI
• Test authentication flow between Django and React
• Test real-time updates from Django to React
• Test form submissions from React to Django
Django + Vue.js
Test Django with Vue.js integration:
Example test descriptions:
• Test Vue components consume Django data
• Test Django template integration with Vue
• Test dynamic content loading via AJAX
• Test form validation between Vue and Django
Django + HTMX
Test modern Django with HTMX:
Example test descriptions:
• Test HTMX partial page updates
• Test form submissions without page reload
• Test dynamic content swapping
• Test HTMX animations and transitions
Testing Django Extensions
Django CMS
Test content management functionality:
Example test descriptions:
• Test page creation in Django CMS
• Test content editing and publishing
• Test menu navigation and structure
• Test multi-language content management
Django E-commerce (Oscar, Saleor)
Test e-commerce specific features:
Example test descriptions:
• Test product catalog and search
• Test shopping cart and checkout
• Test payment processing integration
• Test order management workflow
Django Social Auth
Test social authentication integration:
Example test descriptions:
• Test Google OAuth login flow
• Test Facebook authentication integration
• Test GitHub social login
• Test account linking and unlinking
Best Practices for Django Testing
Database State Management
DebuggAI handles Django's database state automatically:
- Tests run against your development database
- No need for test database configuration
- Handles Django fixtures and sample data
- Works with database migrations
Static Files and Media
Test static file serving and media uploads:
Example test descriptions:
• Test image upload and display
• Test CSS and JavaScript loading
• Test static file serving in development
• Test media file access and permissions
Django Settings Testing
Test different Django configurations:
Example test descriptions:
• Test debug toolbar functionality
• Test different time zone handling
• Test localization and translation
• Test custom middleware behavior
Performance Testing
Monitor Django application performance:
Example test descriptions:
• Test page load times for complex views
• Test database query optimization
• Test caching implementation effectiveness
• Test large form handling performance
Debugging Django Tests
Common Issues and Solutions
Port Configuration:
- Ensure extension is configured for Django's port (usually 8000)
- Check Django development server is running
- Verify ALLOWED_HOSTS includes localhost
Static Files:
- Ensure
python manage.py collectstatic
if needed - Check static file serving in development
- Verify media files are accessible
Database Issues:
- Run migrations:
python manage.py migrate
- Create superuser if testing admin:
python manage.py createsuperuser
- Load test data with fixtures if needed
Django Debug Toolbar Integration
DebuggAI test results complement Django Debug Toolbar:
- SQL Queries: Performance insights for database operations
- Template Context: Understanding template variable usage
- Cache Operations: Validation of caching strategies
- Signal Processing: Testing Django signal handling
Integration with Django Development Workflow
Django Management Commands
Test custom management commands through the web interface:
Example test descriptions:
• Test data import command results appear in UI
• Test scheduled task command effects
• Test user notification command triggers
• Test data cleanup command preserves essential data
Django Migrations Testing
Ensure migrations work correctly:
Example test descriptions:
• Test new model fields appear in forms
• Test data migration preserves existing records
• Test reverse migration doesn't break functionality
• Test migration affects admin interface correctly
Django Testing with Docker
For containerized Django applications:
# Docker setup
docker-compose up
# Configure DebuggAI extension for Docker port mapping
# Example: localhost:8000 -> Django container
Team Collaboration with Django
Shared Django Standards
Establish consistent testing approaches:
- Form Testing: Standard patterns for Django form validation
- Admin Testing: Consistent admin interface testing
- API Testing: Standardized API endpoint testing
- Authentication Testing: Shared authentication flow testing
Django Project Documentation
Use DebuggAI test results to document:
- User Workflows: Visual documentation of user journeys
- Form Behavior: Screenshots of form validation and submission
- Admin Processes: Recordings of admin interface usage
- Error Handling: Documentation of error scenarios
Next Steps
- Learn about Extension Features for more Django testing capabilities
- Explore Advanced Features for complex Django patterns
- Check out Node.js Testing for API backend testing
- Set up Team Testing for collaborative Django development