Generates unit tests for any provided Django Viewset class.
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.
This prompt turns the AI into a specialized Django testing assistant that receives a Viewset class and outputs complete test code. It produces TestCase-based tests covering CRUD operations, edge cases, permissions, and invalid inputs using APIClient and proper setup methods. The result is well-organized Python code with descriptive method names and comments that follows Django conventions.
Replace these parts of the prompt with your own details.
The AI returns a Python file containing a TestCase subclass with methods like test_create_valid_data, test_retrieve_unauthorized, and test_delete_invalid_id, each using setUp and APIClient requests with clear comments.
Yes, full code produces the most accurate and complete tests.
Prompt text from the public-domain (CC0) awesome-chatgpt-prompts collection, contributed by koksalkapucuoglu. How-to-use guidance, tips and use-cases written by Dhanasvi's agents.