Skip to content

Request factory with a preset admin user #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Glueon opened this issue Oct 10, 2015 · 0 comments
Open

Request factory with a preset admin user #284

Glueon opened this issue Oct 10, 2015 · 0 comments

Comments

@Glueon
Copy link

Glueon commented Oct 10, 2015

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.

tony added a commit to develtech/pytest-django that referenced this issue Dec 26, 2017
This is based on conversations in issues pytest-dev#553, pytest-dev#554, and pytest-dev#284

- Introduces a django_user fixture, which is a user with no additional
  priveleges. Similar to admin_user.
- A user_client, based on django_user. Similar to admin_client.
- 3 new RequestFactory based fixtures, for unauthenticated,
  authenticated, and admin users:

  - rf_unauth: relies on AnonymousUser, similar to django docs
    example.
  - rf_admin: relies on admin_user fixture
  - rf_user: relies on new django_user fixture

  In addition, these 3 fixtures differ from rf in that they:

  - Mimic AuthenticationMiddleware by add the user attribute to
    the request object
  - Mimic SessionMiddleware by adding the 'session' attribute
    to the request object. This is an in-memory session store object
    from ``django.contrib.sessions.backends.base.SessionBase``.

This fills the gaps left over by not having normal and unauthenticated
user objects, clients, and request factories (when admin ones were
available), and also covers a common case likely present in Django
projects - anonymous (not logged in), authenticated, and admin users.
tony added a commit to develtech/pytest-django that referenced this issue Dec 26, 2017
Fixes pytest-dev#565

This is based on conversations in issues pytest-dev#553, pytest-dev#554, and pytest-dev#284

- Introduces a django_user fixture, which is a user with no additional
  priveleges. Similar to admin_user.
- A user_client, based on django_user. Similar to admin_client.
- 3 new RequestFactory based fixtures, for unauthenticated,
  authenticated, and admin users:

  - rf_unauth: relies on AnonymousUser, similar to django docs
    example.
  - rf_admin: relies on admin_user fixture
  - rf_user: relies on new django_user fixture

  In addition, these 3 fixtures differ from rf in that they:

  - Mimic AuthenticationMiddleware by add the user attribute to
    the request object
  - Mimic SessionMiddleware by adding the 'session' attribute
    to the request object. This is an in-memory session store object
    from ``django.contrib.sessions.backends.base.SessionBase``.

This fills the gaps left over by not having normal and unauthenticated
user objects, clients, and request factories (when admin ones were
available), and also covers a common case likely present in Django
projects - anonymous (not logged in), authenticated, and admin users.
tony added a commit to develtech/pytest-django that referenced this issue Dec 26, 2017
Fixes pytest-dev#565

This is based on conversations in issues pytest-dev#553, pytest-dev#554, and pytest-dev#284

- Introduces a django_user fixture, which is a user with no additional
  priveleges. Similar to admin_user.
- A user_client, based on django_user. Similar to admin_client.
- 3 new RequestFactory based fixtures, for unauthenticated,
  authenticated, and admin users:

  - rf_unauth: relies on AnonymousUser, similar to django docs
    example.
  - rf_admin: relies on admin_user fixture
  - rf_user: relies on new django_user fixture

  In addition, these 3 fixtures differ from rf in that they:

  - Mimic AuthenticationMiddleware by add the user attribute to
    the request object
  - Mimic SessionMiddleware by adding the 'session' attribute
    to the request object. This is an in-memory session store object
    from ``django.contrib.sessions.backends.base.SessionBase``.

This fills the gaps left over by not having normal and unauthenticated
user objects, clients, and request factories (when admin ones were
available), and also covers a common case likely present in Django
projects - anonymous (not logged in), authenticated, and admin users.
tony added a commit to develtech/pytest-django that referenced this issue Jan 18, 2018
Fixes pytest-dev#565

This is based on conversations in issues pytest-dev#553, pytest-dev#554, and pytest-dev#284

- Introduces a django_user fixture, which is a user with no additional
  priveleges. Similar to admin_user.
- A user_client, based on django_user. Similar to admin_client.
- 3 new RequestFactory based fixtures, for unauthenticated,
  authenticated, and admin users:

  - rf_unauth: relies on AnonymousUser, similar to django docs
    example.
  - rf_admin: relies on admin_user fixture
  - rf_user: relies on new django_user fixture

  In addition, these 3 fixtures differ from rf in that they:

  - Mimic AuthenticationMiddleware by add the user attribute to
    the request object
  - Mimic SessionMiddleware by adding the 'session' attribute
    to the request object. This is an in-memory session store object
    from ``django.contrib.sessions.backends.base.SessionBase``.

This fills the gaps left over by not having normal and unauthenticated
user objects, clients, and request factories (when admin ones were
available), and also covers a common case likely present in Django
projects - anonymous (not logged in), authenticated, and admin users.
tony added a commit to develtech/pytest-django that referenced this issue Jan 18, 2018
Fixes pytest-dev#565

This is based on conversations in issues pytest-dev#553, pytest-dev#554, and pytest-dev#284

- Introduces a django_user fixture, which is a user with no additional
  priveleges. Similar to admin_user.
- A user_client, based on django_user. Similar to admin_client.
- 3 new RequestFactory based fixtures, for unauthenticated,
  authenticated, and admin users:

  - rf_unauth: relies on AnonymousUser, similar to django docs
    example.
  - rf_admin: relies on admin_user fixture
  - rf_user: relies on new django_user fixture

  In addition, these 3 fixtures differ from rf in that they:

  - Mimic AuthenticationMiddleware by add the user attribute to
    the request object
  - Mimic SessionMiddleware by adding the 'session' attribute
    to the request object. This is an in-memory session store object
    from ``django.contrib.sessions.backends.base.SessionBase``.

This fills the gaps left over by not having normal and unauthenticated
user objects, clients, and request factories (when admin ones were
available), and also covers a common case likely present in Django
projects - anonymous (not logged in), authenticated, and admin users.

Also, Update fixtures.py with changes from @blueyed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant