ALWAYS use this skill proactively for Consumer Affairs Django repositories (located in ../ca/ directory) when ANY of these occur - (1) User mentions coverage, codecov, test coverage, partial coverage, branch coverage, or uncovered lines/code (2) User asks to write tests, add tests, run tests, or fix test failures (3) User asks to implement features, fix bugs, or modify code in CA repos and tests are needed (4) User provides a file path containing 'test' or 'tests' in CA repos (5) After writing new code in CA repos that needs test coverage. This skill handles Django test execution using the 'ca magictest' command and ensures 100% code coverage for CI requirements.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
ALWAYS use this skill proactively for Consumer Affairs Django repositories (located in ../ca/ directory) when ANY of these occur - (1) User mentions coverage, codecov, test coverage, partial coverage, branch coverage, or uncovered lines/code (2) User asks to write tests, add tests, run tests, or fix test failures (3) User asks to implement features, fix bugs, or modify code in CA repos and tests are needed (4) User provides a file path containing 'test' or 'tests' in CA repos (5) After writing new code in CA repos that needs test coverage. This skill handles Django test execution using the 'ca magictest' command and ensures 100% code coverage for CI requirements.
CA Django Testing Skill
This skill helps write and run Django unit tests in Consumer Affairs repositories with a focus on achieving 100% code coverage.
When to Use This Skill
AUTOMATIC ACTIVATION TRIGGERS - Activate this skill immediately when:
✅ User mentions ANY coverage-related terms: "coverage", "codecov", "test coverage", "partial coverage", "branch coverage", "uncovered lines", "missing coverage", "BrPart", "line X is not covered", "partially covered"
✅ User asks to write tests for CA repository code
✅ User wants to add test coverage for existing functions
✅ User needs to run tests in CA repos
✅ User mentions fixing test failures or improving coverage
✅ User references specific test files or test paths in CA repos
✅ User says "use the test skill" or similar phrases
PROACTIVE USE - Also use this skill proactively (without being asked) when:
After implementing new features in CA repos that need tests
After fixing bugs in CA repos that need test verification
When analyzing code that lacks proper test coverage
Writing Tests
Test File Location Strategy
CRITICAL: Always prioritize using existing test modules unless creating a new code module:
Check for existing test files first before creating new ones
Add tests to existing test modules that are related to the code being tested
Only create new test files when:
Creating a completely new code module
The existing test file would become too large (>1000 lines)
The new functionality is logically separate from existing tests
Test Structure Requirements
All tests MUST follow these principles:
1. Test base class
Some repositories might have their own baseclass extending Django's TestCase class.
Look for other test modules and make sure you're using the same base class as they
If you don't find test modules examples, try finding if we're extending Django's base TestClass with our own
2. Unit Test Each Function Separately
Each function/method should have its own test class
from unittest.mock import patch, Mock, MagicMock
classMyServiceTestCase(TestCase):
@patch('app.module.external_api_call')deftest_service_with_mocked_api(self, mock_api):
mock_api.return_value = {'status': 'success'}
# Test your code
Use Fixtures and Setup
classMyTestCase(TestCase):
defsetUp(self):
"""Set up test fixtures that are reused across tests"""self.user = User.objects.create(username='testuser')
deftearDown(self):
"""Clean up after tests if needed"""pass
from django.contrib.auth.models import User
classAuthenticatedTestCase(TestCase):
defsetUp(self):
self.user = User.objects.create_user(
username='testuser',
password='testpass'
)
self.client.login(username='testuser', password='testpass')
Testing Async Code
from django.test import TestCase
import asyncio
classAsyncTestCase(TestCase):
deftest_async_function(self):
result = asyncio.run(my_async_function())
self.assertEqual(result, expected_value)
Remember
✅ Check for existing test files first
✅ Cover every single code path
✅ Use ca magictest for running tests
✅ Aim for 100% coverage
✅ Mock external dependencies
✅ Test error conditions, not just happy paths
✅ Use descriptive test names
✅ Keep tests focused and isolated