Write correct Django tests — TestCase vs TransactionTestCase, setUpTestData, factory-boy, assertNumQueries, mock.patch placement, and DRF APITestCase patterns
99
99%
Does it follow best practices?
Impact
99%
1.33xAverage score across 2 eval scenarios
Passed
No known issues
setUpTestData for read-only fixtures
0%
87%
assertNumQueries on list endpoints
0%
100%
factory_boy factories defined
100%
100%
Factories used instead of objects.create
100%
100%
TestCase as default base class
100%
100%
Happy path and error tests present
100%
100%
content_type on POST/PUT requests
100%
100%
Authentication tests
100%
100%
No manual tearDown
100%
100%
setUp only for mutable data
50%
100%
TransactionTestCase for on_commit email test
25%
100%
TestCase for non-commit tests
100%
100%
mock.patch targets orders.views.charge_card
100%
100%
mock.patch targets orders.views.send_order_confirmation
100%
100%
override_settings for MAX_CART_ITEMS
100%
100%
factory_boy factories for test data
50%
100%
Both success and failure payment paths tested
100%
100%
Order status and payment record verified
100%
100%
Authentication required test
100%
100%
No manual tearDown
100%
100%
Table of Contents