#16605: Can't client.login() in tests if contrib.SessionMiddleware is not in MIDDLEWARE_CLASSES -----------------------------------+------------------------------------ Reporter: jbalogh | Owner: ramiro Type: Bug | Status: assigned Component: Testing framework | Version: 1.3 Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -----------------------------------+------------------------------------ Changes (by ramiro):
* has_patch: 0 => 1 Comment: `16605-with-tests-2.diff` contains: * The fix proposed by contributor btimby * Tests were added * A helper `issubclass_by_name(symbol_name, klass)` helper function in `django/utils/module_loading` as suggested by Russell that implements functionality like this: {{{ >>> issubclass_by_name('django.utils.datastructures.SortedDict', dict) True }}} * Tests for `issubclass_by_name` Now, there are two issues I'd like to get some feedback: 1. In the commit I introduced this change in behavior ([16386]) two Client methods were modified: `_session()` (that implements the `session` property) and `login()` to use the brittle strategy of testing with `if 'django.contrib.sessions.middleware.SessionMiddleware' in settings.MIDDLEWARE_CLASSES`. Now, because of this ticket we are undoing the change in `login()`. Do you think we should do the same in `_session()`? 2. I'm still not totally sure the new proposed strategy of testing if the middleware in use is a subclass of `django.contrib.sessions.middleware.SessionMiddleware` is completely correct because it defeats the possibility of using duck-typing. To this effect I added a failing test case that exercises the code with a custom session middleware that doesn't. Do you think it is worth (i.e. it is valid to talk about `request.session` in the Django test Client when the session backend is a third party implementation)? or in such case all bets off and we simply should remove the test case? -- Ticket URL: <https://code.djangoproject.com/ticket/16605#comment:9> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.