pytest-dev / pytest-dev/pytest-django

Request factory with a preset admin user

Open
#284 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

Wouldn't it be reasonable to have a request factory, which sets user field by default on every created request? Like admin_client does. For example:

 @fixture
 def rf_admin(admin_user):
     from django.test.client import RequestFactory

     class AdminRequestFactory(RequestFactory):
         def request(self, **request):
            r = super().request(**request)
            r.user = admin_user
            return r

     return AdminRequestFactory()

Because 90% of the time I use rf fixture I set admin_user on it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing rf fixture and the admin_client fixture, then inspect how Django's RequestFactory is used in the plugin's tests. Define the fixture's expected name and behavior, including when it assigns admin_user, and add coverage showing that created requests receive that user.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.