← ClaudeAtlas

django-tddlisted

Django testing strategies with pytest-django, TDD methodology, factory_boy, mocking, coverage, and testing Django REST Framework APIs.
Izangi2714/claude-code-python-stack · ★ 0 · Testing & QA · score 65
Install: claude install-skill Izangi2714/claude-code-python-stack
# 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 ## Setup ### pytest Configuration ```ini # pytest.ini [pytest] DJANGO_SETTINGS_MODULE = config.settings.test testpaths = tests addopts = --reuse-db --nomigrations --cov=apps --cov-report=html --strict-markers markers = slow: marks tests as slow integration: marks tests as integration tests ``` ### conftest.py ```python import pytest from django.contrib.auth import get_user_model User = get_user_model() @pytest.fixture def user(db): return User.objects.create_user(email='test@example.com', password='testpass123', username='testuser') @pytest.fixture def authenticated_client(client, user): client.force_login(user) return client @pytest.fixture def api_client(): from rest_framework.test import APIClient return APIClient() @pytest.fixture def authenticated_api_client(api_client, user): api_client.force_authenticate(user=user) return api_client ``` ## Factory Boy ```python import factory class UserFactory(factory.django.DjangoModelFactory): class Meta: model = User email = factory.Sequence(lambda n: f"user{n}@example.com") username = factory.Sequence(lambda n: f"user{n}") password = factory.PostGenerationMethodCall('set_password', 'testpa