#21250: Make Remote User tests more flexible
--------------------------------------+--------------------
     Reporter:  elbarto               |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Testing framework     |    Version:  1.5
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21250>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.f16b5e700461915601f7942079834ac2%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to