<< All versions
Skill v1.0.0
currentAutomated scan100/100manikosto/claude-code-python-stack/django-tdd
──Details
PublishedOctober 8, 2026 at 05:14 AM
Content Hashsha256:dfbbd4ec8a7789ac...
Git SHA805c4d6a5783
──Files
Files (1 file, 2.9 KB)
SKILL.md2.9 KBactive
SKILL.md · 112 lines · 2.9 KB
version: "1.0.0" name: django-tdd description: Django testing strategies with pytest-django, TDD methodology, factory_boy, mocking, coverage, and testing Django REST Framework APIs. origin: ECC
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.testtestpaths = testsaddopts = --reuse-db --nomigrations --cov=apps --cov-report=html --strict-markersmarkers =slow: marks tests as slowintegration: marks tests as integration tests
conftest.py
python
import pytestfrom django.contrib.auth import get_user_modelUser = get_user_model()@pytest.fixturedef user(db):return User.objects.create_user(email='test@example.com', password='testpass123', username='testuser')@pytest.fixturedef authenticated_client(client, user):client.force_login(user)return client@pytest.fixturedef api_client():from rest_framework.test import APIClientreturn APIClient()@pytest.fixturedef authenticated_api_client(api_client, user):api_client.force_authenticate(user=user)return api_client
Factory Boy
python
import factoryclass UserFactory(factory.django.DjangoModelFactory):class Meta:model = Useremail = factory.Sequence(lambda n: f"user{n}@example.com")username = factory.Sequence(lambda n: f"user{n}")password = factory.PostGenerationMethodCall('set_password', 'testpass123')class ProductFactory(factory.django.DjangoModelFactory):class Meta:model = Productname = factory.Faker('sentence', nb_words=3)price = factory.fuzzy.FuzzyDecimal(10.00, 1000.00, 2)category = factory.SubFactory(CategoryFactory)
DRF API Testing
python
class TestProductAPI:def test_list_products(self, api_client, db):ProductFactory.create_batch(10)response = api_client.get(reverse('api:product-list'))assert response.status_code == status.HTTP_200_OKassert response.data['count'] == 10def test_create_product_unauthorized(self, api_client, db):response = api_client.post(reverse('api:product-list'), {'name': 'Test'})assert response.status_code == status.HTTP_401_UNAUTHORIZEDdef test_create_product_authorized(self, authenticated_api_client, db):data = {'name': 'Test Product', 'price': '99.99', 'stock': 10}response = authenticated_api_client.post(reverse('api:product-list'), data)assert response.status_code == status.HTTP_201_CREATED
Coverage Goals
| Component | Target | |
|---|---|---|
| Models | 90%+ | |
| Serializers | 85%+ | |
| Views | 80%+ | |
| Services | 90%+ | |
| Overall | 80%+ |