﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21250	Make Remote User tests more flexible	elbarto	elbarto	"I recently had to implement my own middleware with a custom HTTP header, not REMOTE_USER, like:

{{{
from django.contrib.auth.middleware import RemoteUserMiddleware

class MyRemoteUserMiddleware(RemoteUserMiddleware):
    header = 'MY_HTTP_AUTHUSER'
}}}

This is perfect, but then I needed to test my code, so my first idea was to inherit from Django tests overriding my middleware config (I don't know if it's a bad idea) like:

{{{
from django.contrib.auth.tests import RemoteUserTest

class MyRemoteUserTest(RemoteUserTest):
    middleware = 'path.to.MyRemoteUserMiddleware'
}}}

since it would save me to write a lot of code.

The problem is that all tests in such module ( https://github.com/django/django/blob/master/django/contrib/auth/tests/test_remote_user.py ) are dependent for REMOTE_USER, because of many REMOTE_USER keywords are passed to self.client.get() and I was forced to duplicate all the code simply changing REMOTE_USER keyword for my header.

I think it would be great if it could be more flexible.

I was thinking about something like:

{{{
from django.contrib.auth.tests import RemoteUserTest

class MyRemoteUserTest(RemoteUserTest):
    middleware = 'path.to.MyRemoteUserMiddleware'
    header = 'MY_HTTP_AUTHUSER'
}}}

and then changing:

{{{
response = self.client.get('/remote_user/', REMOTE_USER=None)
}}}

for:
{{{
response = self.client.get('/remote_user/', **{self.header: None})
}}}

in all calls.

Or maybe instantiate the middleware (I don't know if it's possible) and getting its self.header.

It would make a lot of easier to implement tests (without duplicating code) when is needed to change the header for the Remote User middleware.

If it were accepted I could code the patch myself."	Cleanup/optimization	closed	Testing framework	1.5	Normal	fixed			Accepted	0	0	0	0	0	0
