DJ

django-test-expert

An automated testing suite for Django that processes models, views, and APIs to generate and run security-focused unit and integration tests.

Install

mkdir -p .claude/skills/django-test-expert && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16463" && unzip -o skill.zip -d .claude/skills/django-test-expert && rm skill.zip

Installs to .claude/skills/django-test-expert

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Expert tool for generating and executing Django unit, integration, and security tests. Triggers when the user mentions "test", "unit test", "coverage", "pytest", or "Django testing". Analyzes Django models, serializers, views, and security layers. Processes Postman collections and API documentation to create edge-case scenarios. Automatically runs pytest and generates CSV/AI reports post-execution.
401 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Advanced

Key capabilities

  • Analyze Django models, serializers, and views
  • Convert Postman collections or API documentation into pytest cases
  • Verify authentication, authorization, and common vulnerabilities
  • Generate test data using factory-boy or faker
  • Run tests using bash with pytest and generate reports

How it works

This skill analyzes Django components and external API definitions to generate pytest test cases, including security and edge-case scenarios. It then executes these tests and produces CSV and AI-summarized reports.

Inputs & outputs

You give it
Django application components (models, serializers, views), Postman collections, or API documentation
You get back
Pytest test cases, test execution reports, and an AI summary of test results

When to use django-test-expert

  • Generate unit tests for Django models and views
  • Convert Postman collections into pytest cases
  • Perform security regression testing on APIs

About this skill

Django Test Expert Skill

You are an expert Django QA Engineer specialized in pytest. Your goal is to ensure high code coverage and robust security for Django applications by generating and running comprehensive test suites.

Core Capabilities

  1. Source Analysis: Read Django models, serializers, and views to understand business logic.
  2. External Input Processing: Convert Postman collections or API documentation into pytest test cases.
  3. Security Testing: Verify authentication, authorization (RBAC), and common vulnerabilities (SQLi, XSS, CSRF) within the Django context.
  4. Edge Case Generation: Automatically identify and test boundary conditions, null values, and invalid data types.
  5. Environment Management: Operate in a standalone test environment/repository, connecting to the target API or mocking dependencies as needed.

Workflow Instructions

1. Discovery Phase

  • List files to identify Django components (models.py, serializers.py, views.py).
  • Read existing requirements.txt or pyproject.toml to confirm pytest and plugins.
  • If a Postman collection or API doc is provided, parse it to map endpoints.

2. Test Generation

  • Use pytest-django for database handling.
  • Use factory-boy or faker for generating test data.
  • Models: Test field constraints, custom methods, and signals.
  • Serializers: Test validation logic, field mapping, and nested representations.
  • Views/APIs: Use APIClient to test status codes, response structure, and permission classes.
  • Security: Explicitly create cases for unauthorized access (401/403) and data leakage.

3. Execution & Reporting

  • Run tests using bash with pytest.
  • Post-Test Action:
    • Generate a test_results.csv containing: Test Name, Status, Duration, Error Message (if any).
    • Provide a high-level AI Summary of the test run, highlighting failed areas and suggestions for fixes.

Best Practices

  • Isolation: Ensure each test is atomic and does not depend on other tests.
  • Mocking: Use unittest.mock or pytest-mock for external service calls.
  • Coverage: Aim for 90%+ coverage on serializers and business logic in models.
  • Cleanliness: Use pytest.fixtures for setup/teardown logic.

Examples

Example 1: Testing a Serializer

import pytest
from my_app.serializers import UserSerializer

@pytest.mark.django_db
def test_user_serializer_invalid_email():
    payload = {"username": "testuser", "email": "invalid-email"}
    serializer = UserSerializer(data=payload)
    assert not serializer.is_valid()
    assert "email" in serializer.errors

Example 2: API Security Test

@pytest.mark.django_db
def test_private_endpoint_requires_auth(api_client):
    url = "/api/v1/private-data/"
    response = api_client.get(url)
    assert response.status_code == 403 # Forbidden if not authenticated

Reporting Format

After execution, always present:

  1. Summary Table: Total tests, passed, failed, skipped.
  2. CSV Location: Path to the generated test_results.csv.
  3. AI Insight: "The failures in test_auth.py suggest that the TokenAuthentication is not properly configured for the staging environment."

When not to use it

  • When the task is not related to Django testing
  • When the task is not related to unit, integration, or security tests
  • When the task does not involve pytest

Limitations

  • The skill's quality score focuses on pattern-specific quality, not generic code metrics.
  • The skill does not perform cyclomatic complexity thresholds checks.
  • The skill does not check method/class length thresholds.

How it compares

This skill automates the generation and execution of Django tests, including security checks and edge-case scenarios, which typically requires manual test writing and execution.

Compared to similar skills

django-test-expert side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
django-test-expert (this skill)06moNo flagsAdvanced
django-verification54moReviewIntermediate
django-tdd75moReviewIntermediate
django-insights04moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry