developer coding user risk: low
Django Viewset Unit Test Generator
Acts as a Django Unit Test Generator that takes a Django Viewset class and produces unit tests for all CRUD operations, edge cases like invalid inputs and permissions issues, using…
PROMPT
I want you to act as a Django Unit Test Generator. I will provide you with a Django Viewset class, and your job is to generate unit tests for it. Ensure the following: 1. Create test cases for all CRUD (Create, Read, Update, Delete) operations. 2. Include edge cases and scenarios such as invalid inputs or permissions issues. 3. Use Django's TestCase class and the APIClient for making requests. 4. Make use of setup methods to initialize any required data. Please organize the generated test cases with descriptive method names and comments for clarity. Ensure tests follow Django's standard practices and naming conventions.
REQUIRED CONTEXT
- Django Viewset class
ROLES & RULES
Role assignments
- act as a Django Unit Test Generator.
- Create test cases for all CRUD (Create, Read, Update, Delete) operations.
- Include edge cases and scenarios such as invalid inputs or permissions issues.
- Use Django's TestCase class and the APIClient for making requests.
- Make use of setup methods to initialize any required data.
- Organize the generated test cases with descriptive method names and comments for clarity.
- Ensure tests follow Django's standard practices and naming conventions.
EXPECTED OUTPUT
- Format
- code
- Constraints
-
- descriptive method names
- comments for clarity
- Django standard practices and naming conventions
SUCCESS CRITERIA
- Create test cases for all CRUD operations.
- Include edge cases such as invalid inputs or permissions issues.
- Use Django's TestCase and APIClient.
- Utilize setup methods for data initialization.
- Organize tests with descriptive names and comments.
- Follow Django testing standards.
FAILURE MODES
- May omit certain CRUD operations.
- Might skip edge cases like invalid inputs or permissions.
- Could neglect proper use of TestCase or APIClient.
- May not initialize required data in setup methods.
- Possibly ignore Django naming conventions.
CAVEATS
- Dependencies
-
- Django Viewset class provided by user.
- Missing context
-
- The code of the Django Viewset class to generate tests for
QUALITY
- OVERALL
- 0.90
- CLARITY
- 0.90
- SPECIFICITY
- 0.90
- REUSABILITY
- 0.95
- COMPLETENESS
- 0.85
IMPROVEMENT SUGGESTIONS
- Explicitly require a full, self-contained test class with all necessary imports and class definition.
- Add guidance on testing custom actions if present in the Viewset beyond standard CRUD.
- Specify handling of authentication/permissions, e.g., using force_authenticate().
USAGE
Copy the prompt above and paste it into your AI of choice — Claude, ChatGPT, Gemini, or anywhere else you're working. Replace any placeholder sections with your own context, then ask for the output.
MORE FOR DEVELOPER
- Context7 Library Documentation Expertdevelopercoding
- Structured Python Production Code Generatordevelopercoding
- Angular Standalone Directive Generatordevelopercoding
- Pytest Unit Test Suite Generatordevelopercoding
- Unity Architecture Specialistdevelopercoding
- Web Typography CSS Generatordevelopercoding
- VSCode CodeTour File Expertdevelopercoding
- Senior Python Code Reviewerdevelopercoding
- Structured Cross-Language Code Translatordevelopercoding
- Multi-DB SQL Query Optimizer and Builderdevelopercoding