← ClaudeAtlas

django-testinglisted

Testing patterns for multi-tenant Django POS projects using pytest-django, RequestFactory, and mocks. No factories, no complex conftest. Trigger: When writing or reviewing tests in any apps/ directory.
lgzarturo/codeconductor · ★ 0 · Testing & QA · score 76
Install: claude install-skill lgzarturo/codeconductor
## When to Use - Writing any test in `apps/*/tests/` or `apps/*/tests.py` - Deciding which test base class to use - Mocking ORM calls for TENANT_APP models - Testing views that use custom access decorators - Testing APIs, PDFs, and cart operations ## Test Architecture in Multi-Tenant Projects ### The Schema Problem This project uses `django-tenants` with multi-schema PostgreSQL: - **Shared apps** (public schema): `core`, `users`, Django contrib - **Tenant apps** (per-store schema): `employees`, `catalog`, `cart`, `orders`, `pos`, `storefront`, `analytics` **The test runner uses the public schema**, so tenant app tables DON'T exist in tests. This profoundly affects how we write tests. ### Base Class Selection | Condition | Use | Notes | | ------------------------------------------- | ------------------------ | --------------------- | | No DB access needed | `SimpleTestCase` | No transaction, no DB | | Only public schema models (`User`, `Store`) | `TestCase` | Uses public schema | | **Any tenant app model** | `SimpleTestCase` + mocks | **ALWAYS** | ```python # WRONG — crashes because tables don't exist class TestProductAPI(TestCase): def test_list_products(self): product = Product.objects.create(...) # Table does not exist! # CORRECT — SimpleTestCase with mocks class TestProductAPI(SimpleTestCase): @pa