Opened 9 years ago

Closed 9 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: dev
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 by Sergey Kolosov, 9 years ago

Has patch: set
Needs tests: set

comment:2 by Raphael Michel, 9 years ago

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 by Claude Paroz, 9 years ago

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 by Sergey Kolosov, 9 years ago

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 by Tim Graham, 9 years ago

Type: UncategorizedNew feature

comment:6 by Walt Javins, 9 years ago

Cc: walt@… added

comment:7 by Sergey Kolosov, 9 years ago

comment:8 by Sergey Kolosov, 9 years ago

Needs tests: unset
Patch needs improvement: unset

comment:9 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:11 by Tim Graham <timograham@…>, 9 years ago

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