Opened 4 years ago

Closed 4 years ago

#25699 closed New feature (fixed)

Allow using test client session handling with custom session apps

Reported by: Sergey Kolosov Owned by: Sergey Kolosov
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: walt@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This ticket follows up #22634 (which allowed extending database-backed session backends).

While it is now possible to reuse session backend classes, it's not the case for the corresponding parts of the test client.

Namely, in case of having the custom session backend and its corresponding parts (models, middleware, etc) as a separate application, you're unable to use the test client with sessions. The issue is 'django.contrib.sessions' being hardcoded inside of _session and login().

Working that around involves monkey-patching the test client with modified copies of _session and login().

I suggest refactoring test client for better reusability (given this would eliminate session app name being hardcoded).

Change History (11)

comment:1 Changed 4 years ago by Sergey Kolosov

Has patch: set
Needs tests: set

comment:2 Changed 4 years ago by Raphael Michel

Triage Stage: UnreviewedAccepted

I think that this is an useful thing to have.

I'm unsure about your PR on first sight, though, as it needs to add a new setting for an edge case and adding settings is generally discouraged. Maybe someone else likes to review it more thouroughly.

comment:3 Changed 4 years ago by Claude Paroz

Instead of adding a new setting, I'd rather see an AppConfig attribute (like session_app), and then the _session_app_is_installed could cycle through installed AppConfig's to look for this attribute.

comment:4 Changed 4 years ago by Sergey Kolosov

Owner: changed from nobody to Sergey Kolosov
Patch needs improvement: set
Status: newassigned

Sounds good, I'll update the PR given the suggested approach.

comment:5 Changed 4 years ago by Tim Graham

Type: UncategorizedNew feature

comment:6 Changed 4 years ago by Walt Javins

Cc: walt@… added

comment:7 Changed 4 years ago by Sergey Kolosov

comment:8 Changed 4 years ago by Sergey Kolosov

Needs tests: unset
Patch needs improvement: unset

comment:9 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:11 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 21dd98a3:

Fixed #25699 -- Allowed using the test client if 'django.contrib.sessions' isn't in INSTALLED_APPS.

Note: See TracTickets for help on using tickets.
Back to Top