xiaohongshu
xiaohongshu
ca-django-tests
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 ...
Full skill instructions
This skill helps write and run Django unit tests in Consumer Affairs repositories with a focus on achieving 100% code coverage.
AUTOMATIC ACTIVATION TRIGGERS - Activate this skill immediately when:
PROACTIVE USE - Also use this skill proactively (without being asked) when:
CRITICAL: Always prioritize using existing test modules unless creating a new code module:
All tests MUST follow these principles:
Some repositories might have their own baseclass extending Django's TestCase class.
TestClass with our ownTHIS IS CRITICAL: You must write tests for:
Goal: 100% code coverage - codecov must pass in CI
def test_<function_name>_<scenario>_<expected_outcome>(self):
"""Clear description of what is being tested"""
Examples:
test_calculate_total_with_valid_items_returns_sum()test_calculate_total_with_empty_list_returns_zero()test_calculate_total_with_negative_values_raises_error()from unittest.mock import patch, Mock, MagicMock
class MyServiceTestCase(TestCase):
@patch('app.module.external_api_call')
def test_service_with_mocked_api(self, mock_api):
mock_api.return_value = {'status': 'success'}
# Test your code
class MyTestCase(TestCase):
def setUp(self):
"""Set up test fixtures that are reused across tests"""
self.user = User.objects.create(username='testuser')
def tearDown(self):
"""Clean up after tests if needed"""
pass
from django.test import TestCase
class ModelTestCase(TestCase):
def test_model_creation(self):
instance = MyModel.objects.create(field='value')
self.assertEqual(instance.field, 'value')
self.assertIsNotNone(instance.pk)
Use the ca helper script with the following priority:
ca magictest (PREFERRED)ca magictest path.to.the.tests.folder.or.module
Examples:
ca magictest app.api.tests.test_viewsca magictest app.api.testsca magictest . (run all tests)This is the preferred method - it uses containers that are already running.
ca pytestca pytest path/to/the/tests/folder/or/module
Use this if the repo has pytest support:
ca pytest app/api/tests/test_views.pyca pytest app/api/tests/ca testca test path.to.the.tests.folder.or.module
Fallback to Django's test runner:
ca test app.api.tests.test_viewsdocker compose run - this starts a separate containerca script - it uses already running containersTo run a single test method:
ca magictest app.api.tests.test_views.MyTestCase.test_specific_method
When user asks to "write tests for the authenticate function":
Locate the function to understand its code paths
Find existing test file for that module (e.g., if function is in app/api/auth.py, look for app/api/tests/test_auth.py)
Analyze all code paths in the function:
Write comprehensive tests covering each path:
Run tests using ca magictest:
ca magictest app.api.tests.test_auth
Verify coverage - ensure all lines are covered
Fix any failures and re-run
from django.test import TestCase, RequestFactory
from unittest.mock import patch
class ViewTestCase(TestCase):
def setUp(self):
self.factory = RequestFactory()
def test_view_returns_200(self):
request = self.factory.get('/api/endpoint/')
response = my_view(request)
self.assertEqual(response.status_code, 200)
from django.contrib.auth.models import User
class AuthenticatedTestCase(TestCase):
def setUp(self):
self.user = User.objects.create_user(
username='testuser',
password='testpass'
)
self.client.login(username='testuser', password='testpass')
from django.test import TestCase
import asyncio
class AsyncTestCase(TestCase):
def test_async_function(self):
result = asyncio.run(my_async_function())
self.assertEqual(result, expected_value)
✅ 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
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience