testing-django

Correct Django API test patterns for authentication, database usage, and permissions.

13|Updated Mar 15, 2019
One-click install
npx skills add https://github.com/WTFox/dotfiles --skill testing-django
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-django
Source: https://github.com/WTFox/dotfiles/tree/main/claude/.claude/skills/testing-django
Command: npx skills add https://github.com/WTFox/dotfiles --skill testing-django

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Django tests for APIs often suffer from misapplied authentication, improper database handling, and incomplete permission coverage. This skill provides correction guidance to ensure tests follow best practices and guardrails.

Core Features & Use Cases

  • Authentication corrections: prefer force_authenticate over embedding tokens to isolate business logic in tests.
  • Database discipline: enforce explicit django_db marks and proper DB state assertions; cover setup/teardown and transactions.
  • Permission and viewset testing: ensure happy path, unauthenticated, and wrong-user scenarios; validate queryset results and signals.

Quick Start

Apply the recommended authentication, database, and permission-testing patterns to your Django tests.

Frequently Asked Questions about testing-django

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Django API permissions without using real token authentication?

Use force_authenticate in Django API tests to bypass token-based auth, isolating business logic and permissions testing from the authentication layer overhead.

What's the best way to handle database setup in pytest-django tests?

In pytest-django tests, enforce explicit django_db marks on test functions or classes to ensure proper database access, setup, teardown, and transaction handling.

Why does my Django APITestCase return wrong queryset results?

Django APITestCase queryset failures often stem from improper database state assertions; validate explicit DB setup and teardown to ensure querysets return expected results.

Does factory_boy work with Django signal testing in integration tests?

Factory_boy works with Django signal testing by generating consistent model instances, allowing tests to assert signal firing and proper on_commit handling behavior.

What Django viewset testing scenarios should I cover for permissions?

Django viewset testing should cover happy path, unauthenticated access, and wrong-user scenarios to ensure complete permission enforcement across all API endpoints.

When should I not use token-based authentication in Django API tests?

Avoid token-based authentication in Django API tests when isolating business logic; prefer force_authenticate to prevent authentication layer side effects from masking permission errors.