django-tdd
Master test-driven development for Django projects using pytest and factory_boy to build reliable models, views, and APIs. This skill covers the red-green-refactor cycle, test fixtures, factory patterns, and Django REST Framework testing.
django-tdd teaches test-driven development methodology for Django applications using pytest and factory_boy.
AI-generated summary based on this skill's SKILL.md
Install
affaan-m/ECC/django-tdd · repository language: JavaScript
git clone https://github.com/affaan-m/ECC
cp -r ECC/skills/django-tdd ~/.claude/skills/django-tddnpx skillfed install affaan-m/ECC/django-tddFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What is django-tdd and how does it help with Django testing?
django-tdd is a comprehensive skill for mastering test-driven development in Django projects. It teaches you to use pytest and factory_boy to build reliable models, views, and APIs through the red-green-refactor cycle. The skill covers test fixtures, factory patterns, and Django REST Framework testing, enabling you to write robust tests before implementing features.
How do I set up pytest and factory_boy for Django model testing?
django-tdd guides you through configuring pytest and factory_boy specifically for Django model and API testing. You'll learn to create test factories that generate model instances efficiently, set up pytest fixtures for reusable test data, and organize your test suite. This setup ensures consistent, maintainable tests across your Django projects.
What does django-tdd teach about testing Django REST Framework APIs?
django-tdd covers comprehensive testing strategies for Django REST Framework, including how to test serializers, viewsets, and endpoints. You'll learn to use Django's test client to make API requests, validate responses, and test authentication and permissions. The skill emphasizes testing complete request-response cycles to ensure your API behaves correctly.
How can I test Django REST API endpoints with django-tdd?
django-tdd teaches you to test Django REST API endpoints using pytest fixtures, factory_boy for test data, and Django's API test client. You'll learn to structure tests for different HTTP methods, validate serializer output, and test viewset actions. The skill includes patterns for testing authentication, permissions, and error responses in your REST APIs.
Does django-tdd cover mocking and test coverage measurement?
Yes, django-tdd addresses mocking external services and measuring test coverage in Django projects. You'll learn to mock third-party APIs, database calls, and other dependencies to isolate your tests. The skill also covers setting up coverage tools to track which parts of your codebase are tested, helping you identify gaps.
What is the red-green-refactor cycle taught in django-tdd?
django-tdd teaches the red-green-refactor cycle, the core of test-driven development. You write a failing test (red), implement code to make it pass (green), then improve the code without breaking tests (refactor). This methodology, combined with pytest fixtures and factory patterns, ensures your Django applications are well-tested and maintainable from the start.
SKILL.md
rendered from the published skill — quoted content, verbatim
Django Testing with TDD
Test-driven development for Django applications using pytest, factory_boy, and Django REST Framework.
When to Activate
- Writing new Django applications
- Implementing Django REST Framework APIs
- Testing Django models, views, and serializers
- Setting up testing infrastructure for Django projects
TDD Workflow for Django
Red-Green-Refactor Cycle
# Step 1: RED - Write failing test
def test_user_creation():
user = User.objects.create_user(email='test@example.com', password='testpass123')
assert user.email == 'test@example.com'
assert user.check_password('testpass123')
assert not user.is_staff
# Step 2: GREEN - Make test pass
# Create User model or factory
# Step 3: REFACTOR - Improve while keeping tests green
Setup
pytest Configuration
```ini
pytest.ini
[pytest] DJANGO_SETTINGS_MODULE = config.settings.test testpaths = tests python_files = test_.py python_classes = Test python_functions =
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
skills/django-tdd/SKILL.md