CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/django-testing

Write correct Django tests — TestCase vs TransactionTestCase, setUpTestData, factory-boy, assertNumQueries, mock.patch placement, and DRF APITestCase patterns

99

1.33x
Quality

99%

Does it follow best practices?

Impact

99%

1.33x

Average score across 2 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-1/

Blog API Tests

Write tests for a Django blog API. The app has the following models:

  • Post: title (CharField), body (TextField), author (ForeignKey to User), created_at (DateTimeField auto_now_add), published (BooleanField default=False)
  • Comment: post (ForeignKey to Post), author (ForeignKey to User), body (TextField), created_at (DateTimeField auto_now_add)
  • Tag: name (CharField unique) with a ManyToManyField on Post called tags

The API exposes these endpoints via Django REST Framework:

  • GET /api/posts/ -- list published posts with their tags (paginated)
  • POST /api/posts/ -- create a new post (authenticated)
  • GET /api/posts/<id>/ -- retrieve a single post
  • PUT /api/posts/<id>/ -- update a post (author only)
  • DELETE /api/posts/<id>/ -- delete a post (author only)
  • GET /api/posts/<id>/comments/ -- list comments for a post
  • POST /api/posts/<id>/comments/ -- add a comment (authenticated)
  • GET /api/tags/ -- list all tags

Output

Produce a test file at blog/tests/test_blog_api.py with comprehensive test coverage for the above endpoints. Include any supporting factory files you need. Assume the models and views already exist; you are only writing the tests.

evals

scenario-1

criteria.json

task.md

tile.json